I am new to Home Assistant automation and I just cannot figure out what is wrong with my automation to turn lights on/off based on sunset/sunrise. It never triggers.
I have tried to use elevation as well but that didn’t work either. I have searched the net for a solution but everything I found gives examples for how sunrise/sunset used to work.
I have already checked that Time and Zone are set correctly.
Please give me some pointers on what I’m doing wrong.
Thanks in advance.
First things first, confirm the automation is not disabled.
If it never triggers then there will be no traces recorded. Can you confirm that there are, in fact, no traces recorded around the times of sunrise and sunset?
I have a similar setup but have made two automations, one for sunrise and one for sunset.
not sure about the offset you use tho, -15:00, is this 15 minutes or hours.
I use -00:15:00
I have another automation that uses the sunrise/sunset that also doesn’t work.
It takes a notification from a Reolink doorbell that a person is detected, or a push button action(used it for testing, rather than manually triggering the Reolink), then it checks if is during the night and if it is, it will turn on the front door lights.
The automation right now triggers regardless of the night/day. I had the same time format error -15:00, I corrected it to -00:15:00 but still turns on the lights even thought is already 9:30 in the morning.
Here is the automation:
alias: Turn on Yolink Entry Light after Person detected and at night -40%
description: Turn on Yolink Entry Light after Person detected and at night-40%
trigger:
- type: turned_on
platform: device
device_id: eb080ea803e08xxxx
entity_id: 27174b2e4463d7xxxxxx
domain: binary_sensor
for:
hours: 0
minutes: 0
seconds: 0
- platform: state
entity_id:
- input_button.person_detected
to: null
condition:
- condition: sun
after: sunset
after_offset: "-00:15:00"
before: sunrise
before_offset: "00:15:00"
action:
- if:
- condition: state
entity_id: input_boolean.visitor_present
state: "off"
then:
- type: turn_on
device_id: e4bc4f238923xxxx
entity_id: af3109b53e2xxxx
domain: light
brightness_pct: 40
- delay:
hours: 0
minutes: 1
seconds: 0
milliseconds: 0
- type: turn_off
device_id: e4bc4f238923xxxx
entity_id: af3109b53e2xxxx
domain: light
enabled: false
- if:
- condition: state
entity_id: input_boolean.visitor_present
state: "off"
then:
- type: turn_off
device_id: e4bc4f238923xxxxx
entity_id: af3109b53e2xxxxx
domain: light
mode: single
Why it failed for you is unclear (and I don’t have the time to discover the reason).
The suggestion to change -4 to -4.0 is moot; they’re the same value and not handled differently.
I tested this moments ago:
platform: sun
event: sunset
offset: "-05:11"
Sunset in my area is in 5 hours and 11 minutes and the automation triggered successfully.
Therefore -15:00 is understood as 15 hours before sunset. Owing to the way sunset is computed, 15 hours prior to the moment when it’s computed produces a time that has already passed. Therefore the automation is never triggered.
FWIW, this also triggers 5 hours and 11 minutes before sunset. However, the Automation Editor doesn’t display it properly in visual mode.
platform: sun
event: sunset
offset:
hours: -5
minutes: -11