blueprints/automation/medication-reminder.yaml aktualisiert
This commit is contained in:
@@ -1,85 +1,96 @@
|
||||
blueprint:
|
||||
name: Dynamic Medication Reminder via NFC
|
||||
name: Medication Reminder via NFC (Companion App Primary)
|
||||
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 scanner gets the reminder.
|
||||
- Sends reminders again after a flexible interval (hours or days).
|
||||
Tracks medication intake. Defaults to the Companion App user who scans the tag.
|
||||
A manual person selection can override this if selected.
|
||||
Creates calendar entries and calculates the next dose time.
|
||||
|
||||
domain: automation
|
||||
|
||||
input:
|
||||
medication_name:
|
||||
name: Medication Name
|
||||
description: The name of the medication.
|
||||
selector:
|
||||
text
|
||||
nfc_tag_id:
|
||||
name: NFC Tag ID
|
||||
medication_tag_id:
|
||||
name: Medication NFC Tag ID
|
||||
description: The unique ID of the NFC tag for this medication.
|
||||
selector:
|
||||
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:
|
||||
name: Reminder Interval
|
||||
description: The number of hours or days for the next reminder.
|
||||
selector:
|
||||
number:
|
||||
min: 1
|
||||
max: 168
|
||||
reminder_unit:
|
||||
name: Time Unit
|
||||
description: The unit of time for the reminder (Hours or Days).
|
||||
selector:
|
||||
select:
|
||||
options:
|
||||
- Hours
|
||||
- Days
|
||||
person_selector:
|
||||
name: Manual person selection
|
||||
selector:
|
||||
entity:
|
||||
domain: input_select
|
||||
|
||||
trigger:
|
||||
- platform: event
|
||||
event_type: tag_scanned
|
||||
|
||||
condition:
|
||||
- condition: template
|
||||
value_template: "{{ trigger.event.data.tag_id == !input nfc_tag_id }}"
|
||||
event_data:
|
||||
tag_id: !input medication_tag_id
|
||||
|
||||
variables:
|
||||
scanned_user_id: "{{ trigger.context.user_id }}"
|
||||
manual_person: "{{ states(!input person_selector) | lower }}"
|
||||
person: >
|
||||
{% if manual_person != "no selection" %}
|
||||
scanned_person: "{{ state_attr('user.' ~ scanned_user_id, 'friendly_name') | default('Unknown User') }}"
|
||||
manual_person: "{{ states(!input person_selector) }}"
|
||||
|
||||
person_name: >
|
||||
{% if manual_person != 'No selection' %}
|
||||
{{ manual_person }}
|
||||
{% else %}
|
||||
{{ state_attr('user.' ~ scanned_user_id, 'friendly_name') | lower }}
|
||||
{{ scanned_person }}
|
||||
{% endif %}
|
||||
|
||||
delay_seconds: >
|
||||
{% if !input reminder_unit == 'Days' %}
|
||||
{{ (!input reminder_delay | int) * 86400 }}
|
||||
{% else %}
|
||||
{{ (!input reminder_delay | int) * 3600 }}
|
||||
{% 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:
|
||||
- service: input_datetime.set_datetime
|
||||
target:
|
||||
entity_id: "{{ datetime_entity }}"
|
||||
data:
|
||||
timestamp: "{{ now().timestamp() }}"
|
||||
- choose:
|
||||
- conditions:
|
||||
- condition: template
|
||||
value_template: "{{ person_name != 'Unknown User' and person_name != 'No selection' }}"
|
||||
sequence:
|
||||
- service: calendar.create_event
|
||||
data:
|
||||
calendar_entity_id: !input calendar_entity_id
|
||||
summary: "{{ !input medication_name }} taken by {{ person_name }}"
|
||||
description: "Next dose due for {{ person_name }} at {{ (now() + timedelta(seconds=delay_seconds)).strftime('%Y-%m-%d %H:%M:%S') }}"
|
||||
start_date_time: "{{ now() }}"
|
||||
end_date_time: "{{ now() }}"
|
||||
- service: input_select.select_option
|
||||
target:
|
||||
entity_id: !input person_selector
|
||||
data:
|
||||
option: "No selection"
|
||||
|
||||
- delay:
|
||||
seconds: "{{ delay_seconds }}"
|
||||
|
||||
- service: "{{ notify_service }}"
|
||||
data:
|
||||
message: "{{ !input medication_name }} is due again for {{ person | title }}."
|
||||
|
||||
- service: input_select.select_option
|
||||
target:
|
||||
entity_id: !input person_selector
|
||||
data:
|
||||
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."
|
||||
Reference in New Issue
Block a user