Hey Everyone,
I’m having issues with the fallow Automation. It will work if I tell it to run between specific times but as night comes at different times id like the automation to auto adjust during the year but when i put in the sunset and sunrise options it just stops working all together.
- alias: Bedroom Nightlight ON
trigger:
platform: state
entity_id: binary_sensor.bedroom_motion_
from: 'off'
to: 'on'
condition:
condition: and
conditions:
- condition: sun
after: sunset
- condition: sun
before: sunrise
- condition: state
entity_id: device_tracker.owntracks_iphone
state: home
action:
- service: homeassistant.turn_on
entity_id: light.bedside_left
You have to OR the conditions. Here’s a complete working example from my personal setup.
- alias: 'arrival: turn on aloha lights and greatroom when needed'
trigger:
platform: state
entity_id: group.aloha_mode
from: 'off'
to: 'on' # any member is on
condition:
condition: or
conditions:
- condition: sun
after: sunset
after_offset: "-00:15:00" # near or after sunset
- condition: sun
before: sunrise
action:
- service: light.turn_on
data:
entity_id: group.alohalights
brightness: 127
- service: light.turn_on
data:
entity_id: light.greatroom_lights_level
brightness: 25
It see that it’s documented that way, but it didn’t seem to work that way. I had a single incident around 1:30 AM when this automation should have triggered but did not. It’s possible that there was some other reason why it didn’t trigger, and I haven’t had an opportunity to re-test after making the condition change. I should probably do some non-disruptive automatic testing to see if the added condition does anything in practice, despite what the documentation says.
Yes, the “after sunset” and “before sunrise” conditions will work as expected only before midnight. Because the sunset will change to the new day’s sunset after midnight so that, even before sunrise, you’re also before sunset (of the next day)…
I ended using the sun elevation, which is nicer because it’s not only the time sun sets or rises, but also the light there is in the house that you can use as a condition.
FYI, according to a project contributor commenting in github’s issue tracker, post-sunset and pre-sunrise are not the same. I’ll submit a documentation change.