I am trying to get my bedroom tv to turn off automatically when my chromecast turns off. Unfortunately my older tv will turn on via CEC, not not off. Anyway, I have successfully done this with my Broadlink and automations:
- alias: Master Bed Cast Ended
trigger:
- platform: state
entity_id: media_player.bedroom_tv
to: "off"
condition: []
action:
- service: script.turn_on
entity_id: script.master_tv_power
My problem now is that sometimes at night the chromecast will drop off the wifi, or do an update, or something else that makes home assistant read it as ‘unavailable’. When it comes back, the state returns to ‘off’, and the automation is triggered. Again, unfortunately, this tv only has a power toggle command, not discreet commands like I use on my main setup. The problem is a wake up in the middle of the night with my tv on and bright in my face.
What I think I need is a template sensor that reflects the state of the chromecast as it was a few seconds ago, so that my automation can add a condition, something like:
condition:
- condition: state
entity_id: sensor.bedroom_tv_recently
state_not: 'unavailable'
This way, if the chromecast changes from ‘playing’ to ‘off’, or anything else to ‘off’, the action will run. But if it just changed from ‘unavailable’ to ‘off’, the condition will not be met and the action will be skipped. I think this is the best way to accomplish this, if it’s possible. The only other idea I had was on the trigger, maybe there’s some kind of ‘from_not’ tag i could add? I use ‘to’ and ‘from’ based on the current needs, but I am not aware of ways to use more than 1 or if there is a ‘not’ function for those.
Any ideas on other solutions are welcome as well, thank you!