I have a sonoff rf bridge flashed with tasmota. The wireless button is mapped to button 1 of the rf bridge.
I have a bunch of LED light strips set under a group called leds.group. These strips are turned on/off and colours changed by a variety of broadlink sensors.
Currently, I can successfully turn the LED strips on/off and change colours via software buttons on relevant the home assistant screen.
I now want this physical button press to also be able to turn all of the LEDs in the group on/off.
This is my automations - I can get everything to turn on fine, however the turn off command does not do anything. Have I missed something obvious from the homeassistant.turn_off part?
automation:
### TURN OFF SINGLE SENSOR BUTTON (SINGLE STATE SENSOR) AFTER 10 SECS OF TURNING ON
- alias: turn button off
initial_state: 'on'
trigger:
- platform: state
entity_id: binary_sensor.led_button
from: 'off'
to: 'on'
for:
seconds: 10
action:
- service: mqtt.publish
data:
topic: "tele/RF_Bridge/RESULT"
payload: "013A18off"
- alias: LEDs On
initial_state: 'on'
trigger:
- platform: state
entity_id: binary_sensor.led_button
to: 'on'
condition:
- condition: state
entity_id: group.leds
state: 'off'
action:
service: homeassistant.turn_on
data:
entity_id: group.leds
- alias: LEDs Off
initial_state: 'off'
trigger:
- platform: state
entity_id: binary_sensor.led_button
to: 'on'
condition:
- condition: state
entity_id: group.leds
state: 'on'
action:
service: homeassistant.turn_off
data:
entity_id: group.leds
The desired behaviour is:
If LEDS are currently off, then press the button to turn them on. (this currently works).
If LEDs are currently on, then press the button to turn them off. (this currently does not work).
Itâs my first go at automations and I thought that I needed to have a condition monitoring the state of the LEDs group, a simpler solution is much better!
Marc noted that you had the initial_state: for the automation set to âoffâ.
But looking at it now it seems to be set to âonâ.(but I canât see an edit )
Just as an aside, this will work, BUT generally leaving out the âinitial_state:â completly is better.
âSome Peopleâ switch automations on and off but this is generally just lazy writting and you should deal with automations with an appropriate condition (or conditions).
The reason why initial_state: âonâ is a bad idea is that on a re-start, you loose all previous attributes; generally the most important of which is âlast_triggeredâ you may not use this now or for this particular automation ever, but the point is itâs really bad practice as knowing when a particular automation last ran, is really important. And not having the attribute (ie none) means it will fail the simple time evaluations.
Also if you are happy with your new automation you should mark @anon43302295 's post as the solution.
This helps others searching the forum
I have replaced the wireless button with an unused relay on a sonoff t3.
When I turn on the sonoff button the LEDs switch on as desired.
However I am finding that when I turn off the button the LEDs donât turn off. I then press it again and they turn off, but this changes the LEDs state to on in HA so i then have to switch the button off again to get the LEDs state correct. So it takes 3 presses to go off. Also often the state in HA and the button state go out of sync due to these multiple presses so then the sonoff button is on and the LEDs off or vice versa.
Has anyone experienced anything similar and if so then what was your solution?
Iâm battling with the same issue, please could you share your working config.
Edit: not to worry thanks, got it working, updated my rule on the Sonoff-Bridge to publish an OFF to the topic after 1sec, now the automation just toggles on the ON topic.