diff --git a/blueprints/automation/medication-reminder.yaml b/blueprints/automation/medication-reminder.yaml index 81030a1..3184e75 100644 --- a/blueprints/automation/medication-reminder.yaml +++ b/blueprints/automation/medication-reminder.yaml @@ -1,6 +1,11 @@ blueprint: 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 input: medication_name: @@ -30,9 +35,17 @@ blueprint: entity: domain: input_select 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: - 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: - platform: event @@ -42,22 +55,30 @@ trigger: variables: scanned_user_id: "{{ trigger.context.user_id }}" - selected_person: "{{ states(!input.person_selector) | lower }}" + manual_person: "{{ states(inputs.person_selector) | lower }}" person: > - {% set map = !input.user_id_map %} + {% set map = inputs.user_id_map | from_json(default={}) %} {% if scanned_user_id in map %} {{ map[scanned_user_id] | lower }} + {% elif manual_person != "no selection" %} + {{ manual_person }} {% else %} - {{ selected_person }} + {{ integration_entities("person") | select('search', scanned_user_id) | list | first | default("unknown") }} {% endif %} delay_seconds: > - {% if !input.reminder_unit == 'Days' %} - {{ ( !input.reminder_delay | int ) * 86400 }} + {% if inputs.reminder_unit == 'Days' %} + {{ (inputs.reminder_delay | int) * 86400 }} {% else %} - {{ ( !input.reminder_delay | int ) * 3600 }} + {{ (inputs.reminder_delay | int) * 3600 }} {% endif %} 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: - service: input_datetime.set_datetime @@ -65,13 +86,16 @@ action: entity_id: "{{ datetime_entity }}" data: timestamp: "{{ now().timestamp() }}" + - delay: seconds: "{{ delay_seconds }}" + - service: "{{ notify_service }}" 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 target: - entity_id: !input.person_selector + entity_id: !input person_selector data: option: "No selection"