I have the following automation that sends a notification to my wife when I leave work:
- alias: "Notify Pieter Going Home from Work in XXX"
trigger:
platform: zone
entity_id: person.pieter_rautenbach
zone: zone.pieter_work_xxx
event: leave
condition:
- condition: time
after: "16:00:00"
weekday:
- mon
- tue
- wed
- thu
- fri
action:
- service: script.turn_on
entity_id: script.send_pieter_work_xxx_to_home_eta
This works well, except that my office location is right next to a highway (the one I normally take home) and there has been cases where I/we drive past the office on that same highway (e.g. on holiday and going to the city for the day), which will cause it to trigger.
What is my best resort? Creating a helper sensor that e.g. turns true if I’m at work for a certain time? But if this helper uses the same zone information, then that sensor will also change state at the same time the automation’s trigger will fire (which would be the same as incorrectly using a zone condition in the automation, because it will then never fire/be true), unless I use a delay in the helper to only change state a few seconds later.
I believe that if you switch to a state trigger, you can use pieter_work_xxx as the to: state and put a for: time to debounce the automation.
If that doesn’t work, you could put a delay followed by a condition in your automation action to check that you are still in the zone before proceeding with the rest of the actions.
Edit: the linked post indicates that my first proposal would work.
Would it work? If I understand it correctly the for will only check that the zone has changed from work to not home, and then has stayed as not home for a certain amount of time. The time check needs to be moved up to the from. As in, when the state changes from work to not home, check if the person was at work for more than a set amount of time.
You’re right. I didn’t note that it’s for leaving, not entering.
How often is your wife with you during these false triggers? If you have location tracking on her phone, and you’re often together when these false triggers happen, you could add a template condition that checks that you are not together (that is, not closer than say a quarter mile of each other).
Something similar would probably work pretty well, I’m just unsure if this is the best execution. Unless tracking work hours is the goal, is there a point to making it a history stat? Also, tracking the last state change time instead and ensuring it wasnt too recent would be usable for any zone change, rather than just work.