Tasmota Singe, Double, tripple press

Im using Tasmota on several switches and need more actions on my buttons.
Tasmota is already set-up and when I press a button multiple times, I can see the console log with

9:43:32 MQT: stat/pRSW_DG01/BUTTON3 = {"ACTION":"SINGLE"}
09:43:34 MQT: stat/pRSW_DG01/BUTTON3 = {"ACTION":"DOUBLE"}
09:43:36 MQT: stat/pRSW_DG01/BUTTON3 = {"ACTION":"TRIPLE"}
09:43:38 MQT: stat/pRSW_DG01/BUTTON3 = {"ACTION":"QUAD"}

ideally I just want to trigger rules on certain events like Button3 double press. It would be great if I don´t need to create a virtual switch for every possible state and instead just trigger on string updates with case statements like double, triple, hold etc…

My current things definition file look like this:

        Type switch : power01   "dgshutterSwitch1"  [stateTopic="stat/pRSW_DG01/POWER1", commandTopic="cmnd/pRSW_DG01/POWER1", on="ON", off="OFF"  ]
        Type string : power01A  "dgshutterSwitch1A" [stateTopic="stat/pRSW_DG01/BUTTON1", transformationPattern="JSONPATH:$.ACTION" ]

        Type switch : power02   "dgshutterSwitch2"  [stateTopic="stat/pRSW_DG01/POWER2", commandTopic="cmnd/pRSW_DG01/POWER2", on="ON", off="OFF"  ]
        Type string : power02A  "dgshutterSwitch2A" [stateTopic="stat/pRSW_DG01/BUTTON2", transformationPattern="JSONPATH:$.ACTION" ]

        Type switch : power03   "dgshutterSwitch3"  [stateTopic="stat/pRSW_DG01/POWER3", commandTopic="cmnd/pRSW_DG01/POWER3", on="ON", off="OFF"  ]
        Type string : power03A  "dgshutterSwitch3A" [stateTopic="stat/pRSW_DG01/BUTTON3", transformationPattern="JSONPATH:$.ACTION" ]

       //Status commands
        Type string : status    "Status"            [stateTopic="tele/pRSW_DG01/LWT"]
        Type number : wifi      "RSSI"              [stateTopic="tele/pRSW_DG01/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
 		Type string : Version   "Firmware"          [stateTopic="tele/pRSW_DG01/STATUS2", transformationPattern="JSONPATH:$.StatusFWR.Version"]

my Item is defined as:

Switch	pRSW_DG01_1			"pRSW_DG01 01 ShutterUP"						(pRSWDebug,gDG)		{channel="mqtt:topic:MQTTBrokerMT:pRSW_DG01:power01", expire="1s,command=OFF"}
Switch	pRSW_DG01_2			"pRSW_DG01 02 Light"							(pRSWDebug,gDG)		{channel="mqtt:topic:MQTTBrokerMT:pRSW_DG01:power02"}
Switch	pRSW_DG01_3			"pRSW_DG01 03 ShutterDWN"						(pRSWDebug,gDG)		{channel="mqtt:topic:MQTTBrokerMT:pRSW_DG01:power03", expire="1s,command=OFF"}
String	pRSW_DG01_1A		"pRSW_DG01 01 Press [%s]"						(pRSWDebug)			{channel="mqtt:topic:MQTTBrokerMT:pRSW_DG01:power01A"}
String	pRSW_DG01_2A		"pRSW_DG01 02 Press [%s]"						(pRSWDebug)			{channel="mqtt:topic:MQTTBrokerMT:pRSW_DG01:power02A"}
String	pRSW_DG01_3A		"pRSW_DG01 03 Press [%s]"						(pRSWDebug)			{channel="mqtt:topic:MQTTBrokerMT:pRSW_DG01:power03A"}
String	pRSW_DG01_Status	"pRSW_DG01 Status [%s]"				<check>		(pRSWDebug)			{channel="mqtt:topic:MQTTBrokerMT:pRSW_DG01:status"}
Number	pRSW_DG01_Wifi		"pRSW_DG01 Wifi [%s %%]"			<antenna>	(pRSWDebug)			{channel="mqtt:topic:MQTTBrokerMT:pRSW_DG01:wifi"}

My rule:

val logName = "Wallmount Switches"
rule "pRSW_DG01_1 Multipress"
		Item pRSW_DG01_1A received update
	    switch pRSW_DG01_1A.state.toString  {
			case "SINGLE": {
        	logInfo(logName, "pRSW_EG01_1" + pRSW_DG01_1A.state.toString)
			case "DOUBLE": {
        	logInfo(logName, "pRSW_EG01_1" + pRSW_DG01_1A.state.toString)
			case "TRIPLE": {
        	logInfo(logName, "pRSW_EG01_1" + pRSW_DG01_1A.state.toString)
			case "QUAD": {
        	logInfo(logName, "pRSW_EG01_1" + pRSW_DG01_1A.state.toString)
			case "HOLD": {
        	logInfo(logName, "pRSW_EG01_1" + pRSW_DG01_1A.state.toString)

I updated my code to the correct solution if anyone is having the same question…

1 Like

JSONPATH is case sensitive. “ACTION” =/= “Action”

But topic xx/POWER3 =/= topic xx/BUTTON3 neither.

1 Like

Your stateTopic is incorrect: should be BUTTON3, not POWER3

Edit: and the case sensitive Action, as @rossko57 mentioned mere seconds before me!!

1 Like

thanks, worked like a charm.

Hi @jamsven
I’m trying to setup my first openhab system using Sonoffs, mqtt and openHab (not straightforward)
By default the Tasmota firmware does not have the double, triple or long push .
Which mode do you use for the sonoff? I’ve been trying setOption 73 but I’m not sure that is the best one.

I think that is interesting to detach the button from the relay (which is programmed by default) and use the rules to decide the actions to perform .

So which mode do you use?

Due to the fact that the Tasmota firmware publishes all the buttons to the same topic. It seems like
you need to filter the payload you want to the item from the channel.

eg. I used…REGEX:(.Button2.)∩JSONPATH:$.Button2.Action in the channel Incoming Value Transformations for button2 because whenever I’d press button 1 I would get this error.

Executing the JSONPATH-transformation failed: Invalid path ‘$.Button2.Action’ in '{“Button1”:{“Action”:“DOUBLE”}}

Or is there a better way to do this?

For the case of a button, you might look at use of the trigger= option of the channel, and generate an event instead of Item state(s).