Tasmota Long Press

My Garge Switch is a pushbutton
its was I first thing I Tasmota so it only had 5.10.0b Had a Idea can I do a long Press and turn ON/OFF the workshop lights

1st upload New verson of tasmota Tasmota latest

  • get the sonoff-minimal.bin and the Latest my case 6.2.1
  • upload minimal first then upload the latest

it work!! didnt have to take out of the wall :slight_smile:

Now go into the Console

we need to change the switchmode

as we want to change switch1

so we just type in “SWITCHMODE1 5” = Set switch mode to PUSHBUTTON (Normally 1, 0 = toggle, Hold = hold)

now we need to change its Topic

so type in “SwitchTopic 1” = Set MQTT switch topic to Topic

and we also need to change the setoption32

I want to hold the button for 4 sec and do its thing

we just type in setoption32 4

now my log say

10:31:14 MQT: cmnd/SONOFF5/POWER1 = ON
10:31:14 MQT: stat/SONOFF5/RESULT = {"POWER":"ON"}
10:31:14 MQT: stat/SONOFF5/POWER = ON (retained)
10:31:17 MQT: cmnd/SONOFF5/POWER1 = OFF
10:31:17 MQT: stat/SONOFF5/RESULT = {"POWER":"OFF"}
10:31:17 MQT: stat/SONOFF5/POWER = OFF (retained)
10:31:19 MQT: cmnd/SONOFF5/POWER1 = HOLD
10:31:19 MQT: stat/SONOFF5/RESULT = {"POWER":"OFF"}
10:31:19 MQT: stat/SONOFF5/POWER = OFF (retained)
10:31:22 MQT: cmnd/SONOFF5/POWER1 = ON
10:31:22 MQT: stat/SONOFF5/RESULT = {"POWER":"ON"}
10:31:22 MQT: stat/SONOFF5/POWER = ON (retained)
10:31:25 MQT: cmnd/SONOFF5/POWER1 = OFF
10:31:25 MQT: stat/SONOFF5/RESULT = {"POWER":"OFF"}
10:31:25 MQT: stat/SONOFF5/POWER = OFF (retained)
10:31:27 MQT: cmnd/SONOFF5/POWER1 = HOLD
10:31:27 MQT: stat/SONOFF5/RESULT = {"POWER":"OFF"}
10:31:27 MQT: stat/SONOFF5/POWER = OFF (retained)

NOTE the cmnd/SONOFF5/POWER1 we have to change HA to this

In the light section

  - platform: mqtt
    entity_id: GarageLight
    name: "Garage"
    friendly_name: "Garage Lights"
    state_topic: "stat/SONOFF5/POWER"
    command_topic: "cmnd/SONOFF5/POWER1"   # was cmnd/SONOFF5/POWER
    payload_on: "ON"
    payload_off: "OFF"

now we add a sensor to read the command_topic
but in HA we put it in the state_topic:

in the sensor section

  - platform: mqtt
    name: "Garge Light"
    state_topic: "cmnd/SONOFF5/POWER1"
    qos: 1
    expire_after: "1"  # Forget what just happen

note expire_after: this just expire the sensor value back to Unknown
so we dont have to right a automation to set it out of the HOLD

Now the fun bit the Automation

- id: 'hold garge light'
  alias: Hold Garge Light
  initial_state: true
  trigger:
  - entity_id: sensor.garge_light
    platform: state
    to: 'HOLD'
  action:
  - data:
      entity_id: light.workshop
    service: light.toggle

NOW when I long PRESS the garage light the workshop light toggle

well that has save me 3 steps

8 Likes

Thanks a lot for this! Exactly what I was looking for, except in my case it’s SwitchMode 6 (inverted).

One small thing I noticed: in the sensor configuration the retain attribute needs to be removed.

Yes you are right
that how old this code is I did not under the retain thing back then

Hi Guys,

Wanted to share double/triple/quad actions, as it might be easier to use.

First, lookup in console of tasmota what is the exact device / topic etc, in my case:
MQT: living_light/stat/BUTTON1T = {“TRIG”:“SINGLE”}
MQT: living_light/stat/BUTTON1T = {“TRIG”:“DOUBLE”}
MQT: living_light/stat/BUTTON1T = {“TRIG”:“TRIPLE”}
MQT: living_light/stat/BUTTON1T = {“TRIG”:“QUAD”}

