-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Button multipress #200
Comments
When the button is pressed once AND buttontopic is set it will execute a MQTT command. In that case a See the cryptic message in wiki - Button usage (https://github.com/arendst/Sonoff-Tasmota/wiki/Button-usage). |
I also would appreciate ionciubotaru's suggestion. I've test several times the buttontopic/switchtopic/switchmode command's, but I don't get it. I'm not able figuring out what the parameters are doing. I'm also looking for a possibility, to switch a fan in the bathroom, by tapping the sonoff touch twice. But Theo, Tasmota is the most fascinating development for ESP's at the moment. Thank you very much for your project! |
Yes, Tasmota is the best software for Sonoff. Looking inside the code I'm impressed of Theo's programming skills.. I set buttontopic to 'second_sonoff' and when the button is pressed once sonoff send the mqtt message: Is it possible to swap ?
|
you have run across a bug that's due to the special casing of the first button. The "correct" behavior afte you have set buttontopic is to not change any local relays, only to send the mqtt messages |
For all Sonoffs, except Touch this behavior is ok, but for Touch is better to turn on the light on the first press - is hard to teach all family members to toggle light with double click, when for many year they did it with a single one :) |
the fixed code would not toggle the relays at all with switchtopic set, it would send one message if you single-tap and a different message if you doubletap The idea is that once you set the switchtopic, it should no longer control the relays directly, only send messages |
It's OK if everything works fine (wireless + MQTT), but if something is wrong nobody can turn on the light and this will be frustrating in a smart house (bad thinks always happened - Murphy's law) |
well, if you don't want the button to not turn on the local relays, why are you setting switchtopic? that's what it does. |
I'm sorry Excuse me for insitence, please tell me how to do:
If this is not possible it's ok, i will change the code manually |
On Thu, 16 Mar 2017, Ion wrote:
I'm sorry `davidelang` but switchtopic has no effect on double click
Only ButtonTopic has effect, but in a reverse order:
that's what I've been saying, and it's a bug
Excuse me for insitence, please tell me how to do:
- when the button is pressed once to toggle the relay
- when the button is pressed twice to send the mqtt message to buttontopic
If this is not possible it's ok, i will change the code manually
This is not possible in the current code.
|
Ok, after re-reading this umpteen times I think I understand what @arendst was saying way up above. double tapping button0 will do one of two things. If you are on a sonoff dual, it will switch the second relay If you are on anything else, it will switch the first relay (as long as it's not in the middle of connecting to a mqtt server), this provides a back-door to switch the first relay if you are disconnected from the network and have buttontopic set. At this point, I think it would be less confusing to have the double-tap do nothing on devices other than the dual, or always act as if button2 was pressed (no matter what type). But I suppose legacy consistency applies here. |
I also got this issue like you. At the moment, it is only a workaroud to archieve a double tap function, and it's really confusing. Furthermore I would appreciate a more easier way to control other things by tapping twice a sonoff touch. |
@arendst
would it make sense to change it so that the double-tap always did what button2
is configured for? (either switch relay 2 or send the power2 mqtt command
depending on buttontopic)
|
@davidelang if I make that change switching won't work anymore when no MQTT server can be reached. That is what you explained just above correctly. That was also the reason of having the double tap available. I do not see a relation between a sonoff touch double tapping and a sonoff dual. Changing it's functionality makes sonoffs useless when there is no MQTT server connection. I need more convincing... |
well, I think it's wrong that if you have buttontopic set, any manipulation of
the button changes the local relay :-)
I see two logical config scenarios, and both are valid
1. you set buttontopic and want the local relays to do nothing if there isn't a
command from a mqtt server.
2. you set buttontopic but want a fallback to local control if the mqtt server
is not reachable.
If you want #2, you really want it for all buttons (including the sonoff dual's
'fake' button from the doubletap)
If you want #1, it's not possible right now, there's always a backdoor for the
local relay (except for on the dual)
So I think it makes more sense to have this as a config option
(buttonfallback??) than to have it be just a feature of a single-button/relay
device.
remember that tasmota is being used more and more with devices that have
multiple switches/relays on them, the stock single-relay sonoffs are still the
common case, but far from the only case.
|
I'd like to do something similar with the Sonoff Touch. For example, it is on the bedroom wall controlling the ceiling light. I have two bedside lights each with basic Sonoffs inside. A single press to the Touch would turn ceiling light on but two short presses would send out an MQTT message to my OpenHAB which would then turn on the lights. From what I am reading, it isn't possible in the current build but it should be possible to implement? |
Please take a look to the first item in this issue. |
Hi ion, Thanks! |
In sonoff.ino search for the block inside if and replace it with the new one. |
I would also use double tapping on the Touch to control other things (through MQTT). So it would be good to have this as an option. |
By trying to get this issue solved I need to know what you want by keeping in mind the original functionality.
I could make situation Wish 1 a selectable option if that solves all your problems although I expect an answer where someone wants to send a MQTT message when pressed once and another message when pressed twice bypassing any local relay control... EDIT: Add Wish 2 as option for Wish 1. Awaiting your input. |
For me Wish 1 makes what I would like to do now. But for a long-term solution I think it would be better to invest into a more generic solution where any combination could be configured. I think it would be easier to maintain and maybe is less LOC. There is also an issue for a Long Press Event (#489), which could be integrated as well (I would use that also). And there is SwitchMode too, which I was not able to use last time I tried. It is and gets even more complicated if you try to implement all wishes with the current model. I think it would be more versatile and easier to understand if it could be configured somehow like this:
Where ReleaseAction is if no immediate press follows (ie this is the SingleClickAction but can be used in Press-Release scenarios like a doorbell button). With these 4 settings all the combinations could be achieved: default operation, MQTT failsafe mode, SwitchMode, SwitchTopic and ButtonTopic things, all the wishes and the multi-relay models too. For example for Wish 1 I could configure this:
Default on a Dual:
Or a momentary switch mode:
But one can connect other switches to the GPIOs so it can be made even more generic... :) |
5.1.6 20170606 * Shrink code * Removed online configuration of Domoticz In and Domoticz Out MQTT strings * Removed commands DomoticzInTopic and DomoticzOutTopic * Add define KEY_HOLD_TIME to configure button hold threshold before sending MQTT Hold message * Add command StateText4 to configure button MQTT Hold text (= MQTT_CMND_HOLD) * Add command SetOption11 0|1 to swap pushbutton single and double press functionality (#200) * Add command SwitchMode<x> 5 (PUSHBUTTONHOLD) and 6 (PUSHBUTTONHOLD_INV) (#489)
@arendst: Yes, I know it is about the "internal" push button not the external ones, but I tried to combine the features of the two to make it even more standardized and easily understandable and programmable way. But never mind, it was just a quick idea, may be worth considering before a major release in the future. I flashed the new release on all my sonoffs, and configured single, double click and hold on some of them and it works like a charm. Thank you very much! The only problem I saw is that the default 4 seconds for hold is a lot. I flashed them with 2 seconds initially, but it is also a bit too much. So I was searching for the MQTT command to alter this value, but I didn't found a command for that. Checked in the source, I saw it is hardcoded (defined). Not a big problem, I will reflash them later, but I think this should be configurable. |
While writing the code I think: How long will it take that someone wants to be able to change the hold timeout online instead of using the default of 4 seconds. I guessed it has always been there as being 4 seconds so a define would have been a great improvement... Any way, in the next release there will be a command to change its value from 0.1 to 20 seconds ;-) |
How can i enable this on Touch? |
@TRIROG: Use the table above to find the required settings. I assume you are using MQTT. Configure your automation software to listen to "cmnd//POWER" topic with a payload "HOLD". This is sent in case of long press. |
I figured that much, but i can't seem to find the correct way to do it. |
@TRIROG: Something like that:
This is the second variation in the last line of the table:
|
5.1.7 20170616 * Prep removal of SetOptions alternatives * Restore webpage upgrade error messages removed in 5.1.5 * Add hold button functionality to buttons 2 to 4 * Add command SetOption32 1..100 to set Key Hold Time from 0.1 seconds to 10 seconds (#200) * Allow slashes in Topic, GroupTopic, ButtonTopic and SwitchTopic (#507) * Changed webpage form actions from post to get and use relative path url (#434, #522)
Is there any way to give feedback to user on Sonoff Touch that the HOLD event was triggered? Maybe blink a led or something? |
Hello, Thanks for all your work @arendst ! Can you tell me how you coded the multipress and longpress in domoticz mqtt messages? I would like to suggest simulating a selector switch using levels, just like the xiaomi button works : 10 = single This would give a MQTT message like this (this is an example, I need to check tonight the right syntax)
|
3.1.13 20170107 * Fix web console command input when SUB_PREFIX contains '/' (arendst#152) * Add command response to web command (arendst#200) * Add option to disable MQTT as define USE_MQTT in user_config.h (arendst#200)
3.1.14 20170107 * Add support for command TOGGLE (define MQTT_CMND_TOGGLE) when ButtonTopic is in use and not equal to Topic (arendst#207) * Fix web console command input when SUB_PREFIX contains '/' (arendst#152) * Add command response to web command (arendst#200) * Add option to disable MQTT as define USE_MQTT in user_config.h (arendst#200)
if you set buttontopic, by default one press will send the remote message, two
presses will change the local relay as if buttontopic wasn't set.
I believe that this is now configurable.
|
|
Hi, Can the button configuration options (table) work with T1 with more than 1 switches, i.e., configuring both options and topics individually for 2 or 3 switches? Say, with a double tap (or long press), I would like to have a delayed toggle; is it possible to configure? Thanks, |
On Sun, 12 Nov 2017, Robert wrote:
Can the button configuration options (table) work with T1 with more than 1 switches, i.e., configuring both options and topics individually for 2 or 3 switches?
no buttontopic works for all buttons, switchtopic affects all switches.
multipress only works on the first button, it was created to work around the
hardware limit of only one button on the stock sonoff devices.
k
|
I have a T1 3ch and have it configured like this:
Now, I get "ON/OFF" when I both press and doublepress the button. If I set SetOption11 to 0, I get for both single and doublepress "TOGGLE". This is not expected. What can be an affecting option? I am using version 5.10 |
Hello, I'm just starting to use the sonoff. Thank |
Can this be used on one of the GPIO's set as a button? I have tried it but it doesnt seem to work. |
hello could some one answer me what i hope is a simple question. in the table for button multi presses. lets take the last 3 row option 1 and 11 are both set to on, button topic is set to what i require it to be called (button2) but how do you change between the different results, ie if i double press i get cmnd/button2/power = toggle and i would like cmnd/button2/power =on/off . |
What does "reset 1" mean, within the actions table, under "Press Hold"? |
Is it possible to distinguish between different kinds of button presses of the 433 MHz button of the Sonoff RF? This way I could control a second Sonoff (Basic) from the 433 MHz button. EDIT: Ok, (kinda) disregard this - HOLD works with the RF button, but double press does not. Would be nice if this could be implemented. |
5.1.6 20170606 * Shrink code * Removed online configuration of Domoticz In and Domoticz Out MQTT strings * Removed commands DomoticzInTopic and DomoticzOutTopic * Add define KEY_HOLD_TIME to configure button hold threshold before sending MQTT Hold message * Add command StateText4 to configure button MQTT Hold text (= MQTT_CMND_HOLD) * Add command SetOption11 0|1 to swap pushbutton single and double press functionality (arendst#200) * Add command SwitchMode<x> 5 (PUSHBUTTONHOLD) and 6 (PUSHBUTTONHOLD_INV) (arendst#489)
5.1.7 20170616 * Prep removal of SetOptions alternatives * Restore webpage upgrade error messages removed in 5.1.5 * Add hold button functionality to buttons 2 to 4 * Add command SetOption32 1..100 to set Key Hold Time from 0.1 seconds to 10 seconds (arendst#200) * Allow slashes in Topic, GroupTopic, ButtonTopic and SwitchTopic (arendst#507) * Changed webpage form actions from post to get and use relative path url (arendst#434, arendst#522)
When the button is press one time the relay toggle and a MQTT message is published
When the button is pressed two times sonoff do the same. (Except Sonoff Dual)
Sugestion:
Can you add this in the future release ?
I use this code to control a second less accesibile Sonoff from a Sonoff Touch.
The text was updated successfully, but these errors were encountered: