Device button with 4 different actions

DEVICE BUTTON WITH 4 DIFFERENT ACTIONS
Tasmota Version 8.3.1 button and switch commands.

EDIT May 28 2020 Added to bottom of post:
Sonoff Touch multiple press and group topic

This works 1 short press, 2 short press, 3 short press and long press on tasmota Sonoffs basic button to toggle other MQTT devices. Remote MQTT Controlled devices do not need to be V8.3.1

!!! WORKS!!!
On a devices that has a button,switch or touch pad.

This is with a tasmota V8.3.1 sonoff basic fixed to a living floor lamp.
IMG_20200527_103812

I wanted the Sonoff basic button pushed onced to toggle the relay ON\OFF to the lamp.
(NO CHANGE from default)

Now I want to hold the button down for 1.5 seconds to toggle ON\OFF kitchen sink light.
And then push putting twice to toggle ON\OFF kitchen overhead light and so on…

Setup on the device to operate push button.
** BACK UP FIRST :skull_and_crossbones:**
SetOption can now be shortened to SO in 8.3.1
In tasmota console input:

SO1 1

SetOption1 Set button multipress mode to
0 = allow all button actions (default)
1 = restrict to single to penta press and hold actions (i.e., disable inadvertent reset due to long press)

Next
(optional)for auto discovery if using Home assistant without yaml.

SO19 1

** Check your other settings.**
Use this backlog.

Backlog SwitchMode1;SwitchTopic1;SetOption73;ButtonTopic1

Should look like this:
“SwitchMode1”:“0” or “SwitchMode1”:“OFF”
“SetOption1”:“1” or “SetOption1”:“ON”
“SwitchTopic”:"" or “SwitchTopic”:“0”
“SetOption73”:“0” or “SetOption73”:“OFF”
“ButtonTopic”:"" or “ButtonTopic”:“0”

Second step:
Set button hold time to 1.5 seconds.
On Lamp tasmota console input

SetOption32 15

SetOption32 Number of 0.1 seconds to hold button before sending HOLD action message.
1…100 to set button hold time (default = 40). This option also affects the time required to perform a firmware defaults reset (10x HOLD action time)

Then type in the rules:

(you can put all in one rule but I like to be able to shut off and on each rule.)

Find the MQTT topic of the device(s)you wish to remotely toggle.
Can view in tasmota device info.

Screenshot_20200527-123915_2

*Check what the order of
prefix/topic or topic/prefix
In tasmota device info or console
by typing

Fulltopic
will look like this or reversed
“FullTopic”:"%prefix%/%topic%/"

kids_bedroom_light/cmnd/
or
cmnd/kids_bedroom_light/

List of button states

  • 10=1 short press
  • 11=2 short press
  • 12=3 short press
  • 13=4 short press
  • 14=5 short press
  • 3=LONG press

Input rules in the tasmota console
each rule is for 3 other devices to toggle from this button.

In console input with your device topic replace device_topic with your prefix/topic order:

Rule1 ON 
button1#state=3 DO publish cmnd/device1_topic/POWER 2 ENDON

Then type:

Rule1 on

Rule2
ON button1#state=11 DO publish device2_topic/cmnd/POWER 2 ENDON

Then type:

Rule2 on

Then type:

Rule3
ON button1#state=12 DO publish device3_topic/cmnd/POWER 2 ENDON

*Then type:

Rule3 on

Single gang Sonoff Touch

sonoff_touch_us
This switch has Capacitive Touch Sensors as the button. Same procedure as the Sonoff basic just a couple of setting changes for the type of button and group topic.

Tasmota settings for the Sonoff Touch. Version 8.3.1
Before you make any changes, ** BACK UP FIRST :skull_and_crossbones:**

  • SwitchMode1 0
  • SwitchTopic 0
  • SetOption73 OFF
  • ButtonTopic 0
  • SetOption1 ON

I set my kitchen lights in a group called kitchen
You can set group topic by editing each device you want in that group device using the console
grouptopic1 kitchen

My rules for this switch in my bedroom will toggle my bedroom light one press, Two press toggle master bathroom light and Long press Power OFF ALL my kitchen lights.

Set my hold action time to 1.5 seconds.
SetOption32 15

Input my two rules.
Set long two press to toggle bathroom.
ON button1#state=11 DO publish my_bathroom/cmnd/POWER 2 ENDON

Set LONG press to do a grouptopic to shut off all kitchens lights.
Rule2 ON button1#state=3 DO publish kitchen/cmnd/POWER 0 ENDON
kitchen is the name of the group for my kitchen lights.

Tasmota gethub help pages

Enjoy,
diyredneck.thestovedoc.com

5 Likes

added at bottom of post
** Sonoff Touch multiple press and group topic**

1 Like

hay bro

did you see this

also I have this which see the button press
as a sensor

  - platform: mqtt
    name: "SpareRoom"
    state_topic: "stat/SpareRoom/BUTTON1"
    value_template: "{{value_json.ACTION }}"
    qos: 1
    expire_after: 1

automations

- id: 'SpareRoom HOLD'
  alias: SpareRoom HOLD
  initial_state: true
  trigger:
  - entity_id: sensor.spareroom
    platform: state
    to: 'HOLD'
  action:
  - data:
      entity_id: light.sidelamp1_1 , light.sidelamp1_2
    service: light.toggle

- id: 'SpareRoom SINGLE'
  alias: SpareRoom SINGLE
  initial_state: true
  trigger:
  - entity_id: sensor.spareroom
    platform: state
    to: 'SINGLE'
  action:
  - data:
      entity_id: light.toilet
    service: light.toggle

and the expire_after: 1 set it back to ‘unknown’

2 Likes

yes I follow Travis that is how I learned but I like to not use yaml if not needed for easy integration and the future of HA is not using so much yaml.
the tasmota rules you don’t really have to do any automation or node red for multi button push.

you know sensors are auto discovery now? Also no need to add in yaml if you set up in tasmota correctly.
the only things I really have in my yaml files are for Shelly and what other setup for integrations to use.

I don’t even use the input selects or booleans anymore because I use the helpers in front end.

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Example configuration.yaml entry
sensor:
  - platform: systemmonitor
    resources:
      - type: disk_use_percent
        arg: /home
      - type: memory_free
      - type: processor_use
      - type: load_1m
      - type: load_15m
      - type: memory_use
      - type: disk_use
        arg: /home
      - type: disk_free
        arg: /home

  
  
homeassistant:
  customize: !include customize.yaml

# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
# http:
#   base_url: example.duckdns.org:8123

# Text to speech
tts:
  - platform: google_translate
  
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
climate: !include climate.yaml
input_select: !include input_select.yaml
input_boolean: !include input_boolean.yaml
# Example configuration.yaml entry
weather:
  - platform: darksky
    api_key: !secret darksky_api
    
 

#add Shelly's below 
switch:
  - platform: mqtt
    name: "Factory Shelly2 MQTT 1"
    state_topic: "shellies/shelly1-C48852/relay/0"
    command_topic: "shellies/shelly1-C48852/relay/0/command"
    payload_on: "on"
    payload_off: "off"
    retain: false
    icon: mdi:fireplace

    
  - platform: mqtt
    name: "fish feeder"
    state_topic: "shellies/shelly1-C497C8/relay/0"
    command_topic: "shellies/shelly1-C497C8/relay/0/command"
    payload_on: "on"
    payload_off: "off"
    retain: false
    icon: mdi:fish

all good bro

1 Like

Hi, stumble upon this. I have three lights in my kitchen. Two Tasmota lights (a dimmer over the table and a switch for the ceiling light) and a Philips Hue over the sink. I have a 'Home Assistant Switch Plate (HASP) to control everything from the sink where the Hue light is but would like to add some more automations from where the Tasmota ceiling switch is (when you enter the kitchen), like:

  • Single press: Turn the ceiling light on;
  • Double press: Turn all three lights on and set to full brightness for the Tasmota dimmer and Hue light ;
  • Triple press: Turn off the ceiling light and table light, turn on the Hue light at 10%;
  • Hold: Turn all three lights off.

