blueprints/automation/medication-reminder.yaml aktualisiert

This commit is contained in:
2025-08-30 12:10:34 +00:00
parent 458c27f431
commit 5b9fc65864

View File

@@ -1,85 +1,96 @@
blueprint: blueprint:
name: Dynamic Medication Reminder via NFC name: Medication Reminder via NFC (Companion App Primary)
description: > description: >
Tracks medication intake via NFC scan. Tracks medication intake. Defaults to the Companion App user who scans the tag.
- If no person is selected, the scanner is assumed to be the taker. A manual person selection can override this if selected.
- If a person is selected manually (e.g. a child without mobile), Creates calendar entries and calculates the next dose time.
the medication schedule resets for them, but the scanner gets the reminder.
- Sends reminders again after a flexible interval (hours or days).
domain: automation domain: automation
input: input:
medication_name: medication_name:
name: Medication Name name: Medication Name
description: The name of the medication.
selector: selector:
text text
nfc_tag_id: medication_tag_id:
name: NFC Tag ID name: Medication NFC Tag ID
description: The unique ID of the NFC tag for this medication.
selector: selector:
text text
person_selector:
name: Manual Person Selection Helper
description: The input_select helper for manual override.
selector:
entity:
domain: input_select
calendar_entity_id:
name: Medication Calendar
description: The calendar entity to log medication intake.
selector:
entity:
domain: calendar
reminder_delay: reminder_delay:
name: Reminder Interval name: Reminder Interval
description: The number of hours or days for the next reminder.
selector: selector:
number: number:
min: 1 min: 1
max: 168 max: 168
reminder_unit: reminder_unit:
name: Time Unit name: Time Unit
description: The unit of time for the reminder (Hours or Days).
selector: selector:
select: select:
options: options:
- Hours - Hours
- Days - Days
person_selector:
name: Manual person selection
selector:
entity:
domain: input_select
trigger: trigger:
- platform: event - platform: event
event_type: tag_scanned event_type: tag_scanned
event_data:
condition: tag_id: !input medication_tag_id
- condition: template
value_template: "{{ trigger.event.data.tag_id == !input nfc_tag_id }}"
variables: variables:
scanned_user_id: "{{ trigger.context.user_id }}" scanned_user_id: "{{ trigger.context.user_id }}"
manual_person: "{{ states(!input person_selector) | lower }}" scanned_person: "{{ state_attr('user.' ~ scanned_user_id, 'friendly_name') | default('Unknown User') }}"
person: > manual_person: "{{ states(!input person_selector) }}"
{% if manual_person != "no selection" %}
person_name: >
{% if manual_person != 'No selection' %}
{{ manual_person }} {{ manual_person }}
{% else %} {% else %}
{{ state_attr('user.' ~ scanned_user_id, 'friendly_name') | lower }} {{ scanned_person }}
{% endif %} {% endif %}
delay_seconds: > delay_seconds: >
{% if !input reminder_unit == 'Days' %} {% if !input reminder_unit == 'Days' %}
{{ (!input reminder_delay | int) * 86400 }} {{ (!input reminder_delay | int) * 86400 }}
{% else %} {% else %}
{{ (!input reminder_delay | int) * 3600 }} {{ (!input reminder_delay | int) * 3600 }}
{% endif %} {% endif %}
datetime_entity: "input_datetime.medication_{{ person }}"
notify_service: >
{% set device_name = state_attr('user.' ~ scanned_user_id, 'device_name') | default('dad_phone') %}
notify.mobile_app_{{ device_name | lower }}
action: action:
- service: input_datetime.set_datetime - choose:
target: - conditions:
entity_id: "{{ datetime_entity }}" - condition: template
value_template: "{{ person_name != 'Unknown User' and person_name != 'No selection' }}"
sequence:
- service: calendar.create_event
data: data:
timestamp: "{{ now().timestamp() }}" calendar_entity_id: !input calendar_entity_id
summary: "{{ !input medication_name }} taken by {{ person_name }}"
- delay: description: "Next dose due for {{ person_name }} at {{ (now() + timedelta(seconds=delay_seconds)).strftime('%Y-%m-%d %H:%M:%S') }}"
seconds: "{{ delay_seconds }}" start_date_time: "{{ now() }}"
end_date_time: "{{ now() }}"
- service: "{{ notify_service }}"
data:
message: "{{ !input 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"
default:
- service: notify.mobile_app_{{ scanned_person | lower | replace(' ', '_') }}
data:
message: "Could not determine who took the medication. Please ensure your Home Assistant app has permission to identify you or manually select a person first."