Custom Component: Flightradar24

Hi,
I’m trying to update a google sheet with information about flights entering my area using this awesome component. I’m not good at writing my own yaml so this is where I’m getting stuck. I’d like a new row created in a google sheet that lists things like flight number, altitude, destination. Probably through an automation.
I’ve created other basic automations in the past for ‘heatpump on when its cold’ etc. But nothing like this…

Google sheets integration and flightradar24 are running successfully already.
I can put information into my google sheet using Developer Tools>Actions>Google Sheets: Append to sheet, so the intergration is working and flightradar24 updates my dashboard with info on flights in my area.
Also I’m using Core 2024.12.5 Supervisor 2024.12.0 Operating System 14.1 Frontend 20241127.8

I’m stuck with what yaml to put into my google sheets configuration through the Automations GUI.
It asks for information to be entered into the ‘data’ fields. These need to first inform the column name (e.g. Plane ID:) then some yaml to get the right info from FlightRadar24.
This information ‘I Think’ is only available when a plane is in the area.

- id: '1735328046269'
  alias: Loud Plane
  description: ''
  triggers:
  - trigger: numeric_state
    entity_id:
    - sensor.flightradar24_current_in_area
    above: 0
  conditions:
  - condition: numeric_state
    entity_id: sensor.atom_bluetooth_proxy_0cf24c_sound_level
    above: 60
  actions:
  - action: google_sheets.append_sheet
    data:
      config_entry: 01JFZTKEK46PKD8CQXHZB6WQ9Z
      worksheet: PlaneNoise
      data:
        Callsign: '{{ trigger.event.data.callsign }}'
  mode: single

Getting 3 errors:
Error while executing automation automation.loud_plane: Error rendering data template: UndefinedError: ‘dict object’ has no attribute ‘event’

Loud Plane: Error executing script. Error for call_service at pos 1: Error rendering data template: UndefinedError: ‘dict object’ has no attribute ‘event’

Template variable error: ‘dict object’ has no attribute ‘event’ when rendering ‘{{ trigger.event.data.callsign }}’

Thanks for any help with this

I made some modifications to the markdown code.

  • Labels in grey and only content in white
  • none Values are not shown
  • Translation to german
    2024-12-30_15h09_28

And I also tried to identify helicopters but the code is not working as expected.
The loop is working fine and sets the is_heli to true, but after the endfor is_heli is reset to false again. Does anybody know how to solve that?

conditions:
  - condition: numeric_state
    entity: sensor.flightradar24_current_in_area
    above: 0
card:
  type: markdown
  content: >-
    {% set data = state_attr('sensor.flightradar24_current_in_area','flights') %}  
    {% set heli_prefixes = ["Airbus AS", "Airbus H", "Bell", "EC", "Hughes", "MD", "R44"] %}   
    {% for flight in data %}
      {% set is_heli = false %}
      {% for prefix in heli_prefixes %}
        {% if flight.aircraft_model.startswith(prefix) %}
          {% set is_heli = true %}
          {% break %}
        {% endif %}
      {% endfor %}
      {% if is_heli %}<ha-icon icon="mdi:helicopter"></ha-icon>{% else %}<ha-icon icon="mdi:airplane"></ha-icon>{% endif %}{% if flight.aircraft_registration is not none %}<font color="orange">{{ flight.aircraft_registration }}</font> - {% endif %}<font color="white">{{ flight.aircraft_model }}</font>{% if flight.airline_short is not none %}<font color="darkgrey"> - Airline: </font><font color="white">{{ flight.airline_short }}</font>{% endif %}
      {% if flight.flight_number is not none %}<font color="darkgrey">Flight</font> <font color="white">{{ flight.flight_number }}</font> <font color="darkgrey">from</font> <font color="white">{{ flight.airport_origin_city }}</font> {% if flight.airport_origin_city %}<img src="https://flagsapi.com/{{ flight.airport_origin_country_code }}/shiny/16.png" title="{{ flight.airport_origin_country_name }}"/>{% endif %} <font color="darkgrey">to</font> <font color="white">{{ flight.airport_destination_city }}</font> {% if flight.airport_destination_country_code %}<img src="https://flagsapi.com/{{ flight.airport_destination_country_code }}/shiny/16.png" title="{{ flight.airport_destination_country_name }}"/>{% endif %}{% else %}<font color="darkgrey">keine Flugnummer verfügbar</font>{% endif %}
      {% if flight.time_scheduled_departure is not none %}<font color="darkgrey">Startzeit: </font><font color="white">{{ flight.time_scheduled_departure | timestamp_custom('%H:%M') }}</font>{% endif %}{% if flight.time_scheduled_arrival is not none %}<font color="darkgrey"> | Ankunftszeit: </font><font color="white">{{ flight.time_scheduled_arrival | timestamp_custom('%H:%M') }}</font>{% else %}<font color="darkgrey">keine Flugdaten verfügbar</font>{% endif %}
      {% if flight.altitude > 0 %}<font color="darkgrey">Flughöhe: </font><font color="white">{{ flight.altitude }} ft | {{(flight.altitude * 0.3048) | round(0)}} m</font>{% endif %}
      {% if flight.ground_speed > 0 %}<font color="darkgrey">Geschwindigkeit: </font><font color="white">{{ flight.ground_speed }} kts | {{(flight.ground_speed * 1.852) | round(0)}} km/h</font>{% endif %}
    {% endfor %}

