Custom Component: Flightradar24

Flightradar24 integration for Home Assistant

IMPORTANT: No need FlightRadar24 subscription!
Flightradar24 integration allows one to track overhead flights in a given region, or particular planes. It will also fire Home Assistant events when flights enter/exit/landed/took off.

It allows you:

  1. Know how many flights in your area right now, or just have entered or exited it. And get list of flights with full information by every relevant flight for the sensor
  2. Track a particular plane or planes no matter where it currently is, even if it is a scheduled flight
  3. Get top 10 most tracked flights on FlightRadar24
  4. Create notifications (example - Get a notification when a flight enters or exits your area, Get a notification when a tracked scheduled flight takes off)
  5. Create automations (example - Automatically track a flight by your needs)
  6. Add flights table to your dashboard


Components

Events

  • flightradar24_entry: Fired when a flight enters the region.
  • flightradar24_exit: Fired when a flight exits the region.
  • flightradar24_most_tracked_new: Fired when a new flight appears in top 10 most tracked flights on FlightRadar24
  • flightradar24_area_landed: Fired when a flight lands in your area.
  • flightradar24_area_took_off: Fired when a flight takes off in your area.
  • flightradar24_tracked_landed: Fired when a tracked flight lands.
  • flightradar24_tracked_took_off: Fired when a tracked flight takes off.

Sensors

  • Current in area
  • Entered area
  • Exited area
  • Additional tracked
  • Most tracked flights (You may disable it via configuration)

Configuration

  • Add to track
  • Remove from track

Sensors shows how many flights in the given area, additional tracked, just have entered or exited it. All sensors have attribute flights with list of flight object contained a full information by every relevant flight for the sensor

Configuration inputs fields allows to add or remove a flight to/from sensor - Additional tracked. Adding/Removing supports flight number, call sign, aircraft registration number

Uses

Notification

To receive notifications of the entering flights add following lines to your configuration.yaml file:

automation:
  - alias: "Flight entry notification"
    trigger:
      platform: event
      event_type: flightradar24_entry
    action:
      service: notify.mobile_app_<device_name>
      data:
        message: "Flight entry of {{ trigger.event.data.callsign }} to {{ trigger.event.data.airport_destination_city }}"

Automation

To automatically add a flight to additional tracking add following lines to your configuration.yaml file:

automation:
  - alias: "Track flights"
    trigger:
      platform: event
      event_type: flightradar24_exit
    condition:
      - condition: template
        value_template: "{{ 'Frankfurt' == trigger.event.data.airport_origin_city }}"
    action:
      - service: text.set_value
        data:
          value: "{{ trigger.event.data.aircraft_registration }}"
        target:
          entity_id: text.flightradar24_add_to_track

This is an example to filter flights to track, change the conditions for your needs

Lovelace Card

You can add flight table to your Home Assistant dashboard

  1. Go to your dashboard
  2. In the top right corner, select the three-dot menu, then select Edit dashboard
  3. Click on + ADD CARD, search for Manual, click on Manual.
  4. Add following code to the input window and click SAVE
type: vertical-stack
title: Flightradar24
cards:
  - type: entities
    entities:
      - entity: sensor.flightradar24_current_in_area
        name: In area
  - 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.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 %}