Next Ensure you have these options set:
SetOption1 1 to prevent unwanted resets etc.
SetOption13 0 to enable multipress (this is on by default, but some of you might have set it to 1 to get a quicker reaction)

Next create a sensor:

  • platform: mqtt
    name: “Living Light Button Tap”
    state_topic: “living_light/stat/BUTTON1T”
    qos: 1
    expire_after: “60”

Next reload config, so the sensor gets created.

Next Automation is easy to trigger, Examples below:

  • id: ‘1592568082210’
    alias: Living Light - Double Tap
    description: ‘’
    trigger:

    • entity_id: sensor.living_light_button_tap
      platform: state
      to: ‘{“TRIG”:“DOUBLE”}’
      action:
      "whatever you needed to do"
  • id: ‘1592568082211’
    alias: Living Light - Triple Tap
    description: ‘’
    trigger:

    • entity_id: sensor.living_light_button_tap
      platform: state
      to: ‘{“TRIG”:“TRIPLE”}’
      action:
      "whatever you needed to do"
  • id: ‘1592568082212’
    alias: Living Light - Triple Tap
    description: ‘’
    trigger:

    • entity_id: sensor.living_light_button_tap
      platform: state
      to: ‘{“TRIG”:“TRIPLE”}’
      action:
      "whatever you needed to do"

good work bro

BUT can you format your code will make easyer to read

platform: mqtt
name: "Living Light Button Tap"
state_topic: "living_light/stat/BUTTON1T"
qos: 1
expire_after: "60"

hit this
image
3 time
paste code
and hit 3 time again

1 Like

You forgot to tell : tasmota 8.3.x needed. Won’t work on previous releases.

1 Like

as its a json message you could

you can replace

platform: mqtt
name: "Living Light Button Tap"
state_topic: "living_light/stat/BUTTON1T"
qos: 1
expire_after: “60”

with

  - platform: mqtt
    name: "Living Light Button Tap"
    state_topic: "living_light/stat/BUTTON1T"
    value_template: "{{value_json.TRIG }}"
    qos: 1
    expire_after: "60"

it would only show whats been press SINGLE
yours is {“TRIG”:“SINGLE”}

good to see your playing bro

1 Like

thanks for the tip. this will make it cleaner :slight_smile:

1 Like

all good bro

1 Like

As I just upgraded to Home Assistant 2022.12.3, this stopped working. Been using this for the last 2 years. Anyone know how to change this or use something better?

Ok … figured it out. MQTT Changed the way they define sensor in the ha configuration, so sensor on it’s own - no longer applicable

so did an upgrade instead by re-writing the automations using the mqtt triger direct. The trick was to use the YAML code, and apply the value.template

alias: Bathroom Light - Quad Tap - All Off
description: ""
trigger:
  - platform: mqtt
    topic: bathroom_1/stat/BUTTON1T
    value_template: "{{value_json.TRIG }}"
    payload: QUAD
condition: []
action:
  - device_id: ffbb1963d64740b3a1041516c621524a
    domain: switch
    entity_id: switch.bathroom_1
    type: turn_off
  - type: turn_off
    device_id: 733ea53032a00ed6d0c6804c2c7c3cdc
    entity_id: switch.bathroom_2
    domain: switch
  - device_id: 8bf2b1f7c2454b3ca67208e36259eb4b
    domain: switch
    entity_id: switch.bathroom_2_plug
    type: turn_off
  - type: turn_off
    device_id: e478511b6da84b3c95ea01381ffb7220
    entity_id: switch.bathroom_fan
    domain: switch
  - service: light.turn_off
    data: {}
    entity_id: light.hall_2
  - service: media_player.turn_off
    target:
      device_id: 079d688e6182806d1a02856afb15b6fe
    data: {}
mode: single

Or you simply could use (in your configuration.yaml):

mqtt:
  sensor:
    - name: e.g. Whiskey Button

Instead of previous:

sensor:
  - platform: mqtt

If we are pointing to the same (I believe yes).

I landed here to ask the question, would it possible to parse json output somehow to show state only, not whole “sosage”, then I saw it is already answered :grinning:
Thank you for the hint!

All good then?