Advanced medication reminder

type: custom:stack-in-card
cards:
  - type: horizontal-stack
    cards:
      - type: custom:mushroom-template-card
        entity: sensor.morning_medication_elapsed_time
        primary: Morning Medication
        secondary: |
          {{ states('sensor.morning_medication_elapsed_time') }} ago
        icon: mdi:pill-multiple
        icon_color: '#f7c242'
        tap_action:
          action: more-info
        layout: vertical
        fill_container: false
        multiline_secondary: false
      - type: custom:mushroom-template-card
        entity: sensor.evening_medication_elapsed_time
        primary: Evening Medication
        secondary: |
          {{ states('sensor.evening_medication_elapsed_time') }} ago
        icon: mdi:pill-multiple
        icon_color: '#79b74a'
        tap_action:
          action: more-info
        layout: vertical
        fill_container: false
        multiline_secondary: false
    style: |
      ha-card {
        background: none;
        box-shadow: none;
      }
  - type: horizontal-stack
    cards:
      - type: custom:mushroom-chips-card
        chips:
          - type: template
            tap_action:
              action: none;
            hold_action:
              action: call-service
              service: automation.trigger
              data:
                skip_condition: true
              target:
                entity_id: automation.automation_62
            icon: mdi:refresh
            icon_color: red
            content: Log Medication
        alignment: center
        card_mod:
          style: |
            ha-card {

              /* Style Chip like Mushroom button */
              --chip-background: rgba(255, 215, 0, 0.2);
              --chip-border-radius: var(--mush-control-border-radius, 12px);
              --chip-height: var(--mush-control-height, 42px);
              --chip-box-shadow: none;
              user-select: none;
            }
            ha-card:active {

              /* Add effect to give feedback on button press */
              --chip-background: rgba(var(--rgb-red), 0.4);
            }
      - type: custom:mushroom-chips-card
        chips:
          - type: template
            tap_action:
              action: none;
            hold_action:
              action: call-service
              service: automation.trigger
              data:
                skip_condition: true
              target:
                entity_id: automation.log_evening_medications_updated
            icon: mdi:refresh
            icon_color: red
            content: Log Medication
        alignment: center
        card_mod:
          style: |
            ha-card {

              /* Style Chip like Mushroom button */
              --chip-background: rgba(0, 128, 0, 0.2);
              --chip-border-radius: var(--mush-control-border-radius, 12px);
              --chip-height: var(--mush-control-height, 42px);
              --chip-box-shadow: none;
              user-select: none;
            }
            ha-card:active {

              /* Add effect to give feedback on button press */
              --chip-background: rgba(var(--rgb-red), 0.4);
            }
  - type: custom:canary-card
    theme: midnight
    style: |
      ha-card {
        font-variant: small-caps;
      }
      .card-header {
        font-size: 16px;
      }
    card:
      type: entities
      entities:
        - type: custom:fold-entity-row
          head:
            type: section
            label: Stock Management
          entities:
            - type: divider
            - entity: counter.med_1_refill
              icon: mdi:alpha-t-circle
              show_state: false
              type: custom:multiple-entity-row
              name: Med 1
              entities:
                - entity: counter.med_1_refill
                  name: Pills Left
                  format: precision0
                  styles:
                    font-weight: bold
            - type: divider
            - entity: counter.med_2_refill
              icon: mdi:alpha-v-circle
              show_state: false
              type: custom:multiple-entity-row
              name: Med 2
              entities:
                - entity: counter.med_2_refill
                  name: Pills Left
                  format: precision0
                  styles:
                    font-weight: bold
            - type: divider
            - entity: counter.med_3_refill
              icon: mdi:alpha-b-circle
              show_state: false
              type: custom:multiple-entity-row
              name: Med 3
              entities:
                - entity: counter.med_3_refill
                  name: Pills Left
                  format: precision0
                  styles:
                    font-weight: bold
            - type: divider
            - entity: counter.med_4_refill
              icon: mdi:alpha-s-circle
              show_state: false
              type: custom:multiple-entity-row
              name: Med 4
              entities:
                - entity: counter.med_4_refill
                  name: Pills Left
                  format: precision0
                  styles:
                    font-weight: bold
            - type: divider
      style: |
        ha-card {
          background: none;
          box-shadow: none;
        }

1 Like

excellent. Thanks. Got my counters set up and working - now to prettify it. First go at mushroom-cards. look nice.

1 Like

How would I adapt this if it’s a month medication for a pet???

I combined those 2 into one (removed ios vs android dependency)

Add new variable and new if the feedback loop:

  phone: "{{ device_attr(device, 'manufacturer')}}"
    - if:
        - condition: template
          value_template: "{{ phone == 'Apple'}}"
      then:
        - wait_for_trigger:
            platform: event
            event_type: ios.notification_action_fired
            event_data: {}
          timeout:
            minutes: !input ask_later_wait_time
      else:      
        - wait_for_trigger:
            platform: event
            event_type: mobile_app_notification_action
            event_data:
              tag: !input input_boolean
          timeout:
            minutes: !input ask_later_wait_time
1 Like

Trying to get the blueprint working for multiple days. Happy to code in if too difficult to get a selector. When I use the following suggestion:

trigger:
...

condition:
   - condition: time
      weekday:
        - mon
        - tue
        - wed

mode: restart

And try and import the Blueprint, I get the following error:
mapping values are not allowed here in "<unicode string>", line 103, column 15: weekday: ^

Is someone able to assist with how to correct this?

In the code you provided, the indentation is wrong. :slight_smile:

Everything under condition: needs to be correctly indented => two spaces. Like this:

trigger:
...
condition:
  - condition: time
    weekday:
      - mon
      - tue
      - wed

mode: restart

Thanks for that. I thought I had checked the indentation but obviously not closely enough…

Been trying all day to figure out how to get your amendments working with an NFC tag rather than a switch. I setup a toggle that will turn on when the tag is scanned, but I can’t get the event and notification/changing to taken working. I either get an error, or only the reply to the notification on the phone works. I have the following code updates:
Resets the toggles to off when the automation runs:

action:
- service: input_boolean.turn_off
  target:
    entity_id: input_boolean.meds_taken
- service: input_boolean.turn_off
  target:
    entity_id: input_boolean.mednfc

Waiting for either than notification on the app to be acknowledged or toggle change to on meaning the NFC tag has been scanned:

    - wait_for_trigger:
        - platform: event
          event_type: mobile_app_notification_action
          event_data:
            tag: !input input_boolean
        - platform: event
          event_type: state_change
          event_data:
            entity_id: input_boolean.mednfc
          new_state: "on"

Taken path to clear notification on NFC scan. I believe this is where my error is coming from:

      - conditions: '{{ wait.trigger and wait.trigger.event.data.command wait.trigger.event.data.command == ''on'' }}'
        sequence:
        - service: input_boolean.turn_on
          target:
            entity_id: !input input_boolean
        - device_id: !input notify_device
          domain: mobile_app
          type: notify
          title: !input notification_title
          message: "clear_notification"
          data:
            tag: !input input_boolean
        - service: logbook.log
          data:
            name: !input notification_title
            message: !input logbook_message_taken
            entity_id: !input input_boolean

Error I’m currently getting:

Message malformed: Expected a dictionary @ data['action'][2]['repeat']['sequence'][4]['choose'][1]['conditions'][0]

A little late, I hope you got it fixed already, but if not… :slight_smile:

You’re having the condition wrong, I suspect you duplicated something accidentally.

Correct would be:
- conditions: '{{ wait.trigger and wait.trigger.event.data.command == ''on'' }}'

I’m not exactly sure what you’re trying to do, but if it would be me, I wouldn’t work with the blueprint for your automation. Just setup an automation using the blueprint as a template. Makes it easier to work with in the aftermath.

If you need help there, let me know! :slight_smile:

Thanks for the response. I ended up just simplifying the automation and bypassing the notification options altogether and it just sending the message. When I get a chance, I might have another go at it.
Cheers.

1 Like

Just discovered this blueprint - looks like it would be exactly what I need. I’m on iOS, and the actionable notifications aren’t working. If I call the notify service directly, with an actions key, it errors unless I nest another data: block.

data:
  message: Test message
  title: Test title
  data:
    actions:
      - action: Test
        title: This is option 1

The blueprint only has a single data block and no actions display. If I try and modify the blueprint to add another data block, HA complains about a missing message key. I’m confused… and pretty new to this :slight_smile:

Could someone check if the actions are shown in this blueprint on iOS?

Is there a way to add a notification sound to the device? The “Optional Action” does not work, as it kills the entire automation.

Thank you in advance

I agree with adding the possibility to name a channel.
We can indeed customize the blueprint but when we update we have to edit the blueprint.
Not everyone is able or has the knowledge to edit a script/blueprint

greetings

@Mati24

look in the blueprint for this code

  - device_id: !input notify_device
      domain: mobile_app
      type: notify
      title: !input notification_title
      message: !input notification_message
      data:
        actions:
        - title: !input notification_action_taken
          action: taken
        - title: !input notification_action_later
          action: later
        - title: !input notification_action_skip
          action: skip
        tag: !input input_boolean
        channel: medication
    - wait_for_trigger:

I have put in new line with “channel: medication” in
Run it once manually
Then, in the app go to channels and look after the channel you past thru the notification en edit to the sound you like

I hope this help.
If I get to ask for a channel in the setup I will pass it on

Ronald

