blueprints/automation/medication-reminder.yaml aktualisiert
This commit is contained in:
@@ -1,6 +1,11 @@
|
|||||||
blueprint:
|
blueprint:
|
||||||
name: Dynamic Medication Reminder via NFC
|
name: Dynamic Medication Reminder via NFC
|
||||||
description: Tracks medication intake via NFC scan, auto-detects user or uses manual selection, and sends reminders after a flexible interval.
|
description: >
|
||||||
|
Tracks medication intake via NFC scan.
|
||||||
|
- 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),
|
||||||
|
the medication schedule resets for them, but the fallback adult gets reminders.
|
||||||
|
- Sends reminders again after a flexible interval (hours or days).
|
||||||
domain: automation
|
domain: automation
|
||||||
input:
|
input:
|
||||||
medication_name:
|
medication_name:
|
||||||
@@ -30,9 +35,17 @@ blueprint:
|
|||||||
entity:
|
entity:
|
||||||
domain: input_select
|
domain: input_select
|
||||||
user_id_map:
|
user_id_map:
|
||||||
name: User ID to Person Name Map
|
name: User ID → Person Map (JSON)
|
||||||
|
description: Enter JSON like {"abc123": "dad", "def456": "mom"}
|
||||||
selector:
|
selector:
|
||||||
object:
|
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
|
||||||
@@ -42,22 +55,30 @@ trigger:
|
|||||||
|
|
||||||
variables:
|
variables:
|
||||||
scanned_user_id: "{{ trigger.context.user_id }}"
|
scanned_user_id: "{{ trigger.context.user_id }}"
|
||||||
selected_person: "{{ states(!input.person_selector) | lower }}"
|
manual_person: "{{ states(inputs.person_selector) | lower }}"
|
||||||
person: >
|
person: >
|
||||||
{% set map = !input.user_id_map %}
|
{% set map = inputs.user_id_map | from_json(default={}) %}
|
||||||
{% if scanned_user_id in map %}
|
{% if scanned_user_id in map %}
|
||||||
{{ map[scanned_user_id] | lower }}
|
{{ map[scanned_user_id] | lower }}
|
||||||
|
{% elif manual_person != "no selection" %}
|
||||||
|
{{ manual_person }}
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ selected_person }}
|
{{ integration_entities("person") | select('search', scanned_user_id) | list | first | default("unknown") }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
delay_seconds: >
|
delay_seconds: >
|
||||||
{% if !input.reminder_unit == 'Days' %}
|
{% if inputs.reminder_unit == 'Days' %}
|
||||||
{{ ( !input.reminder_delay | int ) * 86400 }}
|
{{ (inputs.reminder_delay | int) * 86400 }}
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ ( !input.reminder_delay | int ) * 3600 }}
|
{{ (inputs.reminder_delay | int) * 3600 }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
datetime_entity: "input_datetime.medication_{{ person }}"
|
datetime_entity: "input_datetime.medication_{{ person }}"
|
||||||
notify_service: "notify.mobile_app_{{ person }}"
|
notify_service: >
|
||||||
|
{% set candidate = "notify.mobile_app_" ~ person %}
|
||||||
|
{% if candidate in integration_entities("notify") %}
|
||||||
|
{{ candidate }}
|
||||||
|
{% else %}
|
||||||
|
{{ inputs.notify_fallback }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
action:
|
action:
|
||||||
- service: input_datetime.set_datetime
|
- service: input_datetime.set_datetime
|
||||||
@@ -65,13 +86,16 @@ action:
|
|||||||
entity_id: "{{ datetime_entity }}"
|
entity_id: "{{ datetime_entity }}"
|
||||||
data:
|
data:
|
||||||
timestamp: "{{ now().timestamp() }}"
|
timestamp: "{{ now().timestamp() }}"
|
||||||
|
|
||||||
- delay:
|
- delay:
|
||||||
seconds: "{{ delay_seconds }}"
|
seconds: "{{ delay_seconds }}"
|
||||||
|
|
||||||
- service: "{{ notify_service }}"
|
- service: "{{ notify_service }}"
|
||||||
data:
|
data:
|
||||||
message: "{{ !input.medication_name }} is due again for {{ person | title }}."
|
message: "{{ inputs.medication_name }} is due again for {{ person | title }}."
|
||||||
|
|
||||||
- service: input_select.select_option
|
- service: input_select.select_option
|
||||||
target:
|
target:
|
||||||
entity_id: !input.person_selector
|
entity_id: !input person_selector
|
||||||
data:
|
data:
|
||||||
option: "No selection"
|
option: "No selection"
|
||||||
|
|||||||
Reference in New Issue
Block a user