Hey, I just set up this cool project to help me manage my daily vitamins. It's called the PillMinder, and it uses a little ESP8266 board to keep track of when I need to take them. There's a button to acknowledge when I've taken a vitamin, and an LED lights up as a reminder. It’s all controlled through ESPHome and integrates with Home Assistant, making it super easy to use.
So, here's how it works: when I press the button quickly, it counts down, reminding me how many doses I have left for the day. If I hold the button for a bit longer, it resets the counter back to the starting number, which is perfect for reloading new pills. The LED turns on to remind me when it’s time to take my vitamin and turns off once I acknowledge it. It's such a simple setup, but it makes a big difference in keeping me on track with my vitamins.
The best part is that it integrates with Home Assistant. I’ve set it up to reset the counter automatically at 5 AM every day, and I get notifications on my phone if I’m running low on doses. It’s been a game-changer for me, making sure I never miss a vitamin and keeping my routine hassle-free. I think you’d really appreciate how it blends technology with everyday health management!
Setting up the PillMinder project is super easy. Here’s how you wire it up:
Button Wiring:- One leg of the button goes to GPIO D3 on the ESP8266.
- The other leg connects to GND.
- If you want, you can add a 10kΩ pull-up resistor between the leg connected to D3 and 3.3V. This resistor helps keep things stable and prevents accidental triggers.
- The anode (long leg) of the LED connects to GPIO D4 on the ESP8266. You can add a 220Ω resistor here to protect the LED.
- The cathode (short leg) of the LED goes to GND.
Below is the full ESPHome YAML configuration for the PillMinder project.
ESPHome YAMLesphome:
name: pillminder
friendly_name: PillMinder
esp8266:
board: d1_mini_lite
# Enable logging
logger:
globals:
- id: countdown_counter
type: int
restore_value: yes
initial_value: '0'
# Enable Home Assistant API
api:
encryption:
key: "YOUR_API_ENCRYPTION_KEY"
sensor:
- platform: template
name: "Reminder Countdown"
id: reminder_countdown
update_interval: 10s
lambda: |-
return id(countdown_counter);
binary_sensor:
- platform: gpio
pin:
number: D3
mode: INPUT_PULLUP
inverted: true
name: "Reminder Acknowledge Button"
internal: true # This ensures the button state is only processed locally
id: reminder_button
on_press:
then:
- delay: 1500ms # Wait for 1.5 seconds for long press
- if:
condition:
binary_sensor.is_on: reminder_button # Check if button is still pressed
then:
- lambda: |-
id(countdown_counter) = 100;
id(reminder_countdown).publish_state(id(countdown_counter));
id(reminder_led).turn_off();
else:
- lambda: |-
id(countdown_counter) = id(reminder_countdown).state;
id(countdown_counter)--;
id(reminder_countdown).publish_state(id(countdown_counter));
id(reminder_led).turn_off();
light:
- platform: binary
name: "Reminder LED"
id: reminder_led
output: reminder_led_output
output:
- id: reminder_led_output
platform: gpio
pin: D4
ota:
password: "YOUR_OTA_PASSWORD"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Pillminder Fallback Hotspot"
password: "YOUR_HOTSPOT_PASSWORD"
captive_portal:
ExplanationSetup- esphome: Basic configuration, including the device name.
- esp8266: Specifies the board being used.
- logger: Enables logging for debugging purposes.
- api: Enables the Home Assistant API with encryption.
- countdown_counter: A global integer variable to keep track of the reminder countdown.
- Reminder Countdown: A template sensor that reads the value of
countdown_counter
.
- Reminder Acknowledge Button
: A GPIO binary sensor for the button. It uses
on_press
to handle both short and long presses.
- delay: 1500ms: Waits for 1.5 seconds to differentiate between short and long presses.
- if condition: Checks if the button is still pressed after the delay.
- Long press: Resets the counter to 100 and turns off the LED.
- Short press: Decrements the counter by 1 and turns off the LED.
- if condition: Checks if the button is still pressed after the delay.Long press: Resets the counter to 100 and turns off the LED.Short press: Decrements the counter by 1 and turns off the LED.
- if condition: Checks if the button is still pressed after the delay.Long press: Resets the counter to 100 and turns off the LED.Short press: Decrements the counter by 1 and turns off the LED.
- Reminder LED: A binary light controlled by a GPIO output.
- reminder_led_output: Defines the GPIO pin connected to the LED.
- ota: Enables OTA updates with a password for security.
- wifi: Configures WiFi credentials and fallback hotspot.
- captive_portal: Enables a fallback web interface if the device can't connect to WiFi.
To integrate this ESPHome device with Home Assistant, you need to add the following configurations in your configuration.yaml
file in Home Assistant.
sensor:
- platform: template
sensors:
reminder_countdown:
friendly_name: "Reminder Countdown"
value_template: "{{ states('sensor.reminder_countdown') }}"
unit_of_measurement: "counts"
light:
- platform: mqtt
name: "Reminder LED"
state_topic: "pillminder/light/reminder_led/state"
command_topic: "pillminder/light/reminder_led/command"
binary_sensor:
- platform: mqtt
name: "Reminder Acknowledge Button"
state_topic: "pillminder/binary_sensor/reminder_button/state"
Explanation- sensor.reminder_countdown: This template sensor displays the current value of the countdown counter from the ESPHome device.
- light.mqtt: This light component allows you to control the Reminder LED from Home Assistant.
- binary_sensor.mqtt: This binary sensor component represents the Reminder Acknowledge Button in Home Assistant.
You can create automations in Home Assistant to act on the reminder countdown or the button press events. Here is an example of a simple automation:
automation:
- alias: "Pill Reminder"
trigger:
platform: numeric_state
entity_id: sensor.reminder_countdown
below: 10
action:
- service: light.turn_on
entity_id: light.reminder_led
- service: notify.notify
data:
message: "Reminder: Buy more pills!"
Reset AutomationYou can also create an automation to reset the counter every day at a specific time. Here is an example:
automation:
- alias: Reset Pillminder
description: ""
trigger:
- platform: time
at: "05:00:00"
condition: []
action:
- type: turn_on
device_id: 0b66639ded443dd81ef5a8a3df77d981
entity_id: light.reminder_led
domain: light
mode: single
ConclusionThis ESPHome project provides a practical solution for managing pill reminders using an ESP8266 board. By incorporating both short and long press functionalities, it ensures flexibility and ease of use. The integration with Home Assistant allows for extended functionality and automation.
Feel free to customize the duration and other parameters to suit your specific needs. If you have any questions or need further assistance, don't hesitate to reach out!
Comments
Please log in or sign up to comment.