Device tracer and dynamic zones

My car has a GPS tracker which is available in HA via Tracar.
I’d like to have a script/automation that does the following:

  1. “arm” via button, which creates a temporary zone of x meters around the current position of the device tracker.
  2. if the device tracker now leaves the zone for more than x minutes, send a notification to mobile phone.
  3. “disarm” via button, removes the temporary zone

Step 2 should not be a problem, but I have not found a way to dynamically create/delete a zone in HA.

Is there currently any way to solve this

1 Like

I assume this is the same use case, i.e. you want to know if somehting is moving and lat/lon is chnaging to quickly to be accurate
Create a zone around a moving person - Configuration - Home Assistant Community (home-assistant.io)

You can also try to see if this can be added to Spook :slight_smile:
frenck/spook: Spook :ghost: Not your homie (github.com)

Thanks, I had already seen the post when I was looking for a solution.

Zones would be nice because they would be shown nicely on the map.

Agree that is a nice feature too, ask with Spook

https://github.com/frenck/spook/issues/151

Added services to manage zones added in Spook:

https://github.com/frenck/spook

1 Like

Is it possible to put as latitude and longitude the values of 2 sensors?

I am trying to create a Zone (when I press a button) based on a GPS position that I have (GPS coordinates) and a radius (another entity with a radius value). This Zone is temporary, and changes each time I press the button.

Is this possible?

You can use the spook services to do so. I guess you would have to use the same ‘name’ as then you can create one script that deletes any existing zone with that name and subsequently create a new one.

but in Spook can the lat and long be sensor?

In the service call you should be able to refer to the lat/lon of the sensor you need (via template)
EDIT:
alike:

service: zone.create
data:
  radius: 300
  latitude: "{{ state_attr('device_tracker.iphone','latitude') }}"
  longitude: "{{ state_attr('device_tracker.iphone','longitude') }}"
  name: test

This is my code unforrtuntely in radius does not accpetr template? The template its correct


  - service: zone. Create
    data:
      radius: {{ states('input_number.anchor_radius') }}
      latitude: "{{ states('sensor.position_latitude') }}"
      longitude: "{{ states('sensor.position_longitude') }}"
      name: anchor

but when I launch it it modifies like this


  - service: zone. Create
    data:
      radius:
        "[object Object]": null
      latitude: "{{ states('sensor.position_latitude') }}"
      longitude: "{{ states('sensor.position_longitude') }}"
      name: anchor

You forgot the quotes, do read-up on templates :slight_smile:

Templating - Home Assistant (home-assistant.io)

1 Like

That was it. It’s working now