Hey, my first post, woo!
Down to brass tacks
I think the restart function in Home Assistant automations is not user-friendly and could use some reconfiguration. In the meantime, I believe I’ve figured out a solution to use it effectively.
A bold claim for a newbie, I know! Don’t’ get me wrong, i think HA is great, but this feature needs some work and after combing through several similar topics (there are about five on this forum), none seemed to provide a truly satisfying solution. I think I’ve discovered a method that works, but I also believe we shouldn’t have to jump through these hoops to make it work.
Here’s my use case (if you’re still with me):
I want my hallway lights to turn on when someone enters the hall and stay on as long as there’s movement. Once the hall is empty, the lights should turn off. Simple, right?
So, I set up an automation triggered by an occupancy sensor (Hue Motion Sensor). The automation includes rules for time of day, whether the lights are already on, and a one-minute timer after which the lights turn off. I also set the mode to restart.
But…it doesn’t work. The lights stay on instead of turning off.
Why doesn’t it work?
Simply put, the conditions that initially triggered the automation change after the trigger. In my case, at least two variables are no longer the same:
- The lux levels are now higher because the lights are on.
- The lights themselves are on, whereas they were off before the trigger.
When the occupancy sensor is triggered a second time during the automation’s wait period, the trace shows that none of the conditions are met. The automation takes the wrong path — straight to the end — where no actions are executed.
I think the restart setting should work differently. It should assume that the logic which originally triggered the automation still applies and should re-trigger the actions accordingly.
The workaround: Start at the end and work backward to avoid blind alleys
To solve this, you need to think about what you want to happen after the automation successfully runs. Then, work backward to build the sequence of actions. This approach ensures there are no blind alleys for the automation to get stuck in.
Here’s my current hallway automation. It has a few extra variables and a few redundancies, but it solves the issue effectively.
Anyway, that’s my first post about a problem and what I think is the solution. What do you think?
alias: HallwayAutoMotion
description: HallwayAutoMotion
triggers:
- type: occupied
device_id: f154
entity_id: 7059
domain: binary_sensor
trigger: device
conditions:
- condition: or
conditions:
- condition: state
entity_id: light.hallwaylights_2
state: "off"
- condition: state
entity_id: input_boolean.togglesensorhallway
state: "on"
actions:
- action: input_boolean.turn_on
metadata: {}
data: {}
target:
entity_id: input_boolean.togglesensor
- choose:
- conditions:
- condition: and
conditions:
- condition: or
conditions:
- condition: sun
after: sunrise
- condition: state
entity_id: schedule.schedule_night_lights
state: "off"
- condition: time
before: "08:00:00"
- condition: or
conditions:
- type: is_illuminance
condition: device
device_id: f154
entity_id: b792
domain: sensor
below: 15
- condition: state
entity_id: input_boolean.togglesensorhallway
state: "on"
sequence:
- target:
entity_id: scene.hallway_early_morning
action: scene.turn_on
data:
transition: 1
- delay:
hours: 0
minutes: 1
seconds: 0
- target:
entity_id: scene.hallway_off
action: scene.turn_on
data: {}
- action: input_boolean.turn_off
metadata: {}
data: {}
target:
entity_id: input_boolean.togglesensorhallway
- conditions:
- condition: and
conditions:
- condition: or
conditions:
- condition: sun
after: sunrise
- condition: state
entity_id: schedule.schedule_night_lights
state: "off"
- condition: time
after: "08:00:00"
- condition: or
conditions:
- type: is_illuminance
condition: device
device_id: f154
entity_id: b792
domain: sensor
below: 15
- condition: state
entity_id: input_boolean.togglesensorhallway
state: "on"
sequence:
- target:
entity_id: scene.hallway_daytime
action: scene.turn_on
data:
transition: 1
- delay:
hours: 0
minutes: 1
seconds: 0
- target:
entity_id: scene.hallway_off
action: scene.turn_on
data: {}
- action: input_boolean.turn_off
metadata: {}
data: {}
target:
entity_id: input_boolean.togglesensorhallway
- conditions:
- condition: and
conditions:
- condition: state
entity_id: schedule.schedule_night_lights
state: "on"
sequence:
- target:
entity_id: scene.hallway_nighttime
action: scene.turn_on
data:
transition: 1
- delay:
hours: 0
minutes: 1
seconds: 0
- target:
entity_id: scene.hallway_off
action: scene.turn_on
data: {}
- action: input_boolean.turn_off
metadata: {}
data: {}
target:
entity_id: input_boolean.togglesensorhallway
- action: light.turn_off
metadata: {}
data: {}
target:
entity_id: light.hallwaylights_2
- action: input_boolean.turn_off
metadata: {}
data: {}
target:
entity_id: input_boolean.togglesensorhallway
mode: restart
And here is the code in editor view for clarity .