From 284531abc3d60b70757c8f2f699997269e2c8094 Mon Sep 17 00:00:00 2001 From: thomas Date: Fri, 29 Aug 2025 13:51:40 +0000 Subject: [PATCH] blueprints/automation/medication-reminder.yaml aktualisiert --- .../automation/medication-reminder.yaml | 33 +++++-------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/blueprints/automation/medication-reminder.yaml b/blueprints/automation/medication-reminder.yaml index 6ed90c4..801772d 100644 --- a/blueprints/automation/medication-reminder.yaml +++ b/blueprints/automation/medication-reminder.yaml @@ -4,7 +4,7 @@ blueprint: 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. + the medication schedule resets for them, but the scanner gets the reminder. - Sends reminders again after a flexible interval (hours or days). domain: automation input: @@ -34,19 +34,6 @@ blueprint: selector: entity: 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: - platform: event @@ -57,15 +44,14 @@ trigger: variables: scanned_user_id: "{{ trigger.context.user_id }}" manual_person: "{{ states(inputs.person_selector) | lower }}" + # Determine the "person" whose medication schedule should be reset person: > - {% 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" %} + {% if manual_person != "no selection" %} {{ manual_person }} {% else %} - {{ integration_entities("person") | select('search', scanned_user_id) | list | first | default("unknown") }} + {{ state_attr('user.' ~ scanned_user_id, 'friendly_name') | lower }} {% endif %} + # Calculate the delay in seconds delay_seconds: > {% if inputs.reminder_unit == 'Days' %} {{ (inputs.reminder_delay | int) * 86400 }} @@ -73,13 +59,10 @@ variables: {{ (inputs.reminder_delay | int) * 3600 }} {% endif %} datetime_entity: "input_datetime.medication_{{ person }}" + # Determine notification target: always the scanner's device notify_service: > - {% set candidate = "notify.mobile_app_" ~ person %} - {% if candidate in integration_entities("notify") %} - {{ candidate }} - {% else %} - {{ inputs.notify_fallback }} - {% endif %} + {% set scanner_device = "notify.mobile_app_" ~ state_attr('user.' ~ scanned_user_id, 'device_name') | lower %} + {{ scanner_device }} action: - service: input_datetime.set_datetime