blueprints/automation/medication-reminder.yaml aktualisiert

This commit is contained in:
2025-08-29 14:07:47 +00:00
parent 81f2132bd9
commit 43fac944f5

View File

@@ -15,7 +15,7 @@ blueprint:
nfc_tag_id:
name: NFC Tag ID
selector:
text:
text
reminder_delay:
name: Reminder Interval
selector:
@@ -42,30 +42,26 @@ trigger:
condition:
- condition: template
value_template: >
{{ trigger.event.data.tag_id == inputs.nfc_tag_id }}
{{ trigger.event.data.tag_id == !input nfc_tag_id }}
variables:
scanned_user_id: "{{ trigger.context.user_id }}"
manual_person: "{{ states(inputs.person_selector) | lower }}"
# Determine the "person" whose medication schedule should be reset
manual_person: "{{ states(!input person_selector) | lower }}"
person: >
{% if manual_person != "no selection" %}
{{ manual_person }}
{% else %}
{{ 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 }}
{% if !input reminder_unit == 'Days' %}
{{ (!input reminder_delay | int) * 86400 }}
{% else %}
{{ (inputs.reminder_delay | int) * 3600 }}
{{ (!input reminder_delay | int) * 3600 }}
{% endif %}
datetime_entity: "input_datetime.medication_{{ person }}"
# Determine notification target: always the scanner's device
notify_service: >
{% set scanner_device = "notify.mobile_app_" ~ state_attr('user.' ~ scanned_user_id, 'device_name') | lower %}
{% set scanner_device = "notify.mobile_app_" ~ (state_attr('user.' ~ scanned_user_id, 'device_name') | lower | default('unknown')) %}
{{ scanner_device }}
action:
@@ -80,7 +76,7 @@ action:
- service: "{{ notify_service }}"
data:
message: "{{ inputs.medication_name }} is due again for {{ person | title }}."
message: "{{ !input medication_name }} is due again for {{ person | title }}."
- service: input_select.select_option
target: