I’m trying to make a simple automation to turn on the lamp at the sunset and turn it off at 23:00 sharp.
- id: '1606033784527'
alias: Turn on
description: ''
trigger:
- platform: sun
event: sunset
condition: []
action:
- service: switch.turn_on
data: {}
entity_id: switch.outside_switch
mode: single
- id: '1606063728545'
alias: Turn off
description: ''
trigger:
- platform: time
at: '23:00'
condition: []
action:
- service: switch.turn_off
data: {}
entity_id: switch.outside_switch
mode: single
It works, but only “kinda”. Turning on is delayed for seemingly random amount of time between 1 and 2 hours after sunset and tuning off is delayed by up to 1 hour.
See the example from logbook. The other day, triggering times were:
16:08:11 - sunset
17:53:16 - automation triggered
16:08:46 - sunset
17:28:19 - automation triggered
Similar for 23h hour triggering which was delayed by 25 minutes.
Where about are you? In terms of latitude/longitude? Did you set this value in home assistant?
Is your timezone correct?
The logbook doesn’t necessarily say ‘sunset’. It says “sun” : “set”. There is a possibility it just means the sun is no longer rising.
sunset happens when both the sun is not rising and the sun crosses some elevation. Elevation will be the same value for sunrise and sunset…the only difference being ‘rising’ is true/false.
Google “what time is sunset for my area”. This is the time the automation will likely fire. It should be pretty close to the actual fire time.
Wherever I am, it does not justify the difference in triggering of almost 25 minutes between two consecutive days (17.28 and 17.53). Also, it does not justify the fixed time delay when it was supposed to trigger exactly at 23h.
Anyways, latitude, longitude and timezone are correctly set within home assistant and the syst clock is synchronized by NTP. Sunset value reported by logbook is also correct.
You are right. It should only be a few mins difference. Sunset platform wont work well near the north and south pole…but given the sunset time, I don’t think you’re there lol.
Check the logs. There is something going on here…is your CPU overloaded? Can you ssh into the system and do a " top " command or something? With this large of a delay, it should be very obvious that something is making the system run slow.
That’s all I can think of that would cause the time trigger to be so delayed.
Also, while you’re SSHd into the system, run the ‘date’ command and just verify the system clock matched your timezone. If it doesn’t make sure NTP is running and the timezone is set correctly in the system.
Nope, I’m at 45deg latitude, so sunset is normal. Date command returns accurate time, as well as timedatectl, which also reports:
System clock synchronized: yes
NTP service: active
top reports top process appdaemon to use around 10% CPU constantly (interesting find why is this constant, but it is low enough that I find it irrelevant for this matter) and the 15 min load average is around 0.2 (single CPU core assigned to a VM)
Anything that I can think of is that Virtualbox that runs the VM does not emulate hardware clock really well, but I don’t know how to check it.
Didn’t find the root cause unfortunately. I have reinstalled Virtualbox and switched from Supervised install to HA OS. It has been working fine ever since.