alias: Log Flight Data to Google Sheet
description: ""
triggers:
  - trigger: numeric_state
    entity_id:
      - sensor.flightradar24_entered_area
    above: 0
conditions: []
actions:
  - data:
      config_entry: dcc06e4f4c196953d535dcb9abb6e245
      worksheet: Flight Log
      data:
        Date: "{{ now().strftime('%-d-%b-%Y') }}"
        Time: "{{ now().strftime('%I:%M %p') }}"
        Flight Number: >-
          {{ state_attr('sensor.flightradar24_entered_area',
          'flights')[0].flight_number }}
        Airline: >-
          {{ state_attr('sensor.flightradar24_entered_area',
          'flights')[0].airline }}
        Aircraft Model: >-
          {{ state_attr('sensor.flightradar24_entered_area',
          'flights')[0].aircraft_model }}
        Origin: >-
          {{ state_attr('sensor.flightradar24_entered_area',
          'flights')[0].airport_origin_city }} ({{
          state_attr('sensor.flightradar24_entered_area',
          'flights')[0].airport_origin_code_iata }})
        Destination: >-
          {{ state_attr('sensor.flightradar24_entered_area',
          'flights')[0].airport_destination_city }} ({{
          state_attr('sensor.flightradar24_entered_area',
          'flights')[0].airport_destination_code_iata }})
        Scheduled Departure: >-
          {{ state_attr('sensor.flightradar24_entered_area',
          'flights')[0].time_scheduled_departure | timestamp_custom('%I:%M %p')
          }}
        Scheduled Arrival: >-
          {{ state_attr('sensor.flightradar24_entered_area',
          'flights')[0].time_scheduled_arrival | timestamp_custom('%I:%M %p') }}
        Altitude: >-
          {{ state_attr('sensor.flightradar24_entered_area',
          'flights')[0].altitude }}
        Altitude UOM: ft
        Ground Speed: >-
          {{ (state_attr('sensor.flightradar24_entered_area',
          'flights')[0].ground_speed * 1.15078) | round(0) }}
        Speed UOM: MPH
        Flight Time: >-
          {{ ((state_attr('sensor.flightradar24_entered_area',
          'flights')[0].time_scheduled_arrival -
          state_attr('sensor.flightradar24_entered_area',
          'flights')[0].time_scheduled_departure) / 3600) | int }}h {{
          (((state_attr('sensor.flightradar24_entered_area',
          'flights')[0].time_scheduled_arrival -
          state_attr('sensor.flightradar24_entered_area',
          'flights')[0].time_scheduled_departure) % 3600) / 60) | int }}m
    enabled: true
    action: google_sheets.append_sheet
mode: single

1 Like

