Hi
I have some code that has served me well for many years, but it has creating an error when the some cases.
It’s a simple two-automation function.
One automation that turns off the light when the TV is turned on, and stores in a boolean if the light was on or off.
The other is turning on the light again when the TV is turned of,f based on the boolean value that was stored.
It has one problem, though: if the light was unavailable when the boolean was stored, this code will not work since the complete string will be: light.turn_unavailible light.light_1
- alias: Turn off lights for TV session
triggers:
- trigger: state
entity_id: media_player.lg_webos_tv
to: 'on'
actions:
- action: input_boolean.turn_{{ states('light.light_1') }}
entity_id: input_boolean.light_memory
- action: light.turn_off
target:
entity_id: light.light_1
- alias: Turn on light after TV session
triggers:
- trigger: state
entity_id: media_player.lg_webos_tv
to: 'off'
actions:
- action: light.turn_{{ states('input_boolean.light_memory') }}
target:
entity_id: light.light_1
I have been using this same routine for a while too and it works fine except for one thing. My lighting is Philips Hue and over the course of the day various lighting scenes are triggered based on time of day. These triggers are resident on the Philips Hue hub but accessible in Home Assistant.
My issue is this: the HA automation turns off one particular entity (light) when the TV turns on but this entity turns back on when a new scene is triggered from Philips Hue. In other words, how do I prevent this one light from turning on but allowing the rest of the scene to run its course when the TV is on? Should I hand over the scene changes to HA to make this more viable or is there a script to persistently keep this one entity off when the TV is on regardless of scene changes from Philips Hue?
Thanks for any advise to steer me in the right direction.
Scenes in HA (and I’m assuming also in Hue) don’t check conditions.
You will need to create another scene in Hue with the light excluded. Set up an Automation in HA which checks if the TV is on or off, then trigger the appropriate scene based on that.