I've been using an LED strip with a Magichome controller running Tasmota for more than a year now. A while back I set up a long press to trigger a stateless programmable button in my HomeKit setup. What I ended up actually using the long press for was a kind of nightlight toggle: If the lights were set to more than 50% I'd set them to 5% and vice versa. But this setup has a ton of moving parts so from time to time it'd stop working. I knew of Tasmota's rules functionality, so I wanted to switch to it thinking this really should done be on device.
Since figuring how to do this took me a bit of time. I thought I'd write up a small explainer.
Keywords: Tasmota long-press dimmer toggle, Tasmota rules conditional, Tasmota dimmer high-low toggle, Tasmota rules long press action, Tasmota long-press trigger.
Some background settings:
Backlog SwitchMode 5; ButtonTopic 0; SetOption73 1; SetOption32 12
SwitchMode 5 meaning set push-button with long press mode (0 = TOGGLE, 1 = ON (default), long press = HOLD)
SetOption73 decouples button1 (which usually has a special status) from power and multi-presses, functionality which we will gain back with Rule1 below.
SetOption32 the number of 0.1 seconds to hold button before sending HOLD, holding the button 10x the amount performs firmware defaults reset. Here I choose 1.2 and 12 seconds.
Backlog just executes these at once.
Then the first rule which I call here Rule2
Rule2
ON dimmer#state>50 DO mem1 5 BREAK ON dimmer#state DO mem1 95 ENDON
Rule2 1
Backlog Dimmer1 95When the value of dimmer changes to a value greatter than 50 it sets mem1 (one of 16 available presistant varibles) to 5, and when the value of the dimmer is smaller it sets mem1 to 5. You can change these values to your preferences.
Rule1
ON button1#state=10 DO power1 2 ENDON
ON button1#state=3 DO dimmer %mem1% ENDON
ON button1#state=11 DO publish cmnd/tasmota_OTHERDEVICE/power 2 ENDON
Rule1 1The value of mem1 is read with this rule when button1 state is 3 - meaning HOLD.
State 10 just means a single press which than sets power1 2 - meaning toggle power1. Additionally state 11 means double press and here I use it to toggle power on another device nearby.