Thankyou so much @chintito4ever
I’m going to try this out now

@chintito4ever that works perfectly. Thanks again for your help with this. Much appreciated.

1 Like

@AlexandrErohin and @jake54128 -

I started looking at this again today, having a little bit of uninterrupted time to play around with my HA setup. I did find where I can add a flight to be tracked using a Lovelace card:

image

When I enter one of my planes in there, however, whether by flight number or tail number, it is not persistent. I see nothing in my Developers Tools that shows a tracker for the flight or tail number was created.

I think there might be another configuration step, but following the instructions in the documentation takes me back & forth between two sections.

The only change I’ve made to configuration.yaml at this point is to decrease the database size, as suggested.

Sean

Further investigation, I can see in my logs that FR24 complained “no flights found” when I tried to enter either the flight number or the tail number. Indeed, the plane is sitting on the ground. I’d like it to be tracked if/when it takes off, and also notified of that action.

I tried this and I am lost. If I try to add it with

type: iframe
url: /config/www/bon.html
aspect_ratio: 100%

ii loads for ever. (the local option prefix doesn’t work for me)
I am also incompetent at Adding a web page card

The integration works great though

Hi,

Could you please help with this as I do not have the sensor.flights_above_today available as an entity. Am/Have I done some thing wrong?

I actually created using Home Assistant’s built in Utility Meter…I explained it here:

:man_facepalming: Apologies mate. I knew i had missed somethig. Thank you for getting back to me so quick.

1 Like

Ok, so i think i have it set up now. i do however keep receiving ground vehicle details.
Could someone please help a noob figure out how i can set it to ignore the ground vehicles?

this is what is displayed for a GV.
None(None) - None - Airport Ground Vehicle
None → None

I did look for what to add to the code to ignore them, but i can not find it.

It will be nice if

  1. only specific flight can be tracked (do not need overhead flights). Tracking stops when all tracked flights have landed
  2. Document is updated to provide instruction on how to add/remove specific flights

image
Isn’t it already part of the Integration?

Thanks for sharing.

  1. can it be done without api ?
  2. Can we add/remove flight dynamically to track (using automation) or lovelace dashboard?

Why the f is this not working?


It never gets fired.

I found the solution now, how to show the helicopter symbol. Here the corrected code

      type: markdown
      content: >-
        {% set data = state_attr('sensor.flightradar24_current_in_area','flights') %} 
        {% set heli_prefixes = ["Airbus AS", "Airbus H", "Bell", "EC", "Hughes", "MD", "R44"] %} {% for flight in data %}
          {% set is_heli = namespace(value=false) %}
          {% for prefix in heli_prefixes %}
            {% if flight.aircraft_model.startswith(prefix) %}
              {% set is_heli.value = true %}
              {% break %}
            {% endif %}
          {% endfor %}
          {% if is_heli.value %}<ha-icon icon="mdi:helicopter"></ha-icon>{% else %}<ha-icon icon="mdi:airplane"></ha-icon>{% endif %}{% if flight.aircraft_registration is not none %}<font color="deepskyblue">{{ flight.aircraft_registration }}</font> - {% endif %}<font color="white">{{ flight.aircraft_model }}</font>
          {% if flight.airline_short is not none %}<font color="darkgrey"> Airline: </font><font color="white">{{ flight.airline_short }}</font>{% endif %}
          {% if flight.flight_number is not none %}<font color="darkgrey">Flight</font> <font color="white">{{ flight.flight_number }}</font> <font color="darkgrey">from</font> <font color="white">{{ flight.airport_origin_city }}</font> {% if flight.airport_origin_city %}<img src="https://flagsapi.com/{{ flight.airport_origin_country_code }}/shiny/16.png" title="{{ flight.airport_origin_country_name }}"/>{% endif %} <font color="darkgrey">to</font> <font color="white">{{ flight.airport_destination_city }}</font> {% if flight.airport_destination_country_code %}<img src="https://flagsapi.com/{{ flight.airport_destination_country_code }}/shiny/16.png" title="{{ flight.airport_destination_country_name }}"/>{% endif %}{% else %}<font color="darkgrey">keine Flugnummer verfügbar</font>{% endif %}
          {% if flight.time_scheduled_departure is not none %}<font color="darkgrey">Startzeit: </font><font color="white">{{ flight.time_scheduled_departure | timestamp_custom('%H:%M') }}</font>{% endif %}{% if flight.time_scheduled_arrival is not none %}<font color="darkgrey"> | Ankunftszeit: </font><font color="white">{{ flight.time_scheduled_arrival | timestamp_custom('%H:%M') }}</font>{% else %}<font color="darkgrey">keine Flugdaten verfügbar</font>{% endif %}
          {% if flight.altitude > 0 %}<font color="darkgrey">Flughöhe: </font><font color="white">{{ flight.altitude }} ft | {{(flight.altitude * 0.3048) | round(0)}} m</font>{% endif %}
          {% if flight.ground_speed > 0 %}<font color="darkgrey">Geschwindigkeit: </font><font color="white">{{ flight.ground_speed }} kts | {{(flight.ground_speed * 1.852) | round(0)}} km/h</font>{% endif %}
        {% endfor %}