Do you know if it’s feasible with this method?

Thanks.

Not sure about dimer I have non doninhave not played with it.
Travis might know


Heck his discord

I like the Rule in Tasmota that will trigger the scene or buttons in Home Assistant via MQTT. I do not like to mess with limited Rules memory on each switches. Any help will be appreciated. Like a sample codes, Thanks

What is your HA configration.yaml codes look like for this double pressed? Why you send POWER with payload of 2, can it be anything?

Not understanding question. I’m using tasmota rules not yaml.
The switches are mqtt.

My post about Sonoff tx switches with remote control

@Rod_Poplarchick
Did you manage to decouple the button from the local relay?

I can’t seem to stop mine turning the local relay on, which I don’t want, I just want to send the mqtt message relating to the various button press options for home assistant to do things like adjust the temperature for the thermostat in the room (which will likely turn on the relay, but it also does things like call for heat from the boiler).

When you do the setting and rules like explained above yes the relay used for remote decouple.

I can’t make it work. Are you sure this is correct?

There are so many reason why it dont work
you set the setting and the rule in the Master device console and the devicenametopic is the device you want to control.
]is your setting like this?
**Should look like this:
“SwitchMode1”:“0” or “SwitchMode1”:“OFF”
“SetOption1”:“1” or “SetOption1”:“ON”
“SwitchTopic”:"" or “SwitchTopic”:“0”
“SetOption73”:“0” or “SetOption73”:“OFF”
“ButtonTopic”:"" or “ButtonTopic”:“0”

and you have to put the name device name and topic that you want to control.

Rule1 ON
button1#state=3 DO publish cmnd/YOURDEVICENAMETOPIC/POWER 2 ENDON

and you have to turn the rule on
Rule1 1

1 Like

Thanks for the fast help. I am sure I have it all as in your example.

I wonder about “state=3” instead of “state=10”. Tried it but for right now it doesn’t work.

