Tasmota Long Press Actions - 2023 Update

Hi Guys,

Wanted to share an update since few years went by, and tasmota has changed the way MQTT messages are formed as it’s now a direct HA integration “Tasmota Native” rather than previous versions where it was an HA discovery. SetOption19 1 - For HA discovery, now it’s deprecated and is no longer working.

1. Prerequisites
Assuming you already have done the following

  • Device is Tasmota Flashed, current version June 2023 - Version 12.5
  • Correct Template for the Device is already enabled and all is working as should (relay, button, led etc)
  • MQTT is installed on HA and working
  • Tasmota Device is talking to your MQTTT
  • Native Integration is working
  1. Options to set on Tasmota Device
    Let’s prepare the device, and in case you have changed some defaults, adding here so it’s clear what needs to be set:

SetOption19 0 (default) - This will enable discovery via tasmota HA integration
SetOption1 0 (default) - This will allow multipress actions
SetOption13 0 (default) - This will not trigger the device but enable multipress actions
SetOption32 20 - Recommended set time for HOLD response (default is 40ms)
SetOption4 1 - This will change the way messages are formed for MQTT. Return MQTT response as 1 = %COMMAND% topic ex. devicename/stat/BUTTON1T instead of default devicename/stat/RESULT
ButtonTopic 0 (default) - This must be set to make it work in this example
FullTopic %topic%/%prefix%/ - This must be set to make it work in this example
SetOption73 1 - This will Detach buttons from relays and send multi-press and hold MQTT messages instead. Pressing the button from now on will not trigger the RELAY and it will not turn on your device. Instead the device will now generate example:

devicename/stat/BUTTON1 {“Button1”:{“Action”:“SINGLE”}}

** you can check this in the console on the device, it will spit out the exact code when you press, multipresss, hold etc.

To re-enable buttons, a rule must be set, so every time you press the button it actually turns on the device. To do this set the rule like this:

First Button Rule:
Rule1 ON button1#state=10 DO power1 2 ENDON
Rule1 1
Second Button Rule:
Rule2 ON button1#state=10 DO power2 2 ENDON
Rule2 1
Third Button Rule:
Rule3 ON button3#state=10 DO power3 2 ENDON
Rule3 1

3. Automating
Let’s do something with these new options that will be sent to HA. In this example I’ll use QUAD - Tap option.

- id: '1595194155114'
  alias: Kitchen Bar - Quad Tap
  description: 'Quad Tap - Kitchen, All devices off'
  trigger:
  - platform: mqtt
    topic: devicename/stat/BUTTON1
    value_template: '{{value_json.Button1.Action }}'
    payload: QUAD
  condition: []
  action:
  - type: turn_off
    entity_id: switch.kitchen_hall
    domain: switch
  - type: turn_off
    entity_id: switch.kitchen_bar
    domain: switch
  mode: single

Hope this gives you ideas on how you can extend your tasmota devices with multipress actions.