I want a simple automation that fires when someone has been away from the house for X hours, eg:
triggers:
- trigger: state
entity_id:
- person.john
for:
hours: 8
minutes: 0
seconds: 0
to:
- not_home
However I am finding that even after they have been not_home for over 8 hours the automation does not trigger.
Is this because the state has not changed (although I see repeated updates to the state’s last_updated in developer tools) or as I see in the docs " Use of the for option doesn’t survive a Home Assistant restart or the reload of automations" - I have been editing other automations so perhaps this is reloading all of them?
Do you have other zones setup? Like Work or School?
If so, when John enters one of those zones, the state will be that zone name instead of not_home. When they leave another zone, it will go back to not_home and the for counter would start over.
You could use a timer helper set for 8 hours.
When John’s state goes from home, start the timer.
When the timer ends, do the actions you want.
When John’s state goes back to home, cancel the timer.
The state has to change from home to not_home to begin the 8 hour countdown. If the state remains not_home throughout the 8 hours, at the end of the countdown it will fire the State Trigger.
If the state changes before the completion of the countdown, the countdown is terminated and the trigger is reset (i.e. won’t start the countdown again until it detects a state-change from home to not_home).
It should only reload the automation that was modified. A restart will reload all automations.
It used to reload all automations even if only just one was modified (thereby resetting all of them) but that was many, many versions ago.
As per my first post, a change from any state to not_home should then start HA waiting for 8 hours with the state staying at not_home and then trigger the automation but that’s not happening?
I can see from state history that it changed from home to not_home and stayed that way for over 8 hours.