Tasmota: Shelly 1 - double/tripple press and HOLD function

Created on 22 Oct 2018  路  11Comments  路  Source: arendst/Tasmota

I'm trying to figure out how the Shelly1 should be configured for the double/tripple press and HOLD function to be working.

Here is what i have configured so far:
Setoption1 1
Setoption11 1
setoption32 40 (default)
Switchmode 5

I'm working with a momentary/push-button and this is working, but I'm not seeing the HOLD-function appearing in the console.

I've found some articles and following them, my config should work:
https://community.home-assistant.io/t/sonoff-double-triple-tap/38838

Is this functionality not working because it is seen as a switch and not a button? Or some other reason this isn't working (yet)?

question

Most helpful comment

The following is only confirmed to work with SHELLY 1 due to its hardware characteristic. Other modules might need different GPIO settings

I was struggling with the same problem, to configure a Shelly 1 in a way that it is reacting on pushbutton presses (single, double and hold), while nothing is connected to the relay.

Like mentioned above, the solution was to change to the Generic (0) module template and set up:

  • GPIO4 as "Relay 1"
  • GPIO5 as "Button1in"

The GPIO5 does the magic, and it is wrong in the message above. Note the exact spelling, as specifically for the Shelly 1, it must be th "1in" button style, where "i" means inverted signal and "n" means no pullup resistor.

