blueprint: name: Dynamic Medication Reminder via NFC 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: name: Medication Name selector: text: nfc_tag_id: name: NFC Tag ID selector: text: reminder_delay: name: Reminder Interval selector: number: min: 1 max: 168 reminder_unit: name: Time Unit selector: select: options: - Hours - Days person_selector: name: input_select for manual person selection 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 event_type: tag_scanned event_data: tag_id: !input nfc_tag_id variables: scanned_user_id: "{{ trigger.context.user_id }}" manual_person: "{{ states(inputs.person_selector) | lower }}" 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" %} {{ manual_person }} {% else %} {{ integration_entities("person") | select('search', scanned_user_id) | list | first | default("unknown") }} {% endif %} delay_seconds: > {% if inputs.reminder_unit == 'Days' %} {{ (inputs.reminder_delay | int) * 86400 }} {% else %} {{ (inputs.reminder_delay | int) * 3600 }} {% endif %} datetime_entity: "input_datetime.medication_{{ 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 target: entity_id: "{{ datetime_entity }}" data: timestamp: "{{ now().timestamp() }}" - delay: seconds: "{{ delay_seconds }}" - service: "{{ notify_service }}" data: message: "{{ inputs.medication_name }} is due again for {{ person | title }}." - service: input_select.select_option target: entity_id: !input person_selector data: option: "No selection"