Is there a functional difference between these two triggers? In particular, I’m wondering if using the device trigger for a specific duration will trigger if the precise duration is missed for some reason. For example Home Assistant crashes, but later recovers. Would using a template to test for ‘greater than’ be a more reliable trigger? I suspect they’re doing the same thing and the last_changed is going to be reset when HA recovers.
The main difference is, the first one will work, and the second one won’t ever trigger.
The way the first one works is, when the switch turns on, the trigger will effectively monitor the state of the switch and won’t “fire” until it stays on for the specified 2 hours. If it goes off before that the trigger “resets.” The next time the switch turns on the 2 hour monitoring period will begin again.
The way the second one works is, whenever the switch changes state (goes on or off), the template will be evaluated. But since the last_changed
State object field will have just been updated, the difference between “now” and when it was updated will be almost zero. So it will not trigger. The template will not be re-evaluated until the state of the switch changes again. It will not be re-evaluate just because time changes. So, bottom line, it will never trigger.
That makes sense. Thank you.