I am trying to automate some lights to turn on and off when we aren’t home. I want to run some scripts every 30 minutes from sunset until 2230. The set up currently have seems to run on every hour/half hour after sunset (not from sunset). I think I have the condition and trigger around the wrong way but note sure how to keep it reoccurring. Any suggestions?
#Away light toggle
- alias: 'Away light toggle'
initial_state: 'on'
trigger:
platform: time
minutes: '/30'
seconds: 00
condition:
condition: and
conditions:
- condition: state
entity_id: 'group.family_group'
state: 'not_home'
- condition: and
conditions:
- condition: sun
after: sunset
after_offset: "-00:30:00"
- condition: time
before: '22:30:00'
action:
Your trigger seems right. Your coinditions are double nested with and, any reason for this? Try…
condition:
condition: and
conditions:
- condition: state
entity_id: 'group.family_group'
state: 'not_home'
- condition: sun
after: sunset
after_offset: "-00:30:00"
- condition: time
before: '22:30:00'
Having the after offset means that it will wait until 30 minutes after sunset before it allows the trigger to fire. Seems like it is going to wait until either the X:30 or X:00 mark after sunset before you would see the first automation run.
Thanks, no particular reason the conditions are like that, was just what I came up with from reading the docs. I’ll amend them.
My trigger seems to set the action off at 17:00, rather than at 16:42 (30 mins before the sunsets at 17:12 for example). I not sure have it trigger at sunset and then repeat every 30 mins
On second read, that seems correct. Your offset is a negative so it will go back in time. So 30 min before sunset would be the first time it could fully execute. It will only trigger at x:00 and x:30 increments though as that is the trigger.
So if at 7:30 pm it is not 30 min before sunset it won’t execute the automation. The next time it will attempt to run will be 8:00 pm. Then 8:30 …etc. Your trigger has to fire, and then each condition has to be met. If any condition isn’t met then it won’t try those conditions again until the next trigger fires. Hope that makes sense.
There was nothing technically wrong with your conditions, just a bit redundant.