8.6 KiB
MedMate - Medicine Tracker for Home Assistant
A comprehensive custom integration to track medicines, dosing schedules, inventory, and prescriptions in Home Assistant.
Features
- Complete Medicine Management: Track active ingredients, strength, and pack sizes
- Flexible Scheduling: Set doses by days of the week and times of day (morning, lunchtime, dinner, night, custom)
- Inventory Tracking: Monitor pill counts with automatic updates when doses are taken
- Prescription Management: Track issue dates, expiry dates, doctor info, repeats, and automatic expiration
- Smart Notifications: Binary sensors for dose due, low inventory, and prescription status
- Easy Actions: Buttons to take doses and fill prescriptions
- UI Configuration: Complete setup and management through Home Assistant UI
Installation
Method 1: Manual Installation
-
Create a
medmatefolder in yourcustom_componentsdirectory:config/ └── custom_components/ └── medmate/ ├── __init__.py ├── const.py ├── config_flow.py ├── coordinator.py ├── sensor.py ├── binary_sensor.py ├── button.py ├── manifest.json ├── strings.json └── services.yaml -
Copy all the provided files into the
medmatefolder -
Restart Home Assistant
-
Go to Settings > Devices & Services > Add Integration
-
Search for "MedMate" and click to add
Method 2: HACS (if you publish to HACS)
- Open HACS in Home Assistant
- Go to Integrations
- Click the three dots menu and select "Custom repositories"
- Add your repository URL
- Install MedMate
- Restart Home Assistant
Configuration
Adding a New Medicine
- Go to Settings > Devices & Services
- Click Add Integration and search for "MedMate"
- Follow the setup wizard:
Step 1: Medicine Information
- Medicine Name: Unique name for the medicine
- Active Ingredient: The active pharmaceutical ingredient
- Strength: Dosage strength (e.g., "500mg", "10mg/5ml")
- Pack Size: Number of pills/doses per pack
Step 2: Dosing Schedule
- Days of the Week: Select which days you take this medicine
- Times of Day: Choose from:
- Morning (8:00 AM)
- Lunchtime (12:00 PM)
- Dinner (6:00 PM)
- Night (10:00 PM)
- Custom (configurable)
Step 3: Prescription Details
- Issue Date: When the prescription was issued
- Expiry Date: When the prescription expires
- Doctor: Prescribing doctor (optional)
- Total Repeats: Total number of repeats on prescription
- Repeats Left: Current repeats remaining
Modifying Medicine Settings
- Go to Settings > Devices & Services > MedMate
- Click on the medicine device
- Click Configure to modify any settings
Entities Created
For each medicine, MedMate creates the following entities:
Sensors
sensor.medmate_[medicine]_inventory: Current pill countsensor.medmate_[medicine]_repeats_left: Prescription repeats remainingsensor.medmate_[medicine]_next_dose: Timestamp of next scheduled dose
Binary Sensors
binary_sensor.medmate_[medicine]_dose_due: True when dose is due (within 30 minutes of scheduled time)binary_sensor.medmate_[medicine]_prescription_active: True when prescription is valid and has repeatsbinary_sensor.medmate_[medicine]_low_inventory: True when inventory is below 7 pills
Buttons
button.medmate_[medicine]_fill_prescription: Fill prescription (add pack size to inventory, reduce repeats by 1)button.medmate_[medicine]_take_[time]_dose: Take dose buttons for each scheduled time
Services
MedMate provides several services for automation:
medmate.take_dose
Record that a dose was taken.
service: medmate.take_dose
target:
entity_id: button.medmate_aspirin_take_morning_dose
data:
time_slot: morning
medmate.fill_prescription
Fill a prescription.
service: medmate.fill_prescription
target:
entity_id: button.medmate_aspirin_fill_prescription
medmate.update_inventory
Manually update inventory count.
service: medmate.update_inventory
target:
entity_id: sensor.medmate_aspirin_inventory
data:
inventory: 25
medmate.update_repeats
Manually update repeats left.
service: medmate.update_repeats
target:
entity_id: sensor.medmate_aspirin_repeats_left
data:
repeats_left: 3
Automation Examples
Dose Reminder
automation:
- alias: "Medicine Dose Due Notification"
trigger:
- platform: state
entity_id: binary_sensor.medmate_aspirin_dose_due
to: "on"
action:
- service: notify.mobile_app_your_phone
data:
title: "Medicine Reminder"
message: "Time to take your aspirin!"
data:
actions:
- action: "take_dose"
title: "Mark as Taken"
Low Inventory Alert
automation:
- alias: "Low Medicine Inventory"
trigger:
- platform: state
entity_id: binary_sensor.medmate_aspirin_low_inventory
to: "on"
action:
- service: notify.mobile_app_your_phone
data:
title: "Low Medicine Inventory"
message: "Aspirin inventory is running low. Consider refilling soon."
Auto-fill Prescription
automation:
- alias: "Auto Fill When Empty"
trigger:
- platform: numeric_state
entity_id: sensor.medmate_aspirin_inventory
below: 1
condition:
- condition: state
entity_id: binary_sensor.medmate_aspirin_prescription_active
state: "on"
action:
- service: button.press
target:
entity_id: button.medmate_aspirin_fill_prescription
Dashboard Examples
Medicine Card
type: entities
title: Aspirin
entities:
- entity: sensor.medmate_aspirin_inventory
name: Pills Left
- entity: sensor.medmate_aspirin_repeats_left
name: Repeats
- entity: sensor.medmate_aspirin_next_dose
name: Next Dose
- entity: binary_sensor.medmate_aspirin_dose_due
name: Dose Due
- entity: button.medmate_aspirin_take_morning_dose
name: Take Morning Dose
- entity: button.medmate_aspirin_fill_prescription
name: Fill Prescription
Medicine Overview
type: glance
title: All Medicines
entities:
- entity: sensor.medmate_aspirin_inventory
name: Aspirin
- entity: sensor.medmate_vitamin_d_inventory
name: Vitamin D
- entity: sensor.medmate_calcium_inventory
name: Calcium
show_name: true
show_state: true
Data Storage
MedMate stores all data locally in Home Assistant's storage directory:
- Location:
config/.storage/medmate_medicines - Format: JSON
- Includes: Medicine details, schedules, prescriptions, inventory, and dose history
Troubleshooting
Medicine Not Showing Up
- Check that all files are in the correct directory
- Restart Home Assistant completely
- Check the logs for any error messages
Entities Not Updating
- Check if the coordinator is running properly
- Look for errors in Settings > System > Logs
- Try reloading the integration
Config Flow Issues
- Make sure medicine names are unique
- Check that all required fields are filled
- Verify dates are in the correct format
Advanced Usage
Custom Time Slots
While the integration includes preset times (morning, lunchtime, dinner, night), you can extend the DEFAULT_TIMES dictionary in coordinator.py to add custom times:
DEFAULT_TIMES = {
"morning": time(8, 0),
"lunchtime": time(12, 0),
"dinner": time(18, 0),
"night": time(22, 0),
"bedtime": time(23, 30), # Custom time
}
Multiple Medicines
You can add multiple medicines by running the integration setup multiple times. Each medicine gets its own device and set of entities.
Data Export
Since data is stored in JSON format, you can easily backup or export your medicine data from the storage file.
Contributing
This integration can be extended with additional features:
- Medication interaction checking
- Dose tracking analytics
- Integration with health apps
- Barcode scanning for medicine identification
- Advanced scheduling (every other day, etc.)
Support
For issues, questions, or feature requests, please check:
- Home Assistant logs for error messages
- Ensure all files are properly installed
- Verify your Home Assistant version compatibility
Note: This integration is for tracking purposes only and should not replace professional medical advice. Always consult with healthcare providers for medical decisions.