Hi, when I run the notification and press any of the action buttons in the notification, it won’t change or trigger the logbook message alteration. Who can help me out?

Blockquote

alias: Medicatie herinnering 2
description: “”
triggers:

  • trigger: time
    at: input_datetime.medicatie_2
    actions:
  • target:
    entity_id: input_boolean.tramadol_2
    action: input_boolean.turn_off
    data: {}
  • alias: Notify until the medication has been take
    repeat:
    while:
    - condition: state
    entity_id: input_boolean.tramadol_2
    state: “off”
    sequence:
    - data:
    name: " Medicatie herinnering! "
    message: Reminder verstuurd
    entity_id: input_boolean.tramadol_2
    action: logbook.log
    - choose:
    - conditions:
    - condition: template
    value_template: “{{ true }}”
    sequence:
    - device_id: 9cd6f263ae72163b27c7c65d21a872b8
    domain: mobile_app
    type: notify
    title: ":pill: Medicatie herinnering! :pill: "
    message: "Het is tijd voor je Tramadol :pill: "
    data:
    actions:
    - title: Ingenomen
    action: taken
    - title: Uitstellen
    action: later
    - title: Overslaan
    action: skip
    tag: input_boolean.tramadol_2
    - wait_for_trigger:
    event_type: mobile_app_notification_action
    event_data:
    tag: input_boolean.tramadol_2
    trigger: event
    timeout:
    minutes: 30
    - choose:
    - conditions:
    - condition: template
    value_template: >-
    {{ wait.trigger and wait.trigger.event.data.action ==
    ‘taken’ }}
    sequence:
    - target:
    entity_id: input_boolean.tramadol_2
    action: input_boolean.turn_on
    data: {}
    - data:
    name: "Medicatie herinnering! "
    message: Medicatie ingenomen
    entity_id: input_boolean.tramadol_2
    action: logbook.log
    - conditions:
    - condition: template
    value_template: >-
    {{ wait.trigger and wait.trigger.event.data.action ==
    ‘later’ }}
    sequence:
    - data:
    name: " Medicatie herinnering! "
    message: Uitgesteld
    entity_id: input_boolean.tramadol_2
    action: logbook.log
    - delay:
    minutes: 30
    - conditions:
    - condition: template
    value_template: >-
    {{ wait.trigger and wait.trigger.event.data.action == ‘skip’
    }}
    sequence:
    - target:
    entity_id: input_boolean.tramadol_2
    action: input_boolean.turn_on
    data: {}
    - data:
    name: "Medicatie herinnering! "
    message: Reminder Overgeslagen
    entity_id: input_boolean.tramadol_2
    action: logbook.log
    default:
    - device_id: 9cd6f263ae72163b27c7c65d21a872b8
    domain: mobile_app
    type: notify
    message: clear_notification
    data:
    tag: input_boolean.tramadol_2
    - data:
    name: "Medicatie herinnering! "
    entity_id: input_boolean.tramadol_2
    message: Overgeslagen
    action: logbook.log
    mode: restart

Hi all
Is it possible to keep track of the date and time that a pill is taken (or missed) with this Blueprint?

Thanks

Thanks for the blueprint! I have altered it for my use to send the notification with interruption-level: critical. I recommend this as a new feature with options for active, time-sensitive, or critical.

do you have your code to implement it, or maybe you can make a PR ?

For my purposes, I always wanted the reminder to be critical, so in the notify action, I just added the lines to set the interruption level:

    - device_id: !input notify_device
      domain: mobile_app
      type: notify
      title: !input notification_title
      message: !input notification_message
      data:
        push:
          interruption-level: critical
        actions:
        - title: !input notification_action_taken
          action: taken
        - title: !input notification_action_later
          action: later
        - title: !input notification_action_skip
          action: skip
        tag: !input input_boolean

You could easily change this to allow the user to choose the interruption level.

Also, I wanted a time stamp helper for when the medication was taken. Rather than have a seperate automation handle that, I added an input for a datetime helper and then set that when the Action is “taken”:

    input_datetime:
      name: Dedicated input_datetime
      description: Record the last time the medication was reported as taken
      selector:
        entity:
          domain:
          - input_datetime
          multiple: false
      - conditions: '{{ wait.trigger and wait.trigger.event.data.actionName == ''taken''
          }}'
        sequence:
        - service: input_boolean.turn_on
          target:
            entity_id: !input input_boolean
        - service: input_datetime.set_datetime
          target:
            entity_id: !input input_datetime
          data:
            datetime: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
        - service: logbook.log
          data:
            name: !input notification_title
            message: !input logbook_message_taken
            entity_id: !input input_boolean

One handy use of this is with multiple meds on different schedules you can have appropriately named timestamps and show them on a dashboard or just ask your assistant when you last took XYZ medication.