Need a supervisory condition for when location drops out

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!

Does anyone have any ideas?

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.

1 Like

I updated my previous response with a sample.

Oh my gosh this is so helpful!!! I am implementing this now! THANK YOU!!

The state trigger actually have a not_from: parameter, but it’s not part of the UI I believe

1 Like

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…)

True. She could also just do from: away and to: home in the UI.

Mine does a bunch of different zone checking below. So, I didn’t want those. And I did not know about not_from and not_to when I wrote it :slight_smile:

Thanks. I’ll relook. You might have just fixed my automation.

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!

This is on your trigger.

No. An OR would allow the automation to proceed if either condition was true.

Meaning that your situation your are trying to fix would allow the automation to proceed.

Your situation was from unknown to home. An OR would proceed with the automation because the to was not unknown/unavailable.

We want them both not to be unknown/unavailable.

NOT logic hurts my head :slight_smile:

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.

That is odd. Here are my options
image

You are right. After writing it out in words, it makes sense to me why the AND is there! Thank you again!!

Also I’m wondering if my location options are different because I’m using the iCloud3 location detection? Are you using that?

No. And that makes sense.

Of course, use what your provider gives you :slight_smile:

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 :slight_smile:

ETA: Also coding that condition in YAML as it is probably means if your location provider changes, you have no change to HA.

That is cool! One day I’ll get there. Right now I’m just excited that I don’t have to press the button to open the garage when I get home, haha!

1 Like

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"
1 Like

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!