Skip to content

Commit 61bbe53

Browse files
committed
Enhance friendly location macro to support person and place sensor IDs, improving location reporting in speech briefings. Updated references in the briefing template accordingly.
1 parent f08be9f commit 61bbe53

1 file changed

Lines changed: 20 additions & 16 deletions

File tree

config/templates/speech/briefing.yaml

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -211,21 +211,25 @@
211211
{% endmacro %}
212212

213213
{# friendly duration/location helper #}
214-
{% macro friendly_location(entity_id, name) %}
215-
{% set entity = states[entity_id] %}
216-
{% if not entity %}
214+
{% macro friendly_location(person_id, place_sensor_id, name) %}
215+
{% set person = states[person_id] %}
216+
{% if not person %}
217217
{{ name }}: Away
218218
{% else %}
219-
{% set state = states(entity_id) %}
220-
{% if state == 'unknown' %}
221-
{{ name }}: Away
219+
{% set person_state = states(person_id) %}
220+
{% set place_state = states(place_sensor_id) if place_sensor_id in states else 'unknown' %}
221+
{% set location_label = place_state if place_state not in ['unknown','unavailable','','none'] else person_state %}
222+
{% set location_label = 'Away' if location_label in ['unknown','unavailable','','none'] else location_label %}
223+
{% set last_changed = as_timestamp(person.last_changed) %}
224+
{% set seconds = (as_timestamp(now()) - last_changed) | int(0) if last_changed else 0 %}
225+
{% set hours = (seconds // 3600) | int %}
226+
{% set minutes = ((seconds % 3600) // 60) | int %}
227+
{% set duration = (hours ~ ' hours') if hours >= 1 else (minutes ~ ' minutes') %}
228+
{% if person_state == 'driving' %}
229+
{% set driving_label = location_label if location_label != 'Away' else '' %}
230+
{{ name }}: Driving{% if driving_label %} near {{ driving_label }}{% endif %}{% if seconds >= 60 %} for {{ duration }}{% endif %}
222231
{% else %}
223-
{% set last_changed = as_timestamp(entity.last_changed) %}
224-
{% set seconds = (as_timestamp(now()) - last_changed) | int(0) if last_changed else 0 %}
225-
{% set hours = (seconds // 3600) | int %}
226-
{% set minutes = ((seconds % 3600) // 60) | int %}
227-
{% set duration = (hours ~ ' hours') if hours >= 1 else (minutes ~ ' minutes') %}
228-
{{ name }}: {{ state }}{% if seconds >= 60 %} for {{ duration }}{% endif %}
232+
{{ name }}: {{ location_label }}{% if seconds >= 60 %} for {{ duration }}{% endif %}
229233
{% endif %}
230234
{% endif %}
231235
{% endmacro %}
@@ -255,10 +259,10 @@
255259
[Current date time: {{ month }} {{ day }}, {{ year }} {{ time }}]
256260

257261
[Resident: Location:
258-
- {{ friendly_location('sensor.carlo_place', 'Carlo') }}
259-
- {{ friendly_location('sensor.stacey_place', 'Stacey') }}
260-
- {{ friendly_location('sensor.justin_place', 'Justin') }}
261-
- {{ friendly_location('sensor.paige_place', 'Paige') }}
262+
- {{ friendly_location('person.carlo', 'sensor.carlo_place', 'Carlo') }}
263+
- {{ friendly_location('person.stacey', 'sensor.stacey_place', 'Stacey') }}
264+
- {{ friendly_location('person.justin', 'sensor.justin_place', 'Justin') }}
265+
- {{ friendly_location('person.paige', 'sensor.paige_place', 'Paige') }}
262266
{% if range(1, 100) | random <= 25 %}
263267
Cat Molly: Always home.
264268
{% endif %}

0 commit comments

Comments
 (0)