I have an automation setup that turns the lights on when I arrive home and its 1hr:15 after sunset. I find its still bright enough not to need lights until this point hence the delay i put in rather than just after sunset.
This automation works just fine so no issue there. The problem I am having, while I haven’t totally narrowed it down but I think after midnight this stops working. A couple of days this week I have arrived home after midnight and my lights wouldnt turn on. I haven’t pinpointed the exact time this stops working but I’ve been arriving home after midnight.
Anyone got a better way of achieving this? Ive seen some people use it based on the suns elevation, I would be open to using that if it works well? Or any other ideas?
Here is my automation
alias: Turn on Light
initial_state: True
hide_entity: False
trigger:
platform: state
entity_id: device_tracker.phones_rosss_iphone
from: 'not_home'
to: 'home'
condition:
condition: and
conditions:
- condition: sun
after: sunset
after_offset: "-1:15:00"
- condition: state
entity_id: input_boolean.light_tracking
state: 'on'
action:
- service: scene.turn_on
entity_id: scene.full
- service: notify.pushover
data:
title: ""
message: "Welcome Home! Lights ON!"
Home Assistant has a “break” at midnight. So “after sunset” only works until midnight. So “after sunset” resets at midnight. So you might need some “before sunrise” conditions “or-ed” in there.
Once it is midnight, it’s no longer some time after sunset, but some time before sunrise. In other words: you will have to include an OR condition so your automation can run if it’s after sunset, or if it’s before sunrise.
An automation like this turns on the lights if you arrive home after the set time, but does it also work if you are already home and the activation time is reached or do one need a separate automation for that?
I have a separate automation for that which gives me more control -
automation:
trigger:
platform: sun
event: sunset
offset: "-01:15:00"
condition:
condition: and
conditions:
- condition: state
entity_id: device_tracker.phones_rosss_iphone
state: home
- condition: state
entity_id: input_boolean.sunset_light
state: 'on'
action:
service: scene.turn_on
entity_id: scene.full
This turns on a scene for my lights so long as its 1hr15 after sunset. I also have a switch (inputboolean) on my front page so that I can turn the automation off from the front page if I want, so the automation also check if this switch is on, if its not it won’t run.
Ok I have adjusted my automation, hopefully this works. I used the conditions samples page on the website and you can mix and/ors together like this apparently.
Im out past midnight again tonight so will see if this works!
alias: Turn on Light
initial_state: True
hide_entity: False
trigger:
platform: state
entity_id: device_tracker.phones_rosss_iphone
from: 'not_home'
to: 'home'
condition:
condition: and
conditions:
- condition: sun
after: sunset
after_offset: "-1:15:00"
- condition: state
entity_id: input_boolean.light_tracking
state: 'on'
- condition: or
conditions:
- condition: sun
before: sunrise
action:
- service: scene.turn_on
entity_id: scene.full
- service: notify.pushover
data:
title: ""
message: "Welcome Home! Lights ON!"
Interesting, can you explain why that didn’t work? I can confirm my lights didn’t come on.
I just tried your code and then published via MQTT to make home assistant think I wasn’t home rather than wait till another day, then used own tracks to publish that I was home and my lights came on. Can you explain why yours worked and mine didn’t? It looks to me like all you did was move the sunset to the “or” condition rather than the “and”
Your or condition only has 1 subcondition, the before sunrise one. And your sunset condition was still a subcondition of your and condition, so it was still a condition that had to be met.
In other words, in your automation the conditions are:
it has to be after sunset
and
input_boolean.light_tracking has to be on
and
it has to be before sunrise OR …
The way I wrote your automation, the conditions are:
input_boolean.light_tracking has to be on
and
it has to be after sunset OR before sunrise
It hope this clarifies things a bit for you. If not, let me know