The trick is to use a namespace, so that the variable keeps valid after the loop.
set is_heli = namespace(value=false)

Now the card looks like this, if the name belongs to any helicopter in our area:

2025-01-29_12h36_07

Afternoon,
I absolutely love this, do you have more detail on how to do this with out the translation .I just think this is brilliant for my inner geek

1 Like

Hi all, Im trying to setup this integration properly but everything is becoming a mess. My main problem is having the cards stay with the last relevant info and not them disappearing, see pics.

Any way to do this?


This is what I want, even when the plane exits, I want to see the last plane.

Right now when the plane leaves, I see this:

Any help would be greatly appreciated.
Afterwards, Ill do a good cleanup.

type: vertical-stack
cards:
  - type: entities
    entities:
      - entity: sensor.flightradar24_current_in_area
        name: In area
    show_header_toggle: true
  - type: conditional
    conditions:
      - condition: numeric_state
        entity: sensor.flightradar24_current_in_area
        above: 0
    card:
      type: markdown
      content: >-
        {% set data = state_attr('sensor.flightradar24_current_in_area',
        'flights') %} {% for flight in data %}
          <ha-icon icon="mdi:airplane"></ha-icon>{{ flight.flight_number }}({{ flight.aircraft_registration }}) - {{ flight.airline_short }} - {{ flight.aircraft_model }}
          {{ flight.airport_origin_city }}{%if flight.airport_origin_city %}<img src="https://flagsapi.com/{{ flight.airport_origin_country_code }}/shiny/16.png" title='{{ flight.airport_origin_country_name }}'/>{% endif %} -> {{ flight.airport_destination_city }}{%
          if flight.airport_destination_country_code %}<img src="https://flagsapi.com/{{ flight.airport_destination_country_code }}/shiny/16.png" title='{{ flight.airport_destination_country_name }}'/>{% endif %}
          {%if flight.time_scheduled_departure %}Departure - {{ flight.time_scheduled_departure | timestamp_custom('%H:%M') }}; {% endif %}{%if flight.time_scheduled_arrival%}Arrival - {{ flight.time_scheduled_arrival | timestamp_custom('%H:%M') }}{% endif %}
          Altitude - {{ flight.altitude }} ft{%if flight.altitude > 0 %} ({{(flight.altitude * 0.3048)| round(0)}} m){% endif%}; Gr. speed - {{ flight.ground_speed }} kts{%if flight.ground_speed > 0 %} ({{(flight.ground_speed * 1.852)| round(0)}} km/h){% endif%}
          {% endfor %}
  - type: iframe
    url: >-
      https://www.flightradar24.com/simple?lat=-33.69&lon=150.93&z=14&label1=reg&size=small
    aspect_ratio: 100%
grid_options:
  columns: 12
  rows: 8

There’s some discussion of Aircraft History back in this thread that should get you started on what you are trying to do…
If you search “history” in this thread you’ll get a few posts.

2 Likes