status 0
09:23:27.449 MQT: sonoff/SF_GarageDoorSwitch/STATUS = {"Status":{"Module":1,"DeviceName":"SF_GarageDoorSwitch","FriendlyName":["Tasmota"],"Topic":"SF_GarageDoorSwitch","ButtonTopic":"","Power":1,"PowerOnState":3,"LedState":1,"LedMask":"FFFF","SaveData":1,"SaveState":1,"SwitchTopic":"","SwitchMode":[0,0,0,0,0,0,0,0],"ButtonRetain":0,"SwitchRetain":0,"SensorRetain":0,"PowerRetain":0,"InfoRetain":0,"StateRetain":0}}
09:23:27.463 MQT: sonoff/SF_GarageDoorSwitch/STATUS1 = {"StatusPRM":{"Baudrate":115200,"SerialConfig":"8N1","GroupTopic":"tasmotas","OtaUrl":"http://ota.tasmota.com/tasmota/release/tasmota.bin.gz","RestartReason":"Software/System restart","Uptime":"1T01:53:04","StartupUTC":"2022-12-22T06:30:23","Sleep":50,"CfgHolder":4617,"BootCount":12,"BCResetTime":"2022-10-14T06:10:07","SaveCount":108,"SaveAddress":"FB000"}}
09:23:27.476 MQT: sonoff/SF_GarageDoorSwitch/STATUS2 = {"StatusFWR":{"Version":"12.1.1(tasmota)","BuildDateTime":"2022-08-25T11:33:55","Boot":7,"Core":"2_7_4_9","SDK":"2.2.2-dev(38a443e)","CpuFrequency":80,"Hardware":"ESP8285","CR":"387/699"}}
09:23:27.488 MQT: sonoff/SF_GarageDoorSwitch/STATUS3 = {"StatusLOG":{"SerialLog":2,"WebLog":2,"MqttLog":0,"SysLog":0,"LogHost":"","LogPort":514,"SSId":["home",""],"TelePeriod":300,"Resolution":"558180C0","SetOption":["0000800B","0F05C80001000600003C5A0A002800000000","00000080","00006000","00004000","00000000"]}}
09:23:27.510 MQT: sonoff/SF_GarageDoorSwitch/STATUS4 = {"StatusMEM":{"ProgramSize":624,"Free":376,"Heap":23,"ProgramFlashSize":1024,"FlashSize":1024,"FlashChipId":"144051","FlashFrequency":40,"FlashMode":3,"Features":["00000809","8F9AC787","04368001","000000CF","010013C0","C000F981","00004004","00001000","54000020","00000000"],"Drivers":"1,2,3,4,5,6,7,8,9,10,12,16,18,19,20,21,22,24,26,27,29,30,35,37,45,62","Sensors":"1,2,3,4,5,6"}}
09:23:27.525 MQT: sonoff/SF_GarageDoorSwitch/STATUS5 = {"StatusNET":{"Hostname":"SF-GarageDoorSwitch-5306","IPAddress":"192.168.0.51","Gateway":"192.168.0.1","Subnetmask":"255.255.255.0","DNSServer1":"192.168.0.1","DNSServer2":"0.0.0.0","Mac":"DC:4F:22:9E:74:BA","Webserver":2,"HTTP_API":1,"WifiConfig":4,"WifiPower":17.0}}
09:23:27.540 MQT: sonoff/SF_GarageDoorSwitch/STATUS6 = {"StatusMQT":{"MqttHost":"192.168.0.6","MqttPort":1883,"MqttClientMask":"SF_GarageDoorSwitch","MqttClient":"SF_GarageDoorSwitch","MqttUser":"kai","MqttCount":1,"MAX_PACKET_SIZE":1200,"KEEPALIVE":30,"SOCKET_TIMEOUT":4}}
09:23:27.555 MQT: sonoff/SF_GarageDoorSwitch/STATUS7 = {"StatusTIM":{"UTC":"2022-12-23T08:23:27","Local":"2022-12-23T09:23:27","StartDST":"2022-03-27T02:00:00","EndDST":"2022-10-30T03:00:00","Timezone":99,"Sunrise":"08:41","Sunset":"16:56"}}
09:23:27.572 MQT: sonoff/SF_GarageDoorSwitch/STATUS10 = {"StatusSNS":{"Time":"2022-12-23T09:23:27","Switch1":"ON"}}
09:23:27.588 MQT: sonoff/SF_GarageDoorSwitch/STATUS11 = {"StatusSTS":{"Time":"2022-12-23T09:23:27","Uptime":"1T01:53:04","UptimeSec":93184,"Heap":25,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":1,"POWER":"ON","Wifi":{"AP":1,"SSId":"home","BSSId":"50:XX:F6:83:31:5C","Channel":1,"Mode":"11n","RSSI":100,"Signal":-49,"LinkCount":1,"Downtime":"0T00:00:03"}}}

I still don’t understand your question
Need more information.
Can you type rule1 in your command line and paste the output of that here?
Also what is the topic name of the device you are trying to control ?

Also what are you trying to have the slave device do?
Because the power command 2 at the end is toggle
If you want on or off you use another power command.

Rules for remote buttons to control other MQTT entities/devices.
A little bit of explaining what each command is and what control relays.

Power Control the corresponding power state (1…8) (also restarts PulseTime)
0 / off / false = turn OFF
1 / on / true = turn ON
2 / toggle = if power state is ON switch to OFF and vice versa
3 / blink = toggle power for BlinkCount times each BlinkTime duration (at the end of blink, power state is returned to pre-blink state)
4 / blinkoff = stop blink sequence and return power state to pre-blink state

Thanks, Rod!

when I type “rule1” I get:

MQT: sonoff/SF_GarageDoorSwitch/RESULT = {"Rule1":{"State":"ON","Once":"OFF","StopOnError":"OFF","Length":58,"Free":453,"Rules":"ON button1#state=3 DO publish cmnd/SF_Garage/POWER 2 ENDON"}}` 

I am trying to control with a single click SF_Garage and with a double click “SF_Gate”

My slave devices are connected to other Sonoffs which send an on-command during a second, so they close the relay during one second and open/close a garage door or a gate.