After this, my setup was:
; restrict to single, double, hold (you might want to leave it with the default 0!
Setoption1 1
; do not swap single and double press functionality (if you set it to 1, you have to change the states in the rule)
Setoption11 0
; single, multi-press and hold button actions
Setoption13 0
; mode: pushbutton with hold
SwitchMode 5
; 50 ms hold time
SetOption32 5

Now to recognize all three button press types, I use the following rule:

Rule1
on button1#state=3 do websend [192.168.4.119] event s1=3600 endon
on button1#state=2 do websend [192.168.4.119] event s1=900 endon
on power1#state=1 do backlog power1 off; websend [192.168.4.119] event s1=1800 endon

Explanation: single press will send "event s1=900" to another tasmota device, hold for >= 50 ms duration will send "event s1=3600" to another tasmota device. Double press is special as it doesn't "send" a button state but toggles the relay. As I don't use that relay, I monitor for a toggle to ON (which is the double press), then send "event s1=1800" to another tasmota and then reset the relay to off.

You can and have to replace all the "websend ..." commands with your own functionality of course.
Then, activate that rule with

Rule1 1

Note that if you didn't configure GPIO4 as a relay in the template, a double click will show a power toggle, but the "power1#state" rule isn't fired.

All 11 comments

Hi, you are right. Switches only can't handle double press. Triple press is not supported in Tasmota.

Buttons support single press, double press and hold
Switches as keys, supports just change of state.
Switches as pushbuttons (see switchtopic in the wiki) supports single press and hold.

For using these last two, please see the examples at rules in the wiki.

Thanks

Closing this issue as it has been answered.

If you have further questions please do not hesitate to follow one of the provided support entry points listed below.

Support Information

See Wiki for more information.
See Community for forum.
See Chat for more user experience.

Thanks a lot for answering my noob-questions.

I've been going through the wiki, thehookup and DrZzs and with that info i managed to get this working thus far. The info i can't find is the difference between a switch and a button, only that there is.

I can relate it to GPIO-pins or inputs on the ESP-chip, but i can't see why there should be a difference in terminology when i read the wiki. Why is a switch a switch and a button a button and why does it matter?
As for the sonoff devices, i can relate that there are soldering points for the psysical button and GPIO pins that you can use for switches but also for sensors etc., but why is a physical push button soldered to the Sonoff button-pins called a button, and the same push button to a GPIO-pin a switch?
The Shelly1 does only have one connection where i've connected my push button, but for some reason this physical push button is called switch inside Tasmota and there are no settings to be made unless it is configured as a Sonoff Basic.

As i see it with my own programming skills is that setoption32 sets a timer of 40ms.

  • 1x press inside 40ms triggers the relay
  • 2x press inside 40ms triggers MQTT doublepress
  • HOLD and no release inside 40ms triggers MQTT HOLD

But for some (obviously good) reason there is a difference in a button and a switch in the sonoff devices and therefore in Tasmota and this also influences the Shelly1.

I will look into the rules. Letscontrolit also has a nice topic on that.
https://www.letscontrolit.com/forum/viewtopic.php?t=2637

EDIT: maybe to clarify.
I would like to use the Shelly1 as a cheap remote to control my Philips Hue bulbs with my own Gira push buttons. I don't intend to really use the electric relay of the Shelly1 as the Hue lights always need to be powerd on.
In my setup i use Fibaro Dimmer 2's on Z-Wave and this functionality works flawlessly, but the Shelly1 is pricewise a very good alternative, plus i really like the open-source functionality of Tasmota. Therefore is would be a good match to expand with the Shelly1 instead of Fibaro's.
So if i compare the Fibaro with the Shelly, they look almost identically, but there must be something inside why the fibaro can do all that i would like and the Shelly 1 not..

Hi,

A switch is the key you have in your home to turn on the lights. When you touch it, it flips to on and it keeps that way until you touch again and flips to off.

A button is a pushbutton. When you touch it, it gives you a 1 and when you release it, it gives you a zero.

So, for a switch, if you see a 1 you turn a relay on until it goes to zero.
For a button, if you see a 1 you turn a relay on. You ignore the zero, and when you see another 1, you turn that relay off (that is called toggle)

So, as a switch and a pushbutton are physically different, you need to differenciate them.

Now, you can differenciate a switch from a button.

Now, using a switch there are several configurations you can do. For getting deep into that, you need to see the commands in the wiki at switchmode.

Besides the wiki, you can also search in issues. This was already addressed.

ESPEasy and Tasmota are different softwares aimed to different objectives with different concepts. So, if you read there, might not be the same in Tasmota and viceversa.

So concluded: the Shelly1 can't be configured as a button and only as a switch?

the physical button on the Sonoff is a (push button). If i solder a Gira push button to it, Tasmota will address it as a (push) button.
If i connect a Gira push button to the one of a GPIO-pin, it is seen as a switch. If i flip the switch and do not keep it pushed it turns off.

But when i set Switchmode1 5, the wiki says "Set switch mode to PUSHBUTTON". Now it acts like a push button should be working. But it Tasmota terms is it still a switch? like a simulated push button on a switch?

I've read a lot of topics about this, but this last part is where all topics stop and don't get answered.

the Shelly1 can't be configured as a button and only as a switch?

yes, that is in the template

But when i set Switchmode1 5, the wiki says "Set switch mode to PUSHBUTTON". Now it acts like a push button should be working. But it Tasmota terms is it still a switch? like a simulated push button on a switch?

Yes

You are right about the template. When using the config below with a GENERIC module i got the HOLD function working as a button. I can't get a double press working with a TOGGLE message.

Generic module
GPIO4 21 relay1
GPIO5 90 Button1n

MQTT 10.0.0.13

setoption1 1
setoption11 1
setoption32 40
buttontopic ceilingfan

I've read the rules section and i think rule 16 is exactly what i need?
I've rename button1 on the example to button1n as that is what is configured?

rule on button1n#state=3 do publish cmnd/topicHOLD/power 2 endon on button1n#state=2 do publish cmnd/topicDOUBLEPRESS/power 2 endon

After this i still get a HOLD message when i doublepress the push button.

15:03:25 CMD: rule1
15:03:25 MQT: stat/shell1/RESULT = {"Rule1":"OFF","Once":"OFF","StopOnError":"OFF","Free":385,"Rules":"on button1n#state=3 do publish cmnd/topicHOLD/power 2 endon on button1n#state=2 do publish cmnd/topicDOUBLEPRESS/power 2 endon"}
15:03:35 MQT: cmnd/ceilingfan/POWER = HOLD
15:06:35 MQT: cmnd/ceilingfan/POWER = HOLD

Any thoughts? Would be great to get this working as it adds an extra to the stock firmware of the shelly.

As answered to you in the chat:

button1n#state will not work in rules. Just use button1#state

the n in module config means NO PULL UP RESISTOR.

if you use switchtopic or buttontopic, that will override rules

@JDunnio I am attempting to get this to work on my shelly1 and am glad I came across this. Question, to use the rule that you have set do the setoptions and buttontopic need to be set as you have in your post? Also using the rule it looks like state 3 is hold, state 2 is double and would state 1 or a single press trigger the relay on the shelly?

Hi All.
I am trying to achieve something similar except instead of switching a Sonoff Relay, I want to turn on/off a Hue Light bulb
Is there anyway to send a service command using rules?

  1. Push Push button connected to Sonoff via GPIO3
  2. Toggle the push button to turn light on or off
  3. The light is a Phillips hue so not connected to the Sonoff Relay
  4. Only using a Sonoff to utilise the GPIO commands and or MQTT
  5. I can use rule to switch another Sonoff connected to a different light. (This is NOT want I want to do)
  6. Use the Sonoff to toggle a light only
    Hope that makes sense?

I can use Home Assistant to control the Hue Light however I want to do it via a push button

Any help would be appreciated
Cheers

The following is only confirmed to work with SHELLY 1 due to its hardware characteristic. Other modules might need different GPIO settings

I was struggling with the same problem, to configure a Shelly 1 in a way that it is reacting on pushbutton presses (single, double and hold), while nothing is connected to the relay.

Like mentioned above, the solution was to change to the Generic (0) module template and set up:

  • GPIO4 as "Relay 1"
  • GPIO5 as "Button1in"

The GPIO5 does the magic, and it is wrong in the message above. Note the exact spelling, as specifically for the Shelly 1, it must be th "1in" button style, where "i" means inverted signal and "n" means no pullup resistor.

After this, my setup was:
; restrict to single, double, hold (you might want to leave it with the default 0!
Setoption1 1
; do not swap single and double press functionality (if you set it to 1, you have to change the states in the rule)
Setoption11 0
; single, multi-press and hold button actions
Setoption13 0
; mode: pushbutton with hold
SwitchMode 5
; 50 ms hold time
SetOption32 5

Now to recognize all three button press types, I use the following rule:

Rule1
on button1#state=3 do websend [192.168.4.119] event s1=3600 endon
on button1#state=2 do websend [192.168.4.119] event s1=900 endon
on power1#state=1 do backlog power1 off; websend [192.168.4.119] event s1=1800 endon

Explanation: single press will send "event s1=900" to another tasmota device, hold for >= 50 ms duration will send "event s1=3600" to another tasmota device. Double press is special as it doesn't "send" a button state but toggles the relay. As I don't use that relay, I monitor for a toggle to ON (which is the double press), then send "event s1=1800" to another tasmota and then reset the relay to off.

You can and have to replace all the "websend ..." commands with your own functionality of course.
Then, activate that rule with

Rule1 1

Note that if you didn't configure GPIO4 as a relay in the template, a double click will show a power toggle, but the "power1#state" rule isn't fired.

Was this page helpful?
5 / 5 - 1 ratings

Related issues

renne picture renne  路  3Comments

grizewald picture grizewald  路  3Comments

TylerDurden23 picture TylerDurden23  路  3Comments

abzman picture abzman  路  3Comments

ximonline picture ximonline  路  3Comments