Advanced medication reminder

I’ve created a custom card that displays medication details, including when it was last taken, how many tablets remain, and a color-coded bar indicating the count. It also shows a percentage badge so you can quickly see how much supply is left. Here’s the complete YAML configuration for the card:


Cards you will need:

  1. GitHub - ofekashery/vertical-stack-in-card: 📐 Home Assistant Card: Group multiple cards into a single sleek card.
  2. GitHub - usernein/tailwindcss-template-card: Custom card for Home Assistant that renders html code with TailwindCSS styles into the dashboard
  3. GitHub - custom-cards/bar-card: Customizable Animated Bar card for Home Assistant Lovelace
type: custom:vertical-stack-in-card
cards:
  - type: custom:tailwindcss-template-card
    card_mod:
      style: |
        ha-card {
          border-bottom-left-radius: 0 !important;
          border-bottom-right-radius: 0 !important;
        }
    entity: input_datetime.aspirin_adherence
    content: |
      <div class="p-4">
        <!-- Title + Right-Aligned Schedule -->
        <div class="flex items-center justify-between mb-2">
          <div class="text-lg font-bold">Aspirin</div>
          <div class="text-sm text-gray-500">Daily at 8:00 AM</div>
        </div>

        <!-- Last taken row -->
        <div class="flex items-center space-x-1 text-sm text-gray-600 mb-4">
          <ha-icon icon="mdi:clock-time-four-outline"></ha-icon>
          <span>Last taken: {{ states('input_datetime.aspirin_adherence') }} </span>
        </div>

        <!-- Remaining Tablets row + percentage bubble -->
        <div class="flex items-center justify-between">
          <span class="text-gray-800 font-medium">Remaining Tablets</span>
          <span class="text-gray-800">
            {{ states('counter.aspirin') }}/{{ state_attr('counter.aspirin', 'initial') }}
          </span>
        </div>
        
       
        <div class="mt-1">
          <!-- Percentage bubble -->
          <span class="inline-block text-xs font-bold text-blue-600 bg-blue-100 px-2 py-1 rounded-full">
            {{
              (
                ( states('counter.aspirin')|float
                  / state_attr('counter.aspirin', 'initial')|float
                ) * 100
              )|round(0)
            }}%
          </span>
        </div>
      </div>
  - type: custom:bar-card
    card_mod:
      style: |
        ha-card {
          margin-top: -10px !important; 
        }
    entities:
      - entity: counter.aspirin
        icon: mdi:pill
        positions:
          icon: "off"
          indicator: "off"
          minmax: "off"
          name: "off"
          value: "off"
        min: 0
        max: 90
        height: 12
    severity:
      - from: 0
        to: 4
        color: "#ff0000"
      - from: 5
        to: 29
        color: "#ffa500"
      - from: 30
        to: 59
        color: "#ffff00"
      - from: 60
        to: 90
        color: "#00ff00"
4 Likes

@chintito4ever - nice. Might be cool to turn the background of the card to an alert color if adherence check fails.

I installed the 3 github cards and pasted the code (after creating 2 helpers) but I only have a bar with no text and info

got it working

1 Like

Did anyone find a workaround for this change? I also want to display it as it was before the update

I used your fix but still only see the bar, can you share your full yaml?

1 Like

Has anyone create a dashboard button to manually log the history item as taken and decrement the counter? How did you go about that? Did you just turn on thei nput boolean? I don’t think that would create a log and unless the blueprint is running it would not log it.

Create a script with the same actions that are under “taken” in the blueprint/automation and then launch that script from anywhere you like.

I’m also having trouble getting this to work. I only see the bar.

Where is the ‘input_datetime.aspirin_adherence’ coming from?

I just wanted to says thank you for the blueprint. I added the blueprint as provided. Built the cards for manual take AM & PM buttons, history for a dashboard. May add 15 minute reminders, last taken etc. later. I don’t really need when to refill etc, my pharmacy already reminds me. I also added phone widgets for manual take AM & PM. Medisafe app tracking has been replaced. :+1:

1 Like

In case it helps others. I am still fiddling with this and have multiple setup. I have taken control of the automation so I could edit. Unfortunately, it is only popping up on my phone for my initial setup. I am guessing it is scripted the same and needs to change, but I have not yet had time to rescript. In the short term, I added a button that toggles the input boolean off. I have a 2nd automation that decrements the counter and modifies the adherence input/date time to properly record when it was last taken. This was not working in the original blue print. I would love to change the date time format on adherence (last taken) but haven’t gotten to modifying yet successfully. See below for an example dashboard for a vitamin (this one not hitting phone - so button for “taken”.

Hope this helps someone else.

Hi, could you share your configuration, for the lovelace without times taken, I don’t need to count the pills either, thank you

I’m probably not one to ask lol. Here’s what i think I did in YAML.

Create two toggle helpers.

type: horizontal-stack
cards:
  - show_name: true
    show_icon: true
    type: button
    name: Took AM Meds
    icon: mdi:pill
    tap_action:
      action: toggle
    entity: input_boolean.medicines_am
  - type: button
    name: Took PM Meds
    icon: mdi:pill
    tap_action:
      action: toggle
    entity: input_boolean.medicines_pm

And for logs activity card.

type: logbook
title: Medication Logbook
entities:
  - input_boolean.medicines_am
  - input_boolean.medicines_pm
hours_to_show: 48

Automation

alias: Medication Reminders (Manual Toggles & Logbook)
description: Tracks AM/PM med confirmations, logs events, and resets booleans daily
triggers:

  • entity_id: input_boolean.medicines_am
    to: “on”
    id: am_taken
    trigger: state
  • entity_id: input_boolean.medicines_pm
    to: “on”
    id: pm_taken
    trigger: state
  • at: “04:30:00”
    id: reset_am
    trigger: time
  • at: “16:30:00”
    id: reset_pm
    trigger: time
    conditions:
    actions:
  • choose:
    • conditions:
      • condition: trigger
        id: am_taken
        sequence:
      • data:
        name: Medication
        message: AM meds taken manually
        entity_id: input_boolean.medicines_am
        action: logbook.log
    • conditions:
      • condition: trigger
        id: pm_taken
        sequence:
      • data:
        name: Medication
        message: PM meds taken manually
        entity_id: input_boolean.medicines_pm
        action: logbook.log
    • conditions:
      • condition: trigger
        id: reset_am
        sequence:
      • target:
        entity_id: input_boolean.medicines_am
        action: input_boolean.turn_off
    • conditions:
      • condition: trigger
        id: reset_pm
        sequence:
      • target:
        entity_id: input_boolean.medicines_pm
        action: input_boolean.turn_off
        mode: single

I have reminder automations also, if you need those, holler.

If that doesn’t help, I’ll need to look harder, been a while. Far from an expert.:wink: