Custom Component: Flightradar24

Wonderful project. I have two questions:
1: What would be the benefit of including my FR24 subscription information?
2: Is it possible to add a tracked flight based on IATA/ICAO orign and destination, instead of flightnumber?

[Edit]: What I actually would like to do for number 2 is to provide 3 parameters; Airline, Orign and Destination

Any way of fetching the age of a plane on a specfic flight?
Or age of all planes in “sight”?

Can I adjust the ‘area’ with my location? Or is that not possible? Would be a nice feature.

1 Like

I just made the upgrade of Home Assistant to 2025.5.0 on my test system and the integration is not working any more.

Logger: homeassistant.setup
Source: setup.py:344
First occurred: 22:29:13 (1 occurrence)
Last logged: 22:29:13

Setup failed for custom integration 'flightradar24': Unable to import component: cannot import name 'countries' from 'pycountry' (unknown location)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/loader.py", line 993, in async_get_component
    comp = await self.hass.async_add_import_executor_job(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        self._get_component, True
        ^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/concurrent/futures/thread.py", line 59, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 1053, in _get_component
    ComponentProtocol, importlib.import_module(self.pkg_path)
                       ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/loop.py", line 201, in protected_loop_func
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.13/importlib/__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 1026, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/config/custom_components/flightradar24/__init__.py", line 7, in <module>
    from .coordinator import FlightRadar24Coordinator
  File "/config/custom_components/flightradar24/coordinator.py", line 8, in <module>
    from pycountry import countries
ImportError: cannot import name 'countries' from 'pycountry' (unknown location)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 344, in _async_setup_component
    component = await integration.async_get_component()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/loader.py", line 1013, in async_get_component
    self._component_future.result()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/loader.py", line 1005, in async_get_component
    comp = self._get_component()
  File "/usr/src/homeassistant/homeassistant/loader.py", line 1053, in _get_component
    ComponentProtocol, importlib.import_module(self.pkg_path)
                       ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/loop.py", line 201, in protected_loop_func
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.13/importlib/__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 1026, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/config/custom_components/flightradar24/__init__.py", line 7, in <module>
    from .coordinator import FlightRadar24Coordinator
  File "/config/custom_components/flightradar24/coordinator.py", line 8, in <module>
    from pycountry import countries
ImportError: cannot import name 'countries' from 'pycountry' (unknown location)

This error did not occur during the beta phase.
Shall i open an issue?

1 Like

After clean restart the error disappeared. Ignore my post.

I am getting the same error sometimes after a restart of HA. I say sometimes as I need to restart HA to reload the integration and a restart does not always allow the integration to start.

I’ve opened an issue.

This error means that while update HA had not install python module - pycountry. The reason why HA had not install the module not in this integration.

@AlexandrErohin That would explain why only some restarts generate the error!

Hi,

Did you get this to work properly? I am also in NL trying to get the takeoff of the lifeliners in the area. I set different area’s to track take-off and maybe takeoff again and get that on a map with lon-lat. I have identified some of the lifeliner codes:

| Callsign        | Registration | ICAO Hex   | Type            | Base Location       |
| --------------- | ------------ | ---------- | --------------- | ------------------- |
| **Lifeliner 1** | PH-LLN       | **48605B** | Airbus H135 P3  | Amsterdam (VUmc)    | 48605B
| **Lifeliner 2** | PH-DOC       | **48414F** | Airbus H135 P3  | Rotterdam Airport   |
| **Lifeliner 3** | PH-ELP       | **484144** | Airbus H135 T2+ | Volkel AFB          |
| **Lifeliner 4** | PH-ULP       | **48416F** | Airbus H135 T2  | Groningen (Eelde)   |
| **Medic 01**    | PH-TTR       | **484157** | Airbus H135 P3  | Leeuwarden Air Base |

Any pointers to an automation so that I can track the takeoff and possibly plot the route on a map would be great.

Thanks and best regards

This integration is great! Have added this with the other third party card.

Has anyone been able to get an automation that can send TTS to a smart speaker saying something like flight overhead callsign from departing city to destination city

I had see someone was playing with it but not sure they got it to work.

Yes I’ve been playing with that a while ago - need to get back to it and verify it’s still working but the following automation should give you an example of how to:


alias: Flight entered Zone - Notify
description: Aircraft entered watch zone around home so notify
triggers:
  - event_type: flightradar24_entry
    trigger: event
conditions:
  - condition: state
    entity_id: input_boolean.away_mode
    state: "off"
  - condition: state
    entity_id: binary_sensor.do_not_disturb
    state: "off"
  - condition: state
    entity_id: device_tracker.iphone_loz_2
    state: home
  - condition: time
    after: "09:00:00"
    before: "19:00:00"
actions:
  - choose:
      - conditions:
          - condition: not
            conditions:
              - condition: state
                entity_id: media_player.lgoled65b6t
                state: "off"
        sequence:
          - data:
              title: "FlightRadar24:"
              message: "{{ details }}"
            action: notify.lgoled65b6t
  - data:
      tts_platform: google_translate
      volume_level: 0.35
      unjoin_players: true
      message: "{{ details }}"
      chime_path: ding_dong
    target:
      entity_id: media_player.display_bedroom
    action: chime_tts.say
  - data:
      title: HA FlightRadar24
      message: "{{ details }}"
    action: notify.mobile_app_iphonexsmax_loz
variables:
  flight_data: "{{ trigger.get('event', {}).get('data', {}) }}"
  details: >-
    {% set details = ['Flight nearby is'] %} {% if
    flight_data.get('airline_short') not in [None, 'unknown', ''] %}
      {% set details = details + [flight_data.airline_short] %}
    {% endif %} {% if flight_data.get('flight_number') not in [None, 'unknown',
    ''] %}
      {% set details = details + ['Flight ' ~ flight_data.flight_number] %}
    {% endif %} {% if flight_data.get('aircraft_model') not in [None, 'unknown',
    ''] %}
      {% set details = details + [flight_data.aircraft_model.split('-')[0]] %}
    {% endif %} {% if flight_data.get('airport_origin_city') not in [None,
    'unknown', ''] and flight_data.get('airport_destination_city') not in [None,
    'unknown', ''] %}
      {% set details = details + ['travelling from ' ~ flight_data.airport_origin_city ~ ' to ' ~ flight_data.airport_destination_city] %}
    {% endif %} {% if flight_data.get('distance') not in [None, 'unknown', '']
    %}
      {% set details = details + ['It is ' ~ flight_data.distance|round(0, 'floor') ~ ' km away'] %}
    {% endif %} {% if flight_data.get('altitude') not in [None, 'unknown', '']
    %}
      {% set altitude_in_feet = flight_data.altitude %}
      {% set details = details + ['at ' ~ altitude_in_feet|round(0, 'floor') ~ ' feet'] %}
    {% endif %} {% if flight_data.get('heading') not in [None, 'unknown', ''] %}
      {% set compass_directions = ['North', 'North-Northeast', 'Northeast', 'East-Northeast', 'East', 'East-Southeast', 'Southeast', 'South-Southeast', 'South', 'South-Southwest', 'Southwest', 'West-Southwest', 'West', 'West-Northwest', 'Northwest', 'North-Northwest'] %}
      {% set heading_index = ((flight_data.heading | float(0) + 11.25) // 22.5) | int %}
      {% set heading_direction = compass_directions[heading_index % 16] %}
      {% set details = details + ['Heading ' ~ heading_direction] %}
    {% endif %} {{ details | join(', ') }}
mode: single


1 Like

thanks heaps for this! Will modify and test and see how I go.

So far no go for me, pulled out some of the conditions which arent relevant for me

alias: Flight entered Zone - Notify
description: Aircraft entered watch zone around home so notify
triggers:
  - event_type: flightradar24_entry
    trigger: event
conditions: []
actions:
  - data:
      tts_platform: tts.elevenlabs
      message: "{{ details }}"
      chime_path: ding_dong
    action: chime_tts.say
    target:
      device_id: 517070a4e83b6fce6cb5ca292745a214
variables:
  flight_data: "{{ trigger.get('event', {}).get('data', {}) }}"
  details: >-
    {% set details = ['Flight nearby is'] %} {% if
    flight_data.get('airline_short') not in [None, 'unknown', ''] %}
      {% set details = details + [flight_data.airline_short] %}
    {% endif %} {% if flight_data.get('flight_number') not in [None,
    'unknown',''] %}
      {% set details = details + ['Flight ' ~ flight_data.flight_number] %}
    {% endif %} {% if flight_data.get('aircraft_model') not in [None,
    'unknown',''] %}
      {% set details = details + [flight_data.aircraft_model.split('-')[0]] %}
    {% endif %} {% if flight_data.get('airport_origin_city') not in [None,
    'unknown', ''] and flight_data.get('airport_destination_city') not in [None,
    'unknown', ''] %}
      {% set details = details + ['travelling from ' ~ flight_data.airport_origin_city ~ ' to ' ~ flight_data.airport_destination_city] %}
    {% endif %} {% if flight_data.get('distance') not in [None, 'unknown', '']
    %}
      {% set details = details + ['It is ' ~ flight_data.distance|round(0, 'floor') ~ ' km away'] %}
    {% endif %} {% if flight_data.get('altitude') not in [None, 'unknown', '']
    %}
      {% set altitude_in_feet = flight_data.altitude %}
      {% set details = details + ['at ' ~ altitude_in_feet|round(0, 'floor') ~ ' feet'] %}
    {% endif %} {% if flight_data.get('heading') not in [None, 'unknown', ''] %}
      {% set compass_directions = ['North', 'North-Northeast', 'Northeast', 'East-Northeast', 'East', 'East-Southeast', 'Southeast', 'South-Southeast', 'South', 'South-Southwest', 'Southwest', 'West-Southwest', 'West', 'West-Northwest', 'Northwest', 'North-Northwest'] %}
      {% set heading_index = ((flight_data.heading | float(0) + 11.25) // 22.5) | int %}
      {% set heading_direction = compass_directions[heading_index % 16] %}
      {% set details = details + ['Heading ' ~ heading_direction] %}
    {% endif %} {{ details | join(', ') }}
mode: single

So far im only getting the first 3 words “Flight Nearby is” if i run it manually

When it runs itself it seems to error with an unknown error.

Would you be able to please check its still working for you?

No aircraft in area atm (I’m rural :wink:) can confirm if I run manually get same result as you are getting (first theee words only) - probably as message: ‘{{ details }}’ is not populated as no aircraft in area.

Will try tomorrow morning when aircraft in area & see if I can sort it out…

1 Like

thanks yeah I tried it while aircraft in area and still got that. I am semi rural too so not a huge amount of aircraft around atm,

I did have a version crudely working last year (my HA coding was pretty basic) - I’ll see if I can find that too
More recently been using AI to ‘improve’ a number of automations - not sure if it’s AI or me on a steeper learning curve :sweat_smile:. The code I sent you was one of its suggestions from my original code if I recall correctly. It definitely needed more work - I’d put it aside to attend to more pressing HA issues.

I am not great at coding haha, but i usually can scrape by with HA YAML. Would be interesting to try the more simple code too. I have heard AI can do good coding within good parameters haha.

For some reason I dont think I am getting past the event stage, it just tried to trigger with a flight entering but giving me error right at the start

Ok so I copied your simplified version & changed necessary devices to work on my HA and an aircraft just flew over and was announced on my Google display as it should and created a persistent (for debug) message.
Try this once you check a few things I can think of:

  1. Check your flightradar24 entity trigger is same as mine (or select the correct one from yours.
  2. Im using Integration TTS Say for speech - if you are not either modify my code or i can send you a revised draft version using your preferred speech engine.
alias: WIP V2 Flight entered Zone - Notify
description: Aircraft entered watch zone around home so notify
triggers:
  - event_type: flightradar24_entry
    trigger: event
conditions: []
actions:
  - data:
      title: Flight Entered Debug
      message: "{{ details }}"
    action: persistent_notification.create
  - data:
      tts_platform: google_translate
      message: "{{ details }}"
      chime_path: ding_dong
    target:
      entity_id: media_player.display_bedroom
    action: chime_tts.say
variables:
  flight_data: "{{ trigger.event.data if trigger.event.data is defined else {} }}"
  details: |-
    {% set details = [] %}
    {% if not flight_data %}
      {% set details = ['No aircraft detected entering area'] %}
    {% else %}
      {% set details = ['Flight nearby is'] %}

      {% if flight_data.get('airline_short') not in [None, 'unknown', ''] %}
        {% set details = details + [flight_data.airline_short] %}
      {% endif %}

      {% if flight_data.get('flight_number') not in [None, 'unknown', ''] %}
        {% set details = details + ['Flight ' ~ flight_data.flight_number] %}
      {% endif %}

      {% if flight_data.get('aircraft_model') not in [None, 'unknown', ''] %}
        {% set details = details + [flight_data.aircraft_model.split('-')[0]] %}
      {% endif %}

      {% if flight_data.get('airport_origin_city') and flight_data.get('airport_destination_city') %}
        {% set details = details + ['travelling from ' ~ flight_data.airport_origin_city ~ ' to ' ~ flight_data.airport_destination_city] %}
      {% endif %}

      {% if flight_data.get('distance') not in [None, 'unknown', ''] %}
        {% set details = details + ['It is ' ~ flight_data.distance | round(0, 'floor') ~ ' km away'] %}
      {% endif %}

      {% if flight_data.get('altitude') not in [None, 'unknown', ''] %}
        {% set details = details + ['at ' ~ flight_data.altitude | round(0, 'floor') ~ ' feet'] %}
      {% endif %}

      {% if flight_data.get('heading') not in [None, 'unknown', ''] %}
        {% set compass_directions = ['North', 'North-Northeast', 'Northeast', 'East-Northeast', 'East', 'East-Southeast', 'Southeast', 'South-Southeast', 'South', 'South-Southwest', 'Southwest', 'West-Southwest', 'West', 'West-Northwest', 'Northwest', 'North-Northwest'] %}
        {% set heading_index = ((flight_data.heading | float(0) + 11.25) // 22.5) | int %}
        {% set heading_direction = compass_directions[heading_index % 16] %}
        {% set details = details + ['Heading ' ~ heading_direction] %}
      {% endif %}
    {% endif %}
    {{ details | join(', ') }}
mode: single

This (my example) is what is both said and appears as persistent message for debug / verification purposes
“Flight nearby is, Jetstar, Flight JQ494, Airbus A320, travelling from Newcastle to Gold Coast, It is 18 km away, at 18025 feet, Heading North-Northeast”