How to use passive zones with automations

I’m working on an automation that will detect when someone is on the road leaving home as well as another automation to detect when they are coming home. What I did was create two zones, one called Perimeter 1 and the other Perimeter 2 which encircle my house like so:

zone 5:
name: Perimeter 1
latitude: [Latitude of my house]
longitude: [Longitude of my house]
radius: 2500
passive: false

zone 6:
name: Perimeter 2
latitude: [Latitude of my house]
longitude: [Longitude of my house]
radius: 3500
passive: false

My automation looks like something like this:

  • alias: “Notify Joel is on his way out”
    trigger:
    platform: state
    entity_id: device_tracker.jmricker_jmricker
    from: ‘Perimeter 1’
    to: ‘Perimeter 2’
    action:
    service: notify.pushbullet
    data_template:
    title: “Notification”
    message: “Joel is on his way out.”

This is working pretty well. Next I would like to hide this from the map. According to the documentation, making a zone passive will only use the zone for automation and hide it from the UI and not use the zone for device tracker name. This is the part I’m stuck on. If I make the zone passive, the automation doesn’t trigger because the device doesn’t receive the zone name. If passive is mainly used for automations, how do I detect passive zones for triggers?

I use these in my zones.yaml in addition to the normal “Home”:

- name: Home Michael
  latitude: XXXXX
  longitude: XXXXX
  radius: 100
  passive: true 
  icon: mdi:worker

- name: Home Joanne
  latitude: XXXXX
  longitude: XXXXX
  radius: 100
  passive: true 
  icon: mdi:worker

And this in my proximity.yaml to track when my wife are at home or when either of us individually is away from home:

home: 
    devices:
      - device_tracker.joanne_jflte
      - device_tracker.michael_hlte
    tolerance: 100

home_michael: 
    zone: home_michael
    devices:
      - device_tracker.michael_hlte
    tolerance: 100

home_joanne: 
    zone: home_joanne
    devices:
      - device_tracker.joanne_jflte
    tolerance: 100

And then automate like this (the device_tracker.michael is my PING device_tracker which is used to double check I’m at home and avoid false triggers with GPS accuracy problems):

- alias: 'Michael Home Arrival'
  trigger:
    platform: numeric_state
    entity_id: proximity.home_michael
    below: 3
  condition:
    - condition: template
      value_template: '{{ states.proximity.home_michael.attributes.dir_of_travel == "towards" }}'
    - condition: state 
      entity_id: device_tracker.michael
      state: 'not_home'
    - condition: state
      entity_id: input_boolean.michael_outside_boundary
      state: 'on'
  action:
    service: script.home_michael_arrival

and I use this automation so I know when I’m not just doing things locally in our town (within 2km) by using a boolean for when I go outside the boundary (as I do different automations for that case):

- alias: 'Michael Outside Boundry'
  trigger:
    platform: numeric_state
    entity_id: proximity.home_michael
    above: 5
  action:
    service: script.michael_outside_boundary

I hope all that helps.

2 Likes

Just looking back over your case and I can see you are using two zones but you can do what you want with one only by just using the states.proximity.perimeter_1.attributes.dir_of_travel I would guess but in any case my examples allow individual and group tracking inside and out of a perimeter so it might come in handy and allow you to do more complex things with your scripts.

1 Like