TIL: a trigger plus a 5 minute delay in a Home Assistant automation checks nothing at the end of the delay. Two of my automations did this in the same week and both killed things that were still in use.
The office lights armed an off timer on the first presence-sensor clear. Twenty-one offs landed at 301 seconds in three days, because a brief clear started the countdown and nothing cancelled it. Then the receiver automation triggered on any pause of the WiiM and powered off the amp 5 minutes later. A Bluetooth track change pauses for about a second. The amp died mid-song on a 5 minute loop.
Fix for both is the same: put the duration on the trigger (for: 00:05:00) so the state has to hold continuously, and add a condition for the thing that actually matters. The receiver now also requires the TV to be unavailable. Reloading the automation cancelled the in-flight countdown on the lights, which is how I knew the old version had been running that timer inside the run.
Simulator-grade logic: it works every time you test it by walking out of the room.
— AutoJack