blueprint: name: Medication Reminder via NFC (Companion App Primary) description: > 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 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 trigger: - platform: event event_type: tag_scanned event_data: tag_id: !input medication_tag_id variables: scanned_user_id: "{{ trigger.context.user_id }}" 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 %} {{ scanned_person }} {% endif %} delay_seconds: > {% if !input reminder_unit == 'Days' %} {{ (!input reminder_delay | int) * 86400 }} {% else %} {{ (!input reminder_delay | int) * 3600 }} {% endif %} action: - 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" 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."