@ -211,21 +211,25 @@
{% endmacro %}
{# friendly duration/location helper #}
{% macro friendly_location( entity _id, name) %}
{% set entity = states[entity _id] %}
{% if not entity %}
{% macro friendly_location( person_id, place_sensor _id, name) %}
{% set p erso n = states[p erso n_id] %}
{% if not p erso n %}
{{ name }} : Away
{% else %}
{% set state = states(entity _id) %}
{% if state == 'unknown' %}
{{ name }} : Away
{% else %}
{% set last_changed = as_timestamp( entity .last_changed) %}
{% set person_ state = states(p erso n_id) %}
{% set place_state = states(place_sensor_id) if place_sensor_id in states else 'unknown' %}
{% set location_label = place_state if place_state not in ['unknown','unavailable','','none'] else person_state %}
{% set location_label = 'Away' if location_label in ['unknown','unavailable','','none'] else location_label %}
{% set last_changed = as_timestamp( p erso n.last_changed) %}
{% set seconds = (as_timestamp(now()) - last_changed) | int(0) if last_changed else 0 %}
{% set hours = (seconds // 3600) | int %}
{% set minutes = ((seconds % 3600) // 60) | int %}
{% set duration = (hours ~ ' hours') if hours >= 1 else (minutes ~ ' minutes') %}
{{ name }} : {{ state }}{% if seconds >= 60 %} for {{ duration }}{% endif %}
{% if person_state == 'driving' %}
{% set driving_label = location_label if location_label != 'Away' else '' %}
{{ name }} : Driving{% if driving_label %} near {{ driving_label }}{% endif %}{% if seconds >= 60 %} for {{ duration }}{% endif %}
{% else %}
{{ name }} : {{ location_label }}{% if seconds >= 60 %} for {{ duration }}{% endif %}
{% endif %}
{% endif %}
{% endmacro %}
@ -255,10 +259,10 @@
[Current date time : {{ month }} {{ day }}, {{ year }} {{ time }}]
[Resident : Location:
- {{ friendly_location(' sensor.carlo_place', 'Carlo') }}
- {{ friendly_location(' sensor.stacey_place', 'Stacey') }}
- {{ friendly_location(' sensor.justin_place', 'Justin') }}
- {{ friendly_location(' sensor.paige_place', 'Paige') }}
- {{ friendly_location(' person.carlo', ' sensor.carlo_place', 'Carlo') }}
- {{ friendly_location(' person.stacey', ' sensor.stacey_place', 'Stacey') }}
- {{ friendly_location(' person.justin', ' sensor.justin_place', 'Justin') }}
- {{ friendly_location(' person.paige', ' sensor.paige_place', 'Paige') }}
{% if range(1, 100) | random <= 25 %}
Cat Molly : Always home.
{% endif %}