My job takes me all over the country by train and I need to find my way home a lot by using public transport. The railway in my country has an api i can poll to get the train schedule however they require to put a fixed route in your config.
I was trying to make this dinamic to my location but for this to work i would need to be able to tell the nearest Station to my location. I already have all the stations in my zone.yaml, however i am trying to find how to determine what the nearest “zone” is to my personal location.
all the examples i can find are to find the nearest entity to one particular zone but i need it the other way around.
From this sensor you should be able to get the minimum value with just filter min.
Then do a reverse search to get the zone name from the minimum value.
But at some point, they changed the way zones are expanded. Now it expands to a list of person entities within each zone, so this doesn’t work anymore.
But you could do something along the lines of:
{% set ns = namespace(x=[]) %}
{% for zone in states.zone %}
{% set ns.x = ns.x + [(distance(zone, 'device_tracker.me'), zone.name)] %}
{% endfor %}
{{ (ns.x|sort)[0][1] }}