Hello, I want to switch off a fan after 7 pm. Above is the automation I am using. It works fine and switches off the fan at 7 pm. But in case there is no power lets say between 6:54 pm to 7:15 pm then this automation is not fired when Home-Assistant is started after the power cut. What am I doing wrong here ? How can make this automation to work if the power comes after 7pm.
I can use a trigger a Home-Assistant started and then check for time. But what is wrong in the above trigger I used. Wouldn’t that trigger get fired if hour>=19 ??
Why is it needed to trigger on startup ? Wouldn’t home-assistant check for the below trigger lets say at 20:00 hours if the power comes back at 19:45 ??
If Home Assistant is off during a power outage at either 6:54 pm to 7:15 pm`, 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:
Once a Template Trigger is triggered, it must first be “reset” before it will trigger again. The “reset” occurs when the template evaluates to false. It’s the change from false to true that serves to trigger it. In other words, it must first be false before it can change to true.
The first trigger triggers the automation at 19:00:00, the requirements of the Template Condition are fulfilled, and the switch is turned off.
If Home Assistant starts anytime between 19:00:00 and (moments before) 00:00:00, the second trigger will trigger the automation, the condition’s requirements are met, and the switch is turned off.
If you use Home Assistant > start trigger, you will probably want to use a wait_template to ensure everything needed loaded properly, otherwise your switch might not flip either (unknown/unavailable if integration has yet to fully load and report back to HA).
I was thinking about using events:
– create an automation raising an event at XXX minutes;
– then create automations listening to this event.
But - mainly for educational purpose - I wanted to create a blueprint which has input values:
– timeout in minutes after HA startup;
– list of actions
because I wanted to have a possibility to “postpone” actions for different timeouts.
Also I was thinking about using a delay - kind of:
trigger:
platform: homeassistant
event: start
action:
- delay:
minutes: !input input_TIMEOUT
- ... here call a list of actions
But I was not sure what is more effective - triggered at a particular time (“platform: template”) or calling a “delay” function.
“Effective” - means “uses less resources”.
Just noticed: if an automation uses a “delay” instead of a templated trigger - then after a manual forced starting the automation this delay is also executed.
So, both ways (delay after start OR templated trigger) have some “pro” & “contra”.