blueprints/automation/medication-reminder.yaml aktualisiert
This commit is contained in:
@@ -4,7 +4,7 @@ blueprint:
|
|||||||
Tracks medication intake via NFC scan.
|
Tracks medication intake via NFC scan.
|
||||||
- If no person is selected, the scanner is assumed to be the taker.
|
- If no person is selected, the scanner is assumed to be the taker.
|
||||||
- If a person is selected manually (e.g. a child without mobile),
|
- If a person is selected manually (e.g. a child without mobile),
|
||||||
the medication schedule resets for them, but the fallback adult gets reminders.
|
the medication schedule resets for them, but the scanner gets the reminder.
|
||||||
- Sends reminders again after a flexible interval (hours or days).
|
- Sends reminders again after a flexible interval (hours or days).
|
||||||
domain: automation
|
domain: automation
|
||||||
input:
|
input:
|
||||||
@@ -34,19 +34,6 @@ blueprint:
|
|||||||
selector:
|
selector:
|
||||||
entity:
|
entity:
|
||||||
domain: input_select
|
domain: input_select
|
||||||
user_id_map:
|
|
||||||
name: User ID → Person Map (JSON)
|
|
||||||
description: |
|
|
||||||
Enter JSON like {"abc123": "dad", "def456": "mom"}
|
|
||||||
selector:
|
|
||||||
text:
|
|
||||||
notify_fallback:
|
|
||||||
name: Fallback Notify Service
|
|
||||||
description: >
|
|
||||||
Select who should be notified if the person has no mobile app (e.g. an adult).
|
|
||||||
selector:
|
|
||||||
entity:
|
|
||||||
domain: notify
|
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
- platform: event
|
- platform: event
|
||||||
@@ -57,15 +44,14 @@ trigger:
|
|||||||
variables:
|
variables:
|
||||||
scanned_user_id: "{{ trigger.context.user_id }}"
|
scanned_user_id: "{{ trigger.context.user_id }}"
|
||||||
manual_person: "{{ states(inputs.person_selector) | lower }}"
|
manual_person: "{{ states(inputs.person_selector) | lower }}"
|
||||||
|
# Determine the "person" whose medication schedule should be reset
|
||||||
person: >
|
person: >
|
||||||
{% set map = inputs.user_id_map | from_json(default={}) %}
|
{% if manual_person != "no selection" %}
|
||||||
{% if scanned_user_id in map %}
|
|
||||||
{{ map[scanned_user_id] | lower }}
|
|
||||||
{% elif manual_person != "no selection" %}
|
|
||||||
{{ manual_person }}
|
{{ manual_person }}
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ integration_entities("person") | select('search', scanned_user_id) | list | first | default("unknown") }}
|
{{ state_attr('user.' ~ scanned_user_id, 'friendly_name') | lower }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
# Calculate the delay in seconds
|
||||||
delay_seconds: >
|
delay_seconds: >
|
||||||
{% if inputs.reminder_unit == 'Days' %}
|
{% if inputs.reminder_unit == 'Days' %}
|
||||||
{{ (inputs.reminder_delay | int) * 86400 }}
|
{{ (inputs.reminder_delay | int) * 86400 }}
|
||||||
@@ -73,13 +59,10 @@ variables:
|
|||||||
{{ (inputs.reminder_delay | int) * 3600 }}
|
{{ (inputs.reminder_delay | int) * 3600 }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
datetime_entity: "input_datetime.medication_{{ person }}"
|
datetime_entity: "input_datetime.medication_{{ person }}"
|
||||||
|
# Determine notification target: always the scanner's device
|
||||||
notify_service: >
|
notify_service: >
|
||||||
{% set candidate = "notify.mobile_app_" ~ person %}
|
{% set scanner_device = "notify.mobile_app_" ~ state_attr('user.' ~ scanned_user_id, 'device_name') | lower %}
|
||||||
{% if candidate in integration_entities("notify") %}
|
{{ scanner_device }}
|
||||||
{{ candidate }}
|
|
||||||
{% else %}
|
|
||||||
{{ inputs.notify_fallback }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
action:
|
action:
|
||||||
- service: input_datetime.set_datetime
|
- service: input_datetime.set_datetime
|
||||||
|
|||||||
Reference in New Issue
Block a user