Custom Component: Flightradar24

Here’s the intent script I wrote for my own install (as a tool for the LLM to use) you should be able to adapt the math:

  bearing_to_target:
    description: >
      "Returns the distance (in meters) and bearing from zone.home to a target location's GPS coordinates.
       Test Target, SAT - San Antonio International Airport...
       example: >
        ```json
          {
          'lat': '29.522664576',
          'lon': '-98.469831454'
          }
        ```"
    parameters:
      lat: # the latitude you want to query example: '29.522664576'
      lon: # the longitude you want to query example: '-98.469831454'
    action: []
    speech:
      text: >
        {%-if (lat == '') or (lon == '')  -%}
        ERROR: {% if lat == '' -%}Latitude{%- else %}Longitude{%- endif %} is missing
        {%-else -%}
        {%- set current_lat = state_attr('zone.home', 'latitude') | float -%}
        {%- set current_lon =  state_attr('zone.home', 'longitude') | float -%}
        {%- set target_lat =  lat | float -%}
        {%- set target_lon =  lon | float -%}
        {%- set rad = 0.017453292519943295 -%}
        {%- set current_lat_rad= (current_lat * rad) | float -%}
        {%- set current_lon_rad= (current_lon * rad) | float -%}
        {%- set target_lat_rad= (target_lat * rad) | float -%}
        {%- set target_lon_rad= (target_lon * rad) | float -%}
        {%- set delta_lat = (target_lat_rad - current_lat_rad) | float -%}
        {%- set delta_lon= (target_lon_rad - current_lon_rad) | float -%}
        {%- set half_delta_lat = (delta_lat / 2.0) | float -%}
        {%- set half_delta_lon = (delta_lon / 2.0) | float -%}
        {%- set sin_half_delta_lat = half_delta_lat | float | sin -%}
        {%- set sin_half_delta_lon = half_delta_lon | float | sin  -%}
        {%- set a = ((sin_half_delta_lat ** 2) + (cos(current_lat_rad) *
                    cos(target_lat_rad) * (sin_half_delta_lon ** 2))) | float -%}
        {%- set c = (2.0 * atan2(sqrt(a), sqrt(1.0 - a))) | float -%}
        {%- set dist = (6371000.0 * c) | round(1) -%}
        {%- set y = (sin(delta_lon) | float) * (cos(target_lat_rad) | float) -%}
        {%- set x = ( (cos(current_lat_rad) | float) * (sin(target_lat_rad) | float) -
                      (sin(current_lat_rad) | float) * (cos(target_lat_rad) | float) *
                      (cos(delta_lon) | float)) | float -%}
        {%- set initial_bearing = ((atan2(y, x) * 57.2957795) + 360.0) % 360.0 | round(1) -%}
        target:{'distance': {{dist}}, bearing: {{initial_bearing |round(2)}},}
        {%-endif -%}

Put in Lat Long, machine go brrrr, out comes approximate bearing and distance to target. Uses the lat/lon of zone home for basis of calc for origin… (where you are)

You may need to add custom names into your custom sentences / lists if you want to use it directly. As-is no warranty :wink:


edit:
First if my math is wrong navigators - lmk… :slight_smile: Open to correction and this was from memory and some strategic searching.
If you need info about editing the lists in custom sentences:
Friday’s Party: Creating a Private, Agentic AI using Voice Assistant tools - Configuration / Voice Assistant - Home Assistant Community

4 Likes

This part was inserting a complication that I don’t know how to account for since the distance between longitude lines changes depending on your distance from the equator. I wouldn’t know how to calculate that distance for the given map location.

1 Like

I have an experimental version of this where I expose both sets of gps coords to the llm, second set being optional and assumes home if not provided. It SEEMs reliable… Haven’t tested enough outside the northern hemisphere. I started writing it because I hot tired of ‘Friday’ giving me directions to Boston by car every time I asked… How far is it to Boston. (Now I just need to get her to realize that in context although nobody chooses Logan on purpose, if I happen to have it’s go’s coords, it’s ‘close enough’ for me tk estimate distance from here to Boston is roughly here to Logan. Do that. But this risks spinning the conversation off in a different angle. :wink: I have a thread for that. We’ll be discussing air traffic there soon because of you guys.

@aaroneisele55 's idea for FlightRadar24 integration to calculate the direction to look for a plane would be a cool feature even if complicated. I like it.

1 Like

As more people wants to use device tracker from this integration as person device tracker - so Im thinking to change device tracker work.
Now for every flight from additional flight track list may be created separate device tracker. So every time device tracker name is different and it is difficult to add this device tracker to a person.
So there is a way to use only one device tracker for the integration and allow only one live flight track. So every time when a flight becomes live - device tracker with static name updates. It wont work if in the additional tracked list would be 2 live flights simultaneously

What do you think?

additional track should work for any flight that can be found by flightradar24 search field in the right top of the flightradar24 site

Is this working still for you all?

I’m not able to display the embedded map anymore due to FR24 servers returning the x-frame-options header with value ‘sameorigin’ now a days.

Refused to display 'https://www.flightradar24.com/' in a frame because it set 'X-Frame-Options' to 'sameorigin'.

it has stopped working for me also, with a 403 forbidden error for https://data-live.flightradar24.com/clickhandler/

Some users may get 403 responses. Please look this discussion API seems to have stopped working · Issue #88 · JeanExtreme002/FlightRadarAPI · GitHub

Nope stopped for me, but while using vpn it works… so i have been blocked… rip

Others say its a ddos …

// update
Right now i can access the url within my local, but on the integration it still doesn’t work
https://www.flightradar24.com/flights/most-tracked


https://data-live.flightradar24.com/clickhandler/?flight=395ed85a

Logger: custom_components.flightradar24
Source: custom_components/flightradar24/coordinator.py:144
integration: Flightradar24 ([documentation](https://github.com/AlexandrErohin/home-assistant-flightradar24), [issues](https://github.com/AlexandrErohin/home-assistant-flightradar24/issues))
First occurred: 06:23:44 (4 occurrences)
Last logged: 06:25:14

* 403 Client Error: Forbidden for url: https://www.flightradar24.com/flights/most-tracked
* 403 Client Error: Forbidden for url: https://data-live.flightradar24.com/clickhandler/?flight=395ed85a

thank you for this. Based on that link which points to FlightRadar’s support center, they are under a DDoS attack since Tuesday, so these 403 responses are propably part of their countermeasures.

2 Likes

Some users say it become working

1 Like

for me its working since last night. 7h ago

v1.24.0 Released

Changelog

2 Likes

Hey, if you see that Boeing is one shelf higher than the others, and it also doesn’t have a blue color, can you fix it? Thank you.

looks like that flight doesn’t have all the data the card is looking for (coming from the Flightradar24 API so not an error)…there seems to be no Airline, Flight No, Original or Destination based on your screenshot, so the card is not wrong just showing the missing data as blank…

1 Like

v1.25.0 Released

Changelog

Thanks for this release,
actually i have a question

would it be possible to include (aircraft_category) ?
Right now its not yet supported.

Thanks in advance and have a wonderful day

@malosaa Unfortunately, there is no aircraft_category in flightradar24 api response

v1.25.2 Released

Changelog