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
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.
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. 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.
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
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.
Changed device_tracker work! NOW this integration creates device_tracker with static name device_tracker.flightradar24. So you may add a live flight as device_tracker with the flight information to a person in HA. This device_tracker updates when there is a live flight in the additional tracked list. It works ONLY with one live flight from the additional tracked list at a time!
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…