Include collision-suffixed entity ids in the morning summary
Duplicate child names get HA registry suffixes (_2); the template now iterates the due sensors (which carry present/child_id/child_name as attributes) and pairs counts by child_id, so suffixed duplicates are listed and the household rollup is excluded by the presence guard.
This commit is contained in:
@@ -49,29 +49,26 @@ actions:
|
||||
title: NestQuest morning summary
|
||||
message: |
|
||||
{%- set ns = namespace(lines=[]) -%}
|
||||
{%- for presence in states.binary_sensor
|
||||
| selectattr('entity_id', 'search', '^binary_sensor\\.nestquest_.*_present_today$')
|
||||
| selectattr('state', 'eq', 'on') -%}
|
||||
{%- set child_id = presence.entity_id.split('.')[1].removeprefix('nestquest_').removesuffix('_present_today') -%}
|
||||
{%- set remaining_values = states.sensor
|
||||
| selectattr('entity_id', 'search', '^sensor\\.nestquest_' ~ child_id ~ '_quests_remaining_today$')
|
||||
| map(attribute='state')
|
||||
| list -%}
|
||||
{%- set due_sensors = states.sensor
|
||||
| selectattr('entity_id', 'search', '^sensor\\.nestquest_' ~ child_id ~ '_quests_due_today$')
|
||||
| list -%}
|
||||
{%- set child_name = due_sensors[0].attributes['child_name'] if due_sensors else (child_id | capitalize) -%}
|
||||
{%- if remaining_values -%}
|
||||
{%- set remaining = remaining_values | first | int -%}
|
||||
{%- if remaining > 0 -%}
|
||||
{%- set line = child_name ~ ' owes ' ~ remaining ~ ' quest(s) today.' -%}
|
||||
{%- for due in states.sensor
|
||||
| selectattr('entity_id', 'search', '^sensor\\.nestquest_.*_quests_due_today(_\\d+)?$') -%}
|
||||
{%- if due.attributes.get('present') -%}
|
||||
{%- set remaining_values = states.sensor
|
||||
| selectattr('entity_id', 'search', '^sensor\\.nestquest_.*_quests_remaining_today(_\\d+)?$')
|
||||
| selectattr('attributes.child_id', 'eq', due.attributes.child_id)
|
||||
| map(attribute='state')
|
||||
| list -%}
|
||||
{%- if remaining_values -%}
|
||||
{%- set remaining = remaining_values | first | int -%}
|
||||
{%- if remaining > 0 -%}
|
||||
{%- set line = due.attributes.child_name ~ ' owes ' ~ remaining ~ ' quest(s) today.' -%}
|
||||
{%- else -%}
|
||||
{%- set line = due.attributes.child_name ~ ' is all clear today (0 quests remaining).' -%}
|
||||
{%- endif -%}
|
||||
{%- else -%}
|
||||
{%- set line = child_name ~ ' is all clear today (0 quests remaining).' -%}
|
||||
{%- set line = due.attributes.child_name ~ "'s quest count is unavailable today." -%}
|
||||
{%- endif -%}
|
||||
{%- else -%}
|
||||
{%- set line = child_name ~ "'s quest count is unavailable today." -%}
|
||||
{%- set ns.lines = ns.lines + [line] -%}
|
||||
{%- endif -%}
|
||||
{%- set ns.lines = ns.lines + [line] -%}
|
||||
{%- endfor -%}
|
||||
{%- if ns.lines -%}
|
||||
{{- ns.lines | join('\n') -}}
|
||||
|
||||
Reference in New Issue
Block a user