I’m starting to automate some of my lighting.
I often come across situations where I need two conditions to be true to trigger an automation action, e.g.
“switch on light X WHEN the sun sets AND the tv is on”.
The goal is to have the light turn on when I’m watching tv and the sun sets and also if it’s already dark and I turn on the tv.
So in these cases I always end up with two automation scrips for basically the same thing, one being
trigger: sunset, condition: tv is on
and the other one being
trigger: tv turns on, condition: after sunset
Is there a more elegant way to handle these kinds of cases?
I could imagine putting both conditions into the condition: section of an automation script, but how to trigger it then?
There’s probably a way to fire a trigger event every minute, but that does not sound very efficient to me…
Ok, to be more specific, this is how I’m doing it currently.
I’m using the state of my Kodi box here instead of the state of the TV.
First automation:
alias: 'Lights On: It is dark + Kodi turns on'
trigger:
platform: state
entity_id: media_player.kodi_wetek
from: 'off'
condition:
- condition: and
conditions:
- condition: state
entity_id: light.desklamp
state: 'off'
- condition: state
entity_id: sun.sun
state: 'below_horizon'
action:
service: scene.turn_on
entity_id: scene.wz_watching_movie
Second automation:
alias: 'Lights On: Movie + Sun sets'
trigger:
platform: sun
event: sunset
offset: '+00:05:00'
condition:
- condition: and
conditions:
- condition: state
entity_id: light.desklamp
state: 'off'
- condition: state
entity_id: light.floorlamp
state: 'off'
- condition: or
conditions:
- condition: state
entity_id: media_player.kodi_wetek
state: 'playing'
- condition: state
entity_id: media_player.kodi_wetek
state: 'idle'
- condition: state
entity_id: media_player.kodi_wetek
state: 'paused'
action:
service: scene.turn_on
entity_id: scene.wz_watching_movie
I find it a bit cumbersome that I have to always script two automations for basically the same thing with the trigger<->condition swapped.
I was hoping that there was a more elegant way of expressing these cases.