-
Notifications
You must be signed in to change notification settings - Fork 34
Description
After a tracked flight lands, its tracked_type changes from live to scheduled instead of the flight being automatically removed from tracking.
At the moment, there doesn’t appear to be native support for automatically removing a tracked flight once it has landed. This may be something that could be added in the future.
work around this, I created a Home Assistant automation that monitors the attributes of the Tracked Flight sensor. When a flight transitions from live to scheduled, the automation interprets this as the flight having completed and removes it from tracking automatically.
I intentionally did not rely on the built-in event provided by the integration, as it was not behaving reliably in my setup. Using the sensor attributes and state transitions proved to be more consistent.
This approach keeps the tracked flights list clean without manual intervention and aligns with how FlightRadar24 reports flight completion.
alias: Flight tracking finished
description: ""
triggers:
- value_template: >
{% set flights = state_attr('sensor.flightradar24_additional_tracked',
'flights') %} {% if flights and flights | length > 0 %}
{{ flights[0].tracked_type == 'scheduled' }}
{% else %}
false
{% endif %}
trigger: template
enabled: false
- value_template: >+
{% set flights =
state_attr('sensor.flightradar24_additional_tracked','flights') or [] %}
{{ flights | selectattr('tracked_type','equalto','scheduled') | list |
length > 0 }}
trigger: template
alias: "When Any Flight Changes its tracked_type: to Scheduled"
conditions:
- condition: template
value_template: >
{% set before = trigger.from_state.attributes.flights if
trigger.from_state else [] %} {% set after =
trigger.to_state.attributes.flights if trigger.to_state else [] %} {% set
ns = namespace(found=false) %}
{% if before and after %}
{% for f in before %}
{% set match = after | selectattr('id','equalto', f.id) | list %}
{% if match and f.tracked_type == 'live' and match[0].tracked_type == 'scheduled' %}
{% set ns.found = true %}
{% endif %}
{% endfor %}
{% endif %}
{{ ns.found }}
alias: Ensuring Flight Changed from Live to Scheduled
actions:
- action: input_boolean.toggle
metadata: {}
target:
entity_id: input_boolean.ac
data: {}
- variables:
ended_flights: >
{% set before = trigger.from_state.attributes.flights if
trigger.from_state else [] %} {% set after =
trigger.to_state.attributes.flights if trigger.to_state else [] %} {%
set ns = namespace(out=[]) %} {% if before and after %}
{% for f in before %}
{% set match = after | selectattr('id','equalto', f.id) | list %}
{% if match and f.tracked_type == 'live' and match[0].tracked_type == 'scheduled' %}
{% set ns.out = ns.out + [f.flight_number] %}
{% endif %}
{% endfor %}
{% endif %} {{ ns.out | join(',') }}
alias: Identifying all the Flights that have ended/landed
- action: text.set_value
target:
entity_id: text.flightradar24_remove_from_track
data:
value: "{{ ended_flights }}"
alias: Remove the Flight From Being Tracked
mode: single