Clicking the Execute button in the Automations YAML editor successfully turns off the 5 entities (and vice versa. I have another identical automation script except it says on)
My issue is that physically pressing the IKEA on/off switch in the kitchen does not turn on/off the related entities. It only turns off the IKEA bulbs and ignores the plug and Sonoff.
Being a noob, I’ve searched and tried different syntax but to no avail. Any piece of advice will be greatly appreciated.
Issue could be you are not mentioning the state change in these automations. You already said you have two identical automations. Both these have no trigger state change mentioned so they both might be executed simultaneously. Try with state changes like this
This single automation turns the lights and switches on or off depending on the sensor’s state.
alias: Kitchen - Master Switch On or Off
description: ''
trigger:
- platform: state
entity_id: sensor.tradfri_on_off_switch
condition: []
action:
- service: 'homeassistant.turn_{{ trigger.to_state.state }}'
entity_id:
- light.kitchen_led_plug
- light.tradfri_bulb_4
- light.tradfri_bulb_5
- switch.sonoff_100033c557
- switch.sonoff_100033c860
NOTE:
This automation will work only if the sensor reports its states as on or off. If it doesn’t then the automation will not work correctly.
You mentioned that you observed different behavior when you executed the automation manually compared to when the automation was triggered by the sensor. In the first case, all 5 entities were turned off, in the second case only the lights were turned off and not the two Sonoff switches.
Manually executing the automation skips its trigger and simply executes its action. That means the action does work but there is something strange happening with the trigger because when the sensor changes state only the lights are controlled (not the switches).
Yes, as a matter of fact, both automation scripts did have the right state specified but did not work. As I have mentioned previously, the issue is that it works on WebUI - no problem when Execute button is pressed. Only when I press the physical switch, it ignores some of the entities, namely the none-Ikea entities.
Minimally, you need to execute Configuration > Server Controls > Reload Automations. However, as mentioned, it won’t work if the sensor doesn’t report its states as on or off.
Go to Developer Tools > States, find the sensor, and look at what it reports as its state. Is it either on or off?
That’s important information. Clearly the sensor’s state is neither on or off (so the automation I posted will not work). In fact, this appears to report the sensor’s battery level and is not an appropriate sensor to trigger your automation.
Effectively, your original two automations will only trigger when the sensor’s battery level changes.
Earlier you wrote (but then removed) that the device is still linked to the three IKEA lights. That’s why it continues to control the lights but not the Sonoff switches (because the automation isn’t automatically triggering at all).
Gotcha. The WebUI will literally run the script from the top ignoring any defects, so long as there is no syntax error, hence why. Let me try this with a Xiaomi switch!
Manually executing an automation ignores the trigger and the condition (if it exists). In this case, the trigger is based on battery level so it will only trigger when the sensor’s battery level changes and not when you operate the remote-control. Basically, you’ve chosen the wrong entity to trigger your two automations.
Go to Configuration > Devices and find the device you are using to control the lights (and let us know what it is). It will list all the entities that represent this device. One of those entities will be the battery level sensor but you want an entity that reports the device’s state.
Having this issue as well. My automation used to work flawlessly but has slowly been breaking down. Worked perfectly a few months ago, then last week it was intermittent at best, and now it only works from my Lovelace on/off switch while neither actual wall switch triggers no automation at all.
My Lovelace switch was just the Master Bedroom Lights, but because of the automation it would always trigger the hall light, too. It still does, but now it’s the switches on the wall that don’t trigger the opposite switch at all.