after a power outage, automation turn on/off light wrong time. please help me, thanks.
If Home Assistant is off during a power outage at either 23:00
or 17:30
, it wont be able to trigger at the specified times. When starts later, it will have missed the trigger time and so will not set the switch to the correct state.
The automation needs to be redesigned to handle a third trigger that occurs when Home Assistant starts. Add the following trigger to your automation:
- platform: homeassistant
event: start
Change the template to this:
service: "switch.turn_{{ 'on' if 17 <= now().hour < 23 else 'off' }}"
That ensures the switch is set to the correct state whenever Home Assistant starts.
NOTE:
The template I have suggested will work accurately for 99% of all cases. However, if Home Assistant starts between 17:00
and 17:30
, the template will turn on the switch. Thatâs because the template only concerns itself with checking the current hour, not minutes. Thatâs not a problem when the automation normally triggers at 17:30
. It will only occur if Home Assistant restarts during that half-hour âwindowâ between 17:00
and 17:30
.
If thatâs unacceptable to you, I can show you how to enhance the template so that it also considers minutes. However, in my opinion, the extra complexity isnât worth it and the suggested template is neat, simple, and will handle 99% of restarts accurately.
If you want to learn more about this technique, you may wish to read the following post:
thanks, my HA has a power outage at 21h and has power at 22h, but the automation turns off the lights at 0:17, and sunset turns on the lights at 0:46.
I assume you mean you have another automation doing that? It will also have to be modified to support a trigger on startup.
I have no another automation. I have 2 lights, the garden light uses time to on/off, and the gate light uses sunset to turn on, but they often work wrong after a power outage. example, HA starts at 22h, but at 0:17, the garden lights will turn off and turn on at 18hâŚ, and the gate lights will turn on at 0:46.
If they are not controlled by Home Assistant then I canât help you with that.
Is what I posted above useful for you to correct the behavior of the garden lights automation?
I donât understand why you believe timezone is related to the problem you described in the first post. Does the garden lights automation normally turn the switch on at 17:30
and off at 23:00
local time? If it does then thereâs nothing wrong with how Home Assistantâs time is configured.
it works normally with local time if there is no power outage (on at 17:30 and off at 23:00) . and after a power outage, it takes about 1 to 2 days for the system to work correctly. I donât understand why itâs like that
You said:
When this happened, did Home Assistant turn off the garden light at 23:00
?
when this happened, the garden light was turned off and i turned it on manually, but after about 0H:xx the garden light went off by automation, not at 23:00. about 1 2 days later, the garden light turn off at 23:00
i checked again, error: automation not updating time. example, power outage at 9:00 and come back at 10:00. At that time, the internet was not available, so HA could not update the time, but still used the time of 9:00 for automation. when the internet is connected, HA updates time is 10:03, and automation is still 9:03. error, automation doesnât sync time with HA
My guess is that the computer you are using to host Home Assistant doesnât have a Real Time Clock (RTC) so on startup it must use an Internet-based time source as a reference. If access to the Internet is unavailable on startup, it canât synchronize itself with the time source and so its clock is off.
Given that you live where there are frequent interruptions to power and Internet access, itâs advisable to use a UPS (Uninterruptible Power Supply) as well as a computer with an RTC. If thatâs not possible then I canât see how you can run Home Assistant reliably.
but when the internet is connected, HA updates the time, and automation doesnât update the time, do you know why?
Thatâs not how automations work. The âautomation timeâ is hard coded by you in the trigger, there is nothing to update.
Hi,
HA 2023.10.0 .
Container version, running over a box tv with armbian/debian linux.
I got into a similar situation yesterday here.
My automation to run at sunset, ran twice and completely at the wrong time and the event log was messy.
Already check everything commented in this post and all was OK.
My only suspicious is over the weather service , which is who provide the sunset time , right?
The current sunset, is always close of 18h25m.
My power outage was between 16h20 and 20h39.
The automation ran at 22:39 .
My automation trigger is :
alias: Acender luzes ao por do sol
description: Acende apenas se Cesar ou Thamiris estao em casa.
trigger:
- platform: sun
event: sunset
offset: '- 00:05:00'
This automation ran few scenes which turn on some internal and external lights.
I wakeup twice with all lights on.
However , the automation event log, shows only one execution.
ButâŚ
The event log from one of the lights, show the twice times which was turned on
Checked the syslog of my linux and they up with correctly time, so , isnât a problem of wrong time sync.
Also, my internet begin online in less of 2 minutes after the end of the power outageâŚ
My guess is something wrong about the weather services, some kind of internal timer/countdown to the sunset which pause during the power outage and back the countdown when it return.
I saw that because the differ between the moment of the outage and the sunset, is very close of the gap where the system back online and when the automation triggered :
power outage = 16h20 , sunset ~ 18h25 = 2h05 of gap.
power return = 20h39 , aumation triggered at 22h39 = 2h00 of gap.
Only the second trigger of the automation at 23h09 was very weird and without any plausible explanation.
Does anyone know something about this?
There is anyplace where I can ask for something like this for the developers?