Automations with the mode: restart
configuration seem to have broken in 2021.4.x. The new debugging tool shows the automation stuck between the trigger firing and the first step executing.
The context is that I have an automation that detects when I’m working from home (in the study no less), which I use to boost the heating in my study when it fires. It’s been very reliable for months. One element is figuring out whether my work laptop is actually active; I’ve found that I need to add some additional logic to the macOS companion app to make sure it is active right now. I’ve found that the companion app sensors can become stale, which leads to misfires. Usually this happens when my Mac is asleep connected to my docking station.
To do this, I use an automation that tracks whether the companion app has updated a sensor in the last 6 minutes. If it has, we can trust that the companion app is active and the companion app sensors are not stale.
I do this with a simple automation that triggers when one of two frequently updated sensors are updated by the companion app. The automation sets an input_binary
and then clears it again 6 minutes later. I configure the automation with mode: restart
, so that every time a sensor updates, the 6 minute timer is reset. Something of a watchdog timer.
input_boolean:
nicks_workbook_app_alive:
name: Nick's workbook app alive
icon: mdi:laptop-mac
automation:
- alias: Nick's workbook app alive
id: 20884583-caa5-4f4b-979a-a0733783b2cf
trigger:
- platform: state
entity_id: sensor.nicks_workbook_pro_last_update_trigger
- platform: state
entity_id: sensor.nicks_workbook_pro_storage
mode: restart
action:
- service: input_boolean.turn_on
data:
entity_id: input_boolean.nicks_workbook_app_alive
- delay:
minutes: 6
- service: input_boolean.turn_off
data:
entity_id: input_boolean.nicks_workbook_app_alive
The working at home sensor, by the way, is as follows. The sensor considers whether my Mac is active, whether the macOS companion app can be trusted (the relevant automation at hand) whether I’m at home, whether I’m connected to my home wifi network (my Mac is at home), whether my docking station is connected (something is active in the study), and whether it is in work hours.
binary_sensor:
- platform: template
sensors:
nick_working_at_home:
friendly_name: Nick working at home
delay_on: 00:05:00
delay_off: 00:20:00
value_template: >
{{
states('binary_sensor.nicks_workbook_pro_active') == 'on'
and states('input_boolean.nicks_workbook_app_alive') == 'on'
and states('person.nick') == 'home'
and states('sensor.nicks_workbook_pro_ssid') == 'mySSID'
and states('device_tracker.docking_station') == 'home'
and states('sensor.time') >= '08:00'
and states('sensor.time') <= '21:30'
}}