hottl
February 8, 2024, 4:48pm
1
I have an automation with several actions & delays, ie
When
the time is equal to 7:00 Then do
xxx
Delay
for 30:00 Then do
yyy
Delay
for 1:30:00 Then do
zzz
Will yyy and zzz action if I re-boot the HA server at say, 8:00? If not, what would be the tidiest way to achieve what I want?
Many thanks!
123
(Taras)
February 8, 2024, 4:57pm
2
When you reboot/restart Home Assistant, any automations that are busy processing their actions (delay
, wait_template
, repeat
, etc) are terminated. After startup, the automation does not resume from the point where it was terminated.
Depends on the application’s purpose. It may be possible to redesign the automation to avoid using delay
, perhaps with a timer
.
Post your automation.
hottl
February 8, 2024, 5:18pm
3
Many thanks, @123 This light should come on for a period in the morning, then again in the evening;
I could do two automations, but I was keen to try to reduce the number by combining morning and evening activities where possible.
alias: Lights - Bridge
description: ""
trigger:
- platform: time
at: "07:00:00"
condition: []
action:
- service: light.turn_on
metadata: {}
data:
brightness: 50
target:
entity_id: light.bridge
- delay:
hours: 0
minutes: 30
seconds: 0
milliseconds: 0
- service: light.turn_on
metadata: {}
data: {}
target:
entity_id: light.bridge
- delay:
hours: 1
minutes: 30
seconds: 0
milliseconds: 0
- service: light.turn_off
target:
entity_id: light.bridge
data: {}
- delay:
hours: 9
minutes: 0
seconds: 0
milliseconds: 0
- service: light.turn_on
metadata: {}
data: {}
target:
entity_id: light.bridge
- delay:
hours: 4
minutes: 0
seconds: 0
milliseconds: 0
- service: light.turn_on
metadata: {}
data:
brightness: 20
target:
entity_id: light.bridge
- delay:
hours: 1
minutes: 15
seconds: 0
milliseconds: 0
- service: light.turn_off
target:
entity_id: light.bridge
data: {}
mode: single
123
(Taras)
February 8, 2024, 5:51pm
4
I suggest you simply use Time Triggers with a variable to specify the light’s brightness (0
is off
).
alias: Lights - Bridge
description: ""
trigger:
- platform: time
at: "07:00:00"
variables:
level: 50
- platform: time
at: "07:30:00"
variables:
level: 100
- platform: time
at: "09:00:00"
variables:
level: 0
- platform: time
at: "18:00:00"
variables:
level: 100
- platform: time
at: "22:00:00"
variables:
level: 20
- platform: time
at: "22:00:00"
variables:
level: 0
condition: []
action:
- service: light.turn_on
data:
brightness: '{{ level }}'
target:
entity_id: light.bridge
mode: single
It’s easier to maintain the automation, such as when you want to re-schedule a specific turn on/off time, and it’s far less vulnerable to failures caused by restarting Home Assistant. This version is vulnerable only if Home Assistant is in the process of restarting at one of the 6 scheduled times. There are ways to mitigate that as well.
A brief tutorial demonstrating how to create a single automation to control a light that is able to handle missed events (i.e. Home Assistant is off when the primary trigger(s) occur).
Implemented as two automations:
Turn on a light just before sunset - alias: 'Scheduled Exterior On'
trigger:
- platform: numeric_state
entity_id: sun.sun
attribute: elevation
below: 1.8
action:
- service: light.turn_on
target:
entity_id: light.exterior
Turn off a light just b…
NOTE
You could simply use a trigger’s id
to hold the desired brightness value but I chose to use a trigger variable just to demonstrate its capabilities.