90 lines
4.9 KiB
YAML
90 lines
4.9 KiB
YAML
blueprint:
|
|
name: NestQuest end-of-day report
|
|
description: Sends the parent an end-of-day report on how the day went. It runs
|
|
deliberately BEFORE NestQuest's midnight missed-quest sweep, so it reads the same
|
|
day's data (what is still open at report time, and how much of the day was completed)
|
|
rather than tomorrow-morning's hindsight. Every PRESENT child gets a completion
|
|
line, so the parent always receives the day's summary; children who still owe
|
|
quests get their open count called out on that line, and children who are not
|
|
present today are omitted entirely. A child whose remaining-count sensor is unavailable
|
|
is reported with the completion line only. By default the report is skipped when
|
|
every present child is already done — turn on send-even-when-clear to always get
|
|
the day's completion summary. The notify service is chosen by the household when
|
|
importing this blueprint — NestQuest never hard-codes a personal notify target.
|
|
domain: automation
|
|
input:
|
|
report_time:
|
|
name: Report time
|
|
description: Local time of day the report is sent — deliberately before the
|
|
midnight missed-quest sweep, so the report reads the same day's data.
|
|
default: '20:00'
|
|
selector:
|
|
time: {}
|
|
notify_target:
|
|
name: Notify service
|
|
description: The Home Assistant notify service to call for the report, for example
|
|
notify.mobile_app_your_phone — a placeholder; pick the notify service for
|
|
your own device.
|
|
selector:
|
|
text:
|
|
multiline: false
|
|
multiple: false
|
|
send_report:
|
|
name: Send the report
|
|
description: Turn off to keep the automation installed but skip the notification
|
|
entirely.
|
|
default: true
|
|
selector:
|
|
boolean: {}
|
|
send_even_when_clear:
|
|
name: Send even when clear
|
|
description: Send the report even when every present child has already finished
|
|
their quests today. When off (the default), an all-clear day sends nothing.
|
|
default: false
|
|
selector:
|
|
boolean: {}
|
|
source_url: https://github.com/Maniacs-Mansion/NestQuest/blob/main/custom_components/nestquest/blueprints/automation/end_of_day_report.yaml
|
|
mode: single
|
|
variables:
|
|
send_report: !input send_report
|
|
send_even_when_clear: !input send_even_when_clear
|
|
triggers:
|
|
- trigger: time
|
|
at: !input report_time
|
|
conditions:
|
|
- condition: template
|
|
value_template: '{{ send_report | bool }}'
|
|
- condition: template
|
|
value_template: "{%- set ns = namespace(any_open=false) -%}\n{%- for due in states.sensor\n
|
|
\ | selectattr('entity_id', 'search', '^sensor\\\\.nestquest_.*_quests_due_today(_\\\\d+)?$')
|
|
-%}\n {%- if due.attributes.get('present') -%}\n {%- set remaining_values
|
|
= states.sensor\n | selectattr('entity_id', 'search', '^sensor\\\\.nestquest_.*_quests_remaining_today(_\\\\d+)?$')\n
|
|
\ | selectattr('attributes.child_id', 'eq', due.attributes.child_id)\n
|
|
\ | map(attribute='state')\n | list -%}\n {%- if not remaining_values
|
|
or (remaining_values | first | int(-1)) != 0 -%}\n {%- set ns.any_open =
|
|
true -%}\n {%- endif -%}\n {%- endif -%}\n{%- endfor -%}\n{{- send_even_when_clear
|
|
| bool or ns.any_open -}}\n"
|
|
actions:
|
|
- action: !input notify_target
|
|
data:
|
|
title: NestQuest end-of-day report
|
|
message: "{%- set ns = namespace(lines=[]) -%}\n{%- for due in states.sensor\n
|
|
\ | selectattr('entity_id', 'search', '^sensor\\\\.nestquest_.*_quests_due_today(_\\\\d+)?$')
|
|
-%}\n {%- if due.attributes.get('present') -%}\n {%- set due_count = due.state
|
|
| int -%}\n {%- set completed_values = states.sensor\n | selectattr('entity_id',
|
|
'search', '^sensor\\\\.nestquest_.*_quests_completed_today(_\\\\d+)?$')\n |
|
|
selectattr('attributes.child_id', 'eq', due.attributes.child_id)\n |
|
|
map(attribute='state')\n | list -%}\n {%- set remaining_values =
|
|
states.sensor\n | selectattr('entity_id', 'search', '^sensor\\\\.nestquest_.*_quests_remaining_today(_\\\\d+)?$')\n
|
|
\ | selectattr('attributes.child_id', 'eq', due.attributes.child_id)\n
|
|
\ | map(attribute='state')\n | list -%}\n {%- set completed_count
|
|
= (completed_values | first | int) if completed_values else 0 -%}\n {%- set
|
|
remaining_count = (remaining_values | first | int) if remaining_values else
|
|
none -%}\n {%- if remaining_count is not none and remaining_count > 0 -%}\n
|
|
\ {%- set line = due.attributes.child_name ~ ': ' ~ remaining_count ~ '
|
|
still open (' ~ completed_count ~ '/' ~ due_count ~ ' done).' -%}\n {%- else
|
|
-%}\n {%- set line = due.attributes.child_name ~ ': ' ~ completed_count
|
|
~ '/' ~ due_count ~ ' done.' -%}\n {%- endif -%}\n {%- set ns.lines =
|
|
ns.lines + [line] -%}\n {%- endif -%}\n{%- endfor -%}\n{{- ns.lines | join('\\n')
|
|
-}}"
|