I’ve run into something odd with a simple pair of automations controlling a Tasmota-based switch (via MQTT).
Setup:
- Automation 1 starts the machine at 12:00 PM
- Automation 2 is supposed to stop the machine after it’s been ON for 30 minutes
What happened:
- The machine started at 12:00 PM as expected.
- Around 12:12 PM, Home Assistant restarted.
- During restart, the switch entity briefly went
unavailable→off(for about 1.26 seconds) →on. - After restart, I expected the 30-minute timer to restart from 12:12 PM and turn the machine off around 12:42 PM.
- But the “off” automation never triggered, and the machine kept running indefinitely.
Is this expected behavior that a for: duration in a state trigger doesn’t persist through restarts? And if so, is there a recommended approach to make it survive a restart?
Here’s the YAML for both automations:
alias: Machine - On
description: ""
triggers:
- trigger: time
at: "12:00:00"
conditions: []
actions:
- action: switch.turn_on
metadata: {}
data: {}
target:
entity_id: switch.machine
mode: single
alias: Machine - Off
description: ""
triggers:
- trigger: state
entity_id:
- switch.machine
to: "on"
for:
hours: 0
minutes: 30
seconds: 0
conditions: []
actions:
- action: switch.turn_off
metadata: {}
data: {}
target:
entity_id: switch.machine
mode: single