Lovelace Card with Map

  1. Open in a browser https://www.flightradar24.com
  2. Move the map so that your area is in the middle of the screen. And scroll to select comfortable map zoom
  3. Now you have URL of the map like https://www.flightradar24.com/ 50.03,8.49/12 Remember this URL
  4. Go to your Home Assistant dashboard
  5. In the top right corner, select the three-dot menu, then select Edit dashboard
  6. Click on + ADD CARD, search for Manual, click on Manual.
  7. Add following code to the input window. Replace LATITUDE, LONGITUDE and ZOOM from URL from step 4. (Example - https://www.flightradar24.com/ 50.03,8.49/12 - LATITUDE is 50.03, LONGITUDE is 8.49, ZOOM is 12)
  8. Click SAVE
type: vertical-stack
title: Flightradar24
cards:
  - type: entities
    entities:
      - entity: sensor.flightradar24_current_in_area
        name: In area
  - 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=LATITUDE&lon=LONGITUDE&z=ZOOM&label1=reg&size=small
    aspect_ratio: 100%

Database decrease

To decrease data stored in database add following lines to your configuration.yaml file:

recorder:
  exclude:
    entity_globs:
      - sensor.flightradar24*

Flight fields

Field Description
tracked_by_device If you have defined more than one device of FlightRadar24 for more places to observe - you may be interested to know what device has fired the event. To renema the device check this
tracked_type Only for tracked flights. It shows is flight live or scheduled
flight_number Flight Number
latitude Current latitude of the aircraft
longitude Current longitude of the aircraft
altitude Altitude (measurement: foot)
distance Distance between the aircraft and your point (measurement: kilometers)
ground_speed Ground speed (measurement: knots)
squawk Squawk code are what air traffic control (ATC) use to identify aircraft when they are flying (for subscription only)
vertical_speed Vertical speed
heading The compass direction in which the craft’s bow or nose is pointed (measurement: degrees)
callsign Callsign of the flight
aircraft_registration Aircraft registration number
aircraft_photo_small Aircraft small size photo url
aircraft_photo_medium Aircraft medium size photo url
aircraft_photo_large Aircraft large size photo url
aircraft_model Aircraft model
aircraft_code Aircraft code
airline Airline full name
airline_short Airline short name
airline_iata Airline IATA code
airline_icao Airline ICAO code
airport_origin_name Origin airport name
airport_origin_code_iata Origin airport IATA code
airport_origin_code_icao Origin airport ICAO code
airport_origin_country_name Origin airport country name
airport_origin_country_code Origin airport country code
airport_origin_city Origin airport city name
airport_destination_name Destination airport name
airport_destination_code_iata Destination airport IATA code
airport_destination_code_icao Destination airport ICAO code
airport_destination_country_name Destination airport country name
airport_destination_country_code Destination airport country code
airport_destination_city Destination airport city name
time_scheduled_departure Scheduled departure time
time_scheduled_arrival Scheduled arrival time
time_real_departure Real departure time
time_real_arrival Real arrival time
time_estimated_departure Estimated departure time
time_estimated_arrival Estimated arrival time

Most tracked

Sensor Most tracked shows top 10 most tracked flights on FlightRadar24 with next flight fields

Field Description
flight_number Flight Number
callsign Callsign of the flight
squawk Squawk code are what air traffic control (ATC) use to identify aircraft when they are flying
aircraft_model Aircraft model
aircraft_code Aircraft code
clicks How many people track this flight
airport_origin_code_iata Origin airport IATA code
airport_origin_city Origin airport city name
airport_destination_code_iata Destination airport IATA code
airport_destination_city Destination airport city name

This integration should only be used for your own educational purposes. If you are interested in accessing Flightradar24 data commercially, please contact [email protected]. See more information at Flightradar24’s terms and conditions.

25 Likes

Do I need to subscribe to the FlightRadar24 Business Plan to use the api?

What a fantastic integration !
Installed and works perfect.
The only request I have if possible for the future. It may already be there but I could not see how to change once setup is the ability to adjust the Area distance from the dashboard. The Meters seem to be set once at setup.
Thanks for sharing.

No need FlightRadar24 subscribe!

Thank you!
The ability to change configuration (distance and position) is under development now. Would be in the next releases :slight_smile:

1 Like

Are you automating anything with this or is it just for interest?

By now only I use for notifications and Lovelace Card just for interest but looking for ideas to use it more

Thank you for this great integration! I would really like to see (and filter on) the altitude. Is it possible to add that?

The flight altitude would be added in the next release :slight_smile:

1 Like

Again, I love this component!
What I did (maybe inspiring others):

I created a flightradar24 “device” that listen to all flights within a radius of 500m around my home.
Whenever that happens, the speaker in the living room makes an announcement like:
The plane you hear now is from KLM. It comes from Atlanta in the United States and is on its way to Amsterdam.

My 5 year-old loves it :heart_eyes: and is learning a lot of cities and countries!
I actually have ChatGPT translate the message for me in Dutch, so the country names coming from the event are translated as well.

Translate in Dutch: {% if trigger.event.data.airline == 'Netherlands -
        Police' %}
          The police helicopter is flying in our neighborhood.
        {% elif trigger.event.data.airport_origin_country_name == 'Netherlands' %}
          The plane you hear now is from {{ trigger.event.data.airline }}. It comes from {{ trigger.event.data.airport_origin_city }} and is on its way to {{ trigger.event.data.airport_destination_city }}{% if trigger.event.data.airport_destination_country_name != 'Netherlands' %} in {{ trigger.event.data.airport_destination_country_name }}{% endif %}.
        {% elif trigger.event.data.airport_destination_country_name == 'Netherlands' %}
          The plane you hear now is from {{ trigger.event.data.airline }}. It comes from {{ trigger.event.data.airport_origin_city }} in {{ trigger.event.data.airport_origin_country_name }} and is on its way to {{ trigger.event.data.airport_destination_city }}.
        {% else %}
          The plane you hear now is from {{ trigger.event.data.airline }}. It comes from {{ trigger.event.data.airport_origin_city }} in {{ trigger.event.data.airport_origin_country_name }} and is on its way to {{ trigger.event.data.airport_destination_city }} in {{ trigger.event.data.airport_destination_country_name }}.
        {% endif %}
8 Likes

Thank you! This is superb :grinning:

I cleaned up the flights list a bit using Home-Assistant-Lovelace-HTML-Jinja2-Template-card. In case someone’s interested, here’s a screenshot and the card definition:

fr24

  - type: conditional
    conditions:
      - condition: numeric_state
        entity: sensor.flightradar24_current_in_area
        above: 0
    card:
      type: custom:html-template-card
      ignore_line_breaks: true
      content: >-
        {% set data = state_attr('sensor.flightradar24_current_in_area',
        'flights') %} {% for flight in data %}
          <ha-icon icon="mdi:airplane"></ha-icon> {%if flight.airline_short %}{{ flight.airline_short }}{% endif %}{% if flight.flight_number %} {{ flight.flight_number }}{% endif %}{% if flight.airline_short or flight.flight_number %}, {% endif %}{% if flight.aircraft_model %}{{ flight.aircraft_model }}{% endif %}
          <div>{%if flight.airport_origin_city or flight.airport_destination_city %}{%if flight.airport_origin_city %}<div style="display: inline-block; margin-left: 28px;"><img style="vertical-align: middle;" src="https://flagsapi.com/{{ flight.airport_origin_country_code[:2] }}/shiny/16.png" />{% endif %} {{ flight.airport_origin_city }}</div>{%if flight.airport_destination_country_code %}<div style="display: inline-block;">&nbsp;-&nbsp;<img style="vertical-align: middle;" src="https://flagsapi.com/{{ flight.airport_destination_country_code[:2] }}/shiny/16.png" />{% endif %} {{ flight.airport_destination_city }}</div>{% else %}<div style="margin-left: 28px;">No data</div>{% endif %}</div></div>
        {% endfor %}

What I would be super interested in would be the current latitudes and longitudes of the aircrafts so I would be able to draw the flight paths on a map. Hope these get added at some point.

Also, there’s a small issue with the country codes. Some of them are 3 characters long which means flags can’t be loaded from flagapi. I cut the country code to 2 characters to make it somewhat work in my card definition, but there are cases where just taking the last character off shows the wrong flag. Not a major thing, but perhaps something to think about, if it would be possible to map the 3 char country codes to standard 2 char codes in the integration.

1 Like

Hi
The current latitudes and longitudes of the aircrafts would be in the next release :slight_smile:
Would be great if you post how you build flight map visualisation

Thanks for pointing to a BUG. I will look into it, but I can’t promise that it would be in the next release :frowning:

Thanks for sharing. Nice improvement to layout.
@ AlexandrErohin - Appreciate the willingness to add the features. Very nice integration

1 Like

No problem. I’ll post my results when the coordinates are available and after (if) I get it done :smile:

1 Like

v0.1.0 Released

Changelog

  • Added current latitude and longitude of the aircraft
  • Added current altitude of the aircraft (measurement: foot)
  • Added current ground speed of the aircraft (measurement: knots)
  • Added current heading of the aircraft (measurement: degrees)
  • Added German translation by @miggi92
6 Likes

Alright. I played around for quite a while looking for a way to get the aircrafts on a map. I tried many different ways, and finally I made it. But it’s quite a hack. Here’s a picture for proof:

So. I’ll just briefly describe here what I did. I’ll publish the relevant stuff after I polish them up a bit, in case there are other people interested in getting the aircraft on a map too :slight_smile:

First of all. The only way to get entities appearing automatically on the standard map card seems to be a geo location source (Geolocation - Home Assistant). The only one on that list that makes any sense in this scenario, is the generic GeoJSON Events. There is a built in GeoJSON integration in HASS that I checked out. It could be leveraged if there was a source that provided GeoJSON data of airplanes of a very specific area someone would be interested in. I admit that I didn’t much bother searching for one, as this seems like a long shot.

So I started looking on how I could use the data already retrieved by this Flightradar24 integration. The coordinates and other data is there, just not in the correct format for the GeoJSON integration. I was hoping to be able to use Home Assistant’s API directly to get the data and format it inside HASS somehow, but that didn’t work out. The API requires authentication and one can’t query for specific attributes anyway, it’s the whole state of a sensor that is retrieved. Also, the GeoJSON integration does not support any kind of authentication. Also I noticed that the scan interval is not configurable either. It’s hardcoded to 5 minutes which is way too long for something like this.

After some poking around I ended up forking the GeoJSON integration and adding 2 configurable fields there. One for scan interval (10 seconds seems quite good), and another one for access token. Now I could enter the API token from HASS to this field and pass it on to a proxy service that could access the HASS API, format the retrieved data to proper GeoJSON, and return it to my customized GeoJSON integration. I created a very simple Node app hosted in a Docker container for handling the data processing. With all this, I managed to get the data to show on a map card.

If you want to achieve the same, you will need the following:

  • My custom GeoJSON integration forked from the built in HASS GeoJSON integration
  • My Node based proxy service for querying HASS API and formatting the retrieved data
  • A server where you can run the Node app (or a Docker container)

Like I wrote earlier, I will publish the above with guides after I clean them up a bit.

What annoys me very much is how limited the map card and the geo location features seem to be. I can only pass a few properties with the GeoJSON data: An ID, latitude and longitude, and the title. Map card automatically shows the title on the markers when geo location sources are used, there’s no way to customize it. So what I’ve done is put an airplane icon (it’s an UTF-character), and the flight number to the title with my proxy service. On the map it will just show the icon and the first character of the flight code. Clicking on a marker gives you this:

So basically the few fields I already mentioned, and the distance to your selected location as the entity state. I would have wanted to get all the relevant data here, and the marker to show up as just an airplane which I would have rotated with CSS according to the aircraft heading. It’s just not possible. If there was some history of coordinates for each plane (not just the current ones, but a list of coordinates), I could draw the route too if I understand the documentation correctly. But as there’s just the current location, the markers will just move each time a new dataset is retrieved.

Sorry, that turned out to be a longer story than intended. In the end the solution is really hacky, but I wanted it done so that’s that :smiley:

2 Likes

Thanks for the research.
It looks complicated to have a map :frowning:
Is there any needed data that I can add to the integration to make it little simpler?

I managed to squeeze out one level of complexity, as I noticed that integrations can be forced to refresh with a service call. Meaning, we are not tied to the 5 min default value of GeoJSON integration. This means that there’s no need to have a forked version of the GeoJSON integration. Unfortunately there’s no way to get data out of the FR24 integration in the correct format, Home Assistant’s API is very limited. That’s why a proxy service is still needed. I pushed the code to github and wrote a short setup guide if someone wants to try it out: GitHub - jesmak/fr24_proxy: Proxy app to convert data from home-assistant-flightradar24 custom integration to GeoJSON format

So, there’s no data that could be added to make this any simpler, but if it’s possible to get more coordinates of a single aircraft (not just the current location), I should be able to draw the flight path on the map too. Don’t know if it’s possible to get this from FR24, but if it is, that might be something worth doing in the future.

Edit: Scrap that. GeoJSON integration only understands Point types, not LineString types which would have to be used to draw the routes. I might look into putting the data on a Grafana map chart later. This would remove the need for a proxy service and would allow drawing the routes. But, I think I’m done with FR24 for now. I’ll return to this topic later at some point.

1 Like

Very impressive work trying to get the map working.

I have a question on this integration. Is there anything stored that will make the database increase over time?
I’m working through my HA configurations to try and reduce integrations that make significant increases to the DB.
Thanks

1 Like

I’d say yes and no. In my experience when there’s a bunch of aircraft in the area, the dataset is so big that HASS logs will show that the recorded will not store the data due to possible performance issues (I think the limit was 16KB or so). So if you’re in an area that has just the right amount of aircraft around all the time, so that the dataset size remains under 16KB but still big, database size will increase with quite a pace when the polling schedule is in the range of seconds. I hope there’s a way in this integration to restrict the returned flight attributes to a predefined set at some point in the future as I would only need a few, and I too would like to keep the database size in control.