I have a simple automation that turns on the back lights on the tv when the tv is turned on after sunset (see below). the issue i am having is that if you turn on the TV before sunset, then the back lights don’t come one. i am pretty sure i can manage this with another automation that turns them on after the sun sets if the TV is on, but was wondering if there is a way to manage it within a single automation?
alias: ROOM - Living Room - TV back lights sync with TV power
description: ''
trigger:
- platform: state
entity_id:
- media_player.big_tv
condition:
- condition: state
entity_id: sun.sun
state: below_horizon
action:
- service: light.turn_{{trigger.to_state.state}}
data: {}
target:
entity_id: light.big_tv_lights
mode: single
I don’t really see a good way of doing it since you want two different events really. the first is anytime someone turns it on when the sun is down, you turn on the lights. The second is if it’s on already (could have been all day) and the sun sets then you want that to turn on.
I would just make a second automation with a trigger of sunset and condition of it being on.
You can add a sunset trigger. And also add a condition that the TV is on. So it would always try to trigger when the TV is on and at sunset, but it would have to meet both conditions that the sun is below the horizon and the TV is on. Make sense?
… Although it looks like you are trying to also turn the lights OFF when the TV turns off. I would create a separate automation for that piece. And you’re going to have to get rid of your {{trigger.to_state.state}} if you’re adding a sunset trigger.
Although I am sure there are more elegant ways of doing it, you could for example set the automation as follows:
Trigger 1 = Media player goes from off to on
Trigger 2 = Media player goes from on to off
Trigger 3 = Sun below horizon
Then in action use choose function:
Choice 1 = Trigger 1 - condition sun below - turn on lights
Choice 2 = Trigger 2 - turn off lights (you could add a condition of them being on but probably pointless)
Choice 3 = Trigger 3 - condition media player = on - turn on lights
As I am on a mobile device I have not attempted yaml but hopefully you get the idea.