I was playing with distances yesterday and came up with a couple that some folks might find useful. Thought I’d put them here for y’all.
The first one is distance between all zones and persons in the setup.
type: markdown
title: Distance From Zone to Person
content: |
{% set ns = namespace(table_format='', table_line='') -%}
{%- set ns.table_format = "|---" -%}
{%- set ns.table_line = "| Zone" -%}
{%- for person in integration_entities("person") -%}
{%- set ns.table_format = ns.table_format + "|---:" -%}
{%- set ns.table_line = ns.table_line + "| " + state_attr(person, 'friendly_name').split(' ')[0] -%}
{%- endfor %}
{{ ns.table_line }}
{{ ns.table_format }}
{%- for zone in integration_entities("zone") | sort() -%}
{%- set ns.table_line = "| " + state_attr(zone, 'friendly_name') -%}
{%- for person in integration_entities("person") -%}
{%- set ns.table_line = ns.table_line + " | " + ("<ha-icon icon='mdi:map-marker'></ha-icon> " if states(person) | lower() == zone | replace('zone.', '') else distance(zone, person) | round(1) | string + ' mi') -%}
{%- endfor %}
{{ ns.table_line }}
{%- endfor %}
This one looks like:
Yes, me, my wife, and my truck are my persons.
And, the second is distance between all zones in a setup.
type: markdown
title: Distance From Zone to Zone
content: |
{% set ns = namespace(table_format='', table_line='') -%}
{%- set ns.table_format = "|:---:" -%}
{%- set ns.table_line = "| " -%}
{%- for zone in integration_entities("zone") | sort() -%}
{%- set ns.table_format = ns.table_format + "|:---:" -%}
{%- set ns.table_line = ns.table_line + "| " + state_attr(zone, 'friendly_name') | replace(' ', '<br>') -%}
{%- endfor %}
{{ ns.table_line }}
{{ ns.table_format }}
{%- for zone1 in integration_entities("zone") | sort() -%}
{%- set ns.table_line = "| <b>" + state_attr(zone1, 'friendly_name') | replace(' ', '<br>') + '</b>' -%}
{%- for zone2 in integration_entities("zone") | sort() -%}
{%- set ns.table_line = ns.table_line + " | " + ("-" if zone1 == zone2 else distance(zone1, zone2) | round(1) | string) -%}
{%- endfor %}
{{ ns.table_line }}
{%- endfor %}
And, the output:
I hope someone can use these or use the ideas in these.