Except I would want the last condition to be ignored if the lightgroup went from ‘on’ to ‘off’ and not only if it’s just currently ‘off’.
So the conditions that I need are (needs all to be true):
haspsensor is on
lightgroup is off
sun’s elevation is less than or equal to elevationday
sun’s elevation is more than or equal to elevationnight, unless the light group was on before it switched to off (ie, we went in because of that trigger, not the sun).
Can I check for a state transition in the condition section?
Probably the easiest option is to add a trigger ID and then use that as an OR clause in the final template condition:
trigger:
- platform: state
entity_id: sun.sun
attribute: elevation
- id: lightgroup
platform: state
entity_id: !input lightgroup #make sure to change this if you are actually creating an automation, not a blueprint.
from: 'on'
to: 'off'
condition:
- condition: template
value_template: "{{ is_state(haspsensor, 'ON') }}"
- condition: state
entity_id: !input lightgroup #make sure to change this if you are actually creating an automation, not a blueprint.
state: 'off'
- condition: template
value_template: "{{ state_attr('sun.sun', 'elevation') | round(default=90) <= elevationday }}"
- condition: template
value_template: |
{{ state_attr('sun.sun', 'elevation') | round(default=-90) >= elevationnight
or trigger.id == 'lightgroup' }}
Also know that all those conditions must be true for the automation to run actions.
(perhaps you want to look at choose to change some of the conditions to apply some of the time?)
Perhaps post the whole automation instead of random pieces would help.
In case someone stumbles here looking for answer, I had to correct the code a bit. I had to define:
lightgroup: !input lightgroup
in the variables: section, replaced trigger.id for trigger.entity_id and replaced 'lightgroup' for just lightgroup (the variable I defined above). So that line now looks like this: