Nope, even the documentation says so. Here’s the example it gives to solve the issue:
condition:
condition: or # 'when dark' condition: either after sunset or before sunrise - equivalent to a state condition on `sun.sun` of `below_horizon`
conditions:
- condition: sun
after: sunset
- condition: sun
before: sunrise
So, on any given day, can it be both after 20:00 and before 05:00? Rhetorical question - of course it can’t. I am almost 100% certain that I have read somewhere that is how it works.
I understand your logic (if it is after 20:00 then it is before 05:00 the next day), but I am fairly certain that in this case it is per day, so it can’t be both.
Yeah, it’s probably fine. You just can’t use the automation editor for that automation anymore because it doesn’t support nested conditions. Or is a nested condition. And is only supported because the default non-nested conditions mean ‘and’.
The condition also checks if the light is currently off (to avoid needlessly turning it on).
- id: '1562767530621'
alias: 'Living room - TV source dim Lights'
trigger:
platform: template
value_template: >
{% set src = state_attr('media_player.living_room_tv', 'source') %}
{{ src in ['Netflix','PS4','Plex'] }}
condition:
- condition: state
entity_id: sun.sun
state: 'below_horizon'
- condition: state
entity_id: light.wall_lights
state: 'off'
action:
service: light.turn_on
data:
entity_id: light.wall_lights
brightness: 75
transition: 3
It should work with the Automation Editor (because the conditions use a logical and).
EDIT
Replaced: {{ src == 'Netflix' or src == 'PS4' or src == 'Plex' }}
with: {{ src in ['Netflix','PS4','Plex'] }}
as per Marius’ suggestion (see below).
sure, but didn’t want to diverge to much from the original suggestion
it’s a bit of give and take with these conditions for my taste. I like it short and simple, but also like to make it easily maintainable and re-usable using logical ordering.
In this particular case, I would have kept them separated.
Please describe the precise steps you performed to test the automation.
The automation is triggered whenever the media_player’s source attribute changes state and only if it changes to Netflix, PS4, or Plex (the names have to match exactly as shown).
you might have to change to trigger state, and use the sources as condition. I fear the template trigger is always true when changing sources, so doesnt change and hence doesnt trigger the automation.
changing to state should take care of that, and the condition will make sure it only changes when the sources are met.
- id: '1562767530621'
alias: Living room - TV source dim Lights
trigger:
platform: state
entity_id: media_player.living_room_tv
condition:
- condition: template
value_template: >
{% set src = state_attr('media_player.living_room_tv', 'source') %}
{{ src in ['Netflix','PS4','Plex'] }}
- condition: template
value_template: >
{{is_state('sun.sun','below_horizon')}}
- condition: template
value_template: >
{{is_state('light.wall_lights','off')}}
action:
service: light.turn_on
data:
entity_id: light.wall_lights
brightness: 75
transition: 3
In theory, Home Assistant will create a listener for media_player.living_room_tv and monitor its source attribute for state-changes. Switching from Netflix to Plex is a state-change.
I believe you have media_players (I don’t), can you test the template trigger with your system to confirm it works (or does not work)?