|
211 | 211 | {% endmacro %} |
212 | 212 |
|
213 | 213 | {# 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 %} |
217 | 217 | {{ name }}: Away |
218 | 218 | {% 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 %} |
222 | 231 | {% 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 %} |
229 | 233 | {% endif %} |
230 | 234 | {% endif %} |
231 | 235 | {% endmacro %} |
|
255 | 259 | [Current date time: {{ month }} {{ day }}, {{ year }} {{ time }}] |
256 | 260 |
|
257 | 261 | [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') }} |
262 | 266 | {% if range(1, 100) | random <= 25 %} |
263 | 267 | Cat Molly: Always home. |
264 | 268 | {% endif %} |
|
0 commit comments