Bug: Sun integration and sleeping computer

Hello to all,

At first, i am not sure if this is the correct category to post this but if it’s not, i would please a moderator to move it.

I think i have identified a bug with the sun integration. I have home assistant on a virtual machine (virtualbox) and i have an automation that turns on my aquarium lights 30 minutes before sunset.

Lately, i decided to be putting the computer that the virtual machine is on to sleep and if required i can wake it up on LAN.

So, today, i put the computer to sleep for one hour. I woke it up far before the aquarium automation would start and i was expecting the lights to turn on 30 min before sunset… they didn’t. They turned on one hour after they should.

This means, that for as long as the computer sleeps, the automation delays. I thought that the sun integration either checks regularly the position of the sun or it sets it up on startup but its not time related.

Automations that are based on time they dont have any problem. Only the ones thwt use the Sun integration.

Is there any solution / workaround?


Home Assistant is designed to operate on a machine that runs continuously, not a machine that only operates periodically.

Feel free to report the problem as a bug but you’re likely to be told the same thing.

I definately understand this position and i may even agree. I started putting the computer to sleep in order to save energy.

I dont really believe that its gonna be so difficult to make the integration to periodically check the sun’s position.

If there is no other workaround i either need to restart HA after waking up the computer or use time triggers instead of Sun

You should know that if you want an integration (like the Sun integration) to behave differently from the way it does now, that’s considered to be a Feature Request (not a bug).

Feature Requests for Home Assistant Core are submitted to this forum and not to Home Assistant’s Core repository on GitHub.

According to the documentation, the Sun Integration uses the location to track if the sun is above or below the horizon: Sun - Home Assistant

There is no mention on the frequency that is checking. Therefore, people like me can assume that it checks periodically which seems not to be the case. Also the computer does not change location so there is nothing to indicate that the integration behaves as it should (therefore a bug).

But ok, lets not fight if it is a bug or a feature request, i can accept it as a feature request and i please a moderator to move the post.

Is anyone aware if there is any weather service that exposes sun position to HA so it can be used instead?

Thank you!

The issue here is that you use virtualbox.
Virtualbox is virtualizing hardware for the VM and that includes the hardware clock.

On bare metal the clock would be adjusted by the hardware clock. This would normally also happen on a VM if there are a virtualization utility set installed, but HA installed a QEMU utility set and not a virtualbox one.
This means the VM on virtualbox does actually not know that it has been in a sleep state for some time.

It’s my understanding that the Sun integration does periodically compute new values for sun.sun (its state value and attributes). The frequency varies and is more frequent around sunrise and sunset.

If your automation is designed to trigger a half-hour before sunset, when do you wake up the computer and start Home Assistant? Have you checked the reported system time in Home Assistant after it has been restarted? Is it correct?

I put the computer to sleep when we leave for work (around 7:30) in the morning and i wake it up about 12:00 far before 16:32 that the automstion should kick in.

I haven’t checked the system time because automations that have time triggers work normally so i thought that the time is syncronizing.

I will pay attention to it a bit more as it can be that there maybe something wrong with the offset. For example, i will move the automation to turn the lights on exactly at sunset (when the entity change from above horizon to below horizon).

Will report back!

Thank you for your answer!!!

The sun integration has the following sensors.


Does this mean that if i pause the VM (from VirtualBox) it would work?

No, the pause is what happens when your computer goes to sleep.

You need a hypervisor that is supported by HA if you want to set your computer to sleep and that means QEMU or a variant.
Not sure if QEMU is available on Windows though.