Hi there! I have an automation where my garage door opens whenever my husband or I enter the home zone. The other day, in the middle of the night, the garage door randomly opened when we were both at home sleeping. I looked at the logs and traced it down to the fact that both of our locations went from “at home”, to “unknown” for just a blip of time, and then back to “at home”. That change from “unknown” back to “at home” was enough to trigger the garage door opening. I need some way to supervise this so little blips in location changes don’t randomly open my garage.
I was thinking of changing my trigger to something like: if zone.home changes from 0 → 1, or 1 ->2, then run the garage opening automation. That way when zone.home changes from “unknown” → 2 in the middle of the night, hopefully it won’t trigger. But I don’t know how to go about doing this!
Check trigger.from_state.state to make sure it was not unknown/unavailable.
Or, make sure it was away.
Or, if you connect your phone to your car, add a condition that only works if the phone is connected to the car.
This is what I have for trigger and condition
triggers:
- trigger: state
entity_id:
- person.me
- person.her
conditions:
- condition: template
value_template: >-
{{ trigger.from_state.state not in 'unavailable,unknown' and trigger.to_state.state not in 'unavailable,unknown' }}
Then down below I have a bunch of different conditions and stuff it does where I check zones before doing things. But for the garage, the person needs to be me and I am connected to Android Auto in my truck to open my garage door.
I’m thinking your “and” between the two conditions should be an “or”… am I wrong?
trigger.from_state.state not in ‘unavailable,unknown’ OR trigger.to_state.state not in ‘unavailable, unknown’
Since you don’t want to run any of the automations if either the old state or the new state it is transitioning into is unavailable/unknown. (I think…)
Thanks again for your help. I figured out how to add your template to the UI… I’ll try it with the OR and see how it goes.
I’m not following your other solution… “from:away and to:home in the UI”. I’m a big fan of the UI so this would be cool to do, but I can’t figure out what you’re talking about!
Found it! Except my options are “Home” and “Not home” instead of “Home” and “Away”. I am hoping that “Not home” doesn’t include the “unavailable” or “unknown” states too. I don’t think it does, since those are listed separately.
Also, over time you will get away from the UI. Not totally at all. But as your wants get more involved, you will want some YAML in some situations.
My automation for this is actually much more involved as it handles all zones we may go into and allows us to get notified as each other travels. But also does not notify her if I am at my brother’s house hours away and run to the store there.
I could probably do this all in UI. But it would be 20ish automations I am guessing.
I have two input_booleans named stalk_me and stalk_her
ETA: Also coding that condition in YAML as it is probably means if your location provider changes, you have no change to HA.
There are a few more things you can do, e.g. to only execute between certain times and to check that there wasn’t a recent event.
Here is part of one of my automations:
- alias: "Open The Gate When Arriving Home"
initial_state: true
trigger:
- platform: state
entity_id: binary_sensor.pieter_present
to: "on"
# prevent false positive due to flaky connectivity or after loadshedding and sensors being unavailable
not_from: "unavailable"
mode: single
condition:
- condition: and
conditions:
# prevent a glitch in case the cover was recently closed
# since there is also an availability template for the cover defined, it will usually also prevent the gate from opening
# when the location gets updated after the power returns (after loadshedding)
- condition: state
entity_id: cover.main_gate
state: "closed"
for:
minutes: 2
- condition: time
after: "07:00:00"
before: "23:00:00"
This is good stuff. I also have a gate so I need to think about this.
I had no idea not_from is a thing, thanks for the example of how to use it. They need to add this to the GUI!