Zone Wildcard Trigger template

Is there a way to add a wild card in from a zone trigger from a certain geolocation source,

For example I defined a custom zone equivalent of the range of my ADS-B SDR and want to set up a trigger to notify me of any plane that flies over that zone.

something like

trigger:
  - platform: template
    zone: zone.flightairmap_tracking
    event: enter
    entities: geolocation.flightairmap.*
action:
  - data_template:
      message: '{{trigger.from_zone.name}} plane spotted in your area'
      title: Alert
    service: notify.notify

I understand that is completely wrong but that’s the general consensus of it

what integration is creating the planes w/ geolocation?

It is a custom component that reads GeoJSON data from FlightAirMap
info here

Alright, just trying to get info about it.

So does it create a new entity? The format geolocation.flightairmap. isn’t correct for an entity_id. Can you provide a screenshot of the entity that is created by this?

I believe so, this is what I see for the entity under developer tools.

Well best I can offer is a “what planes are inside this zone” sensor. Outside of that, I can’t think of anything that would do this.

sensor:
- platform: template
  sensors:
    planes_in_zone:
      value_template: >
        {% set radius = state_attr('zone.home', 'radius') | int / 1000 %}
        {% set ns = namespace(inside=[]) %}
        {% for gl in states.geo_location if gl.object_id.startswith('flightairmap') and distance(gl.entity_id) < radius %}
          {% ns.inside = ns.inside + [ gl ] %}
        {% endfor %}
        {{ ns.inside | map(attribute='name') | join(', ') if gl | length > 0 else 'Empty' }}

This will watch for any geo_location state change, and add the plane to the list. THen you can use this sensor to make triggers. But you’ll get notifications when leaving or entering.

Now if you only want entering…

sensor:
- platform: template
  sensors:
    planes_in_zone:
      value_template: >
        {% set radius = state_attr('zone.home', 'radius') | int / 1000 %}
        {% set ns = namespace(inside=[]) %}
        {% for gl in states.geo_location if gl.object_id.startswith('flightairmap') and distance(gl.entity_id) < radius %}
          {% ns.inside = ns.inside + [ gl ] %}
        {% endfor %}
        {{ ns.inside | count }}
      attribute_templates:
        latest: >
          {% set current = state_attr('sensor.planes_in_zone', 'planes').split(', ') %}
          {% set radius = state_attr('zone.home', 'radius') | int / 1000 %}
          {% set ns = namespace(inside=[]) %}
          {% for gl in states.geo_location if gl.object_id.startswith('flightairmap') and distance(gl.entity_id) < radius %}
            {% ns.inside = ns.inside + [ gl ] %}
          {% endfor %}
          {{ ns.inside | rejectattr('name', 'in', current) | map(attribute='name') | first }}
        planes: >
          {% set radius = state_attr('zone.home', 'radius') | int / 1000 %}
          {% set ns = namespace(inside=[]) %}
          {% for gl in states.geo_location if gl.object_id.startswith('flightairmap') and distance(gl.entity_id) < radius %}
            {% ns.inside = ns.inside + [ gl ] %}
          {% endfor %}
          {{ ns.inside | map(attribute='name') | join(', ') }}

Then in your automation…

- alias: Notify entering planes.
  trigger:
  - platform: state
    entity_id: sensor.planes_in_zone
  condition:
    condition: template
    value_template: >
      {{ trigger.to_state != None and trigger.from_state != None and
         trigger.to_state.state | int > trigger.from_state.state | int }}
  action:
  ....

Theres a very good chance this doesn’t work out of the box because I haven’t tested any of it.

This is my automation for planes entering a custom zone named “plane_far”. It then just currently sends a message to my slack channel #planes with the name of the plane.

- alias: Planes
  id: 50a0b332433534435345
  trigger:
    platform: geo_location
    source: flightairmap_feed
    zone: zone.plane_far
    # Event is either enter or leave
    event: enter # or "leave"
  action:
    - service: notify.slack
      data:
        message: "Plane in far zone {{ trigger.to_state.name }}"
        target:
          - "#planes"

My zone “plane_far” is also set as passive so it still uses my home zone for my other automation involving my home.

This is just adapted from the automation page documentation.

Well TIL. I did not know about geo_location triggers. Nice!

Awesome! So I think I just overthought it and by not specifying a specific name you in turn are just saying all planes?
Learning more and more every day!!