I am sure there are many opinions on the what is a healthy amount and it varies from person to person and climates. But I think it is a pretty good memory trick 8 x 8. It uses a single button to record each glass of water consumed and displays the daily count on an 8‑LED WS2812 strip. The tracker runs locally with optional MQTT support (and Home Assistant via MQTT discovery) for dashboards and automation. Additionally, the tracker automatically resets at midnight using NTPClient, and the WiFi and MQTT configuration are configurable through a captive portal powered by WiFiManager.
Project GoalsLocal Water Consumption Tracking:Use a button to register each glass of water consumed. Each short press increments the water count, lighting up one more LED on the strip; a long press resets the count
Visual Feedback:The LED strip displays the current water count reliably, with each LED representing one glass of water
Remote Integration:Use MQTT for reporting the water count and receiving commands (e.g., to set the count) so that the device can integrate with home automation platforms such as Home Assistant.
Automatic Daily Reset:Use NTPClient to obtain the current time and automatically reset the water count at midnight.
User-Friendly Configuration:WiFiManager is used to set up the device’s WiFi connection as well as custom parameters such as MQTT settings and the timezone offset (for Eastern Standard Time, enter -18000 seconds) via a captive portal. Settings persist in EEPROM across resets.
Hardware Components- ESP8266 Module (e.g., NodeMCU or Wemos D1 Mini)
- 8‑LED WS2812/NeoPixel LED Strip
- Pushbutton (with appropriate wiring for INPUT_PULLUP))
The project is developed in the Arduino IDE and uses the following libraries:
- ESP8266WiFi – For WiFi connectivity.
- WiFiManager – To provide a captive portal for WiFi and custom parameter configuration.
- PubSubClient – For MQTT communication.
- FastLED – To control the LED strip.
- EEPROM – For persistent storage of water count, MQTT settings, and timezone offset.
- WiFiUdp & NTPClient – To obtain current time from an NTP server for the daily reset.
- Bounce2 – For reliable button debouncing.
LED Strip:
- Data: Connect the LED strip’s data input (DIN) to GPIO5 (LED_PIN). It’s recommended to use a ~330Ω resistor in series for protection.
- Power: Connect the LED strip’s +5V to the ESP8266’s onboard 5V (USB power).
- Ground: Connect the LED strip’s GND to the ESP8266’s GND.
Button:
- Connect one terminal of the pushbutton to D2 (BUTTON_PIN).
- Connect the other terminal to GND.
- (The ESP8266’s internal pull-up resistor is enabled, so the pin reads HIGH normally and goes LOW when pressed.)
Button Functionality:
- Short Press: When the button is pressed and released (held for less than 2 seconds), the water count increments by one. The LED strip is then updated so that the first n LEDs are lit blue (where n is the water count).
- Long Press: Holding the button for longer than 2 seconds resets the water count to zero.
LED Update:The displayCount()
function clears the LED buffer and then lights up exactly the first glassCount LEDs in blue. This guarantees that the LED strip always mirrors the locally tracked water count.
Reporting:The water count is published to the MQTT topic watertracker/status
as a JSON payload (e.g., {"glassCount": 4}
).
- Reporting:The water count is published to the MQTT topic
watertracker/status
as a JSON payload (e.g.,{"glassCount": 4}
).
Command Reception:The device subscribes to the MQTT topic watertracker/command
and responds to commands such as:
increment
– Increments the count.reset
– Resets the count.setCount:4
– Sets the water count to 4.getStatus
– Publishes the current water count.- Additional commands (like
help
andreminder
) are supported.
MQTT Discovery:MQTT discovery messages are published so that Home Assistant automatically detects the water tracker as an MQTT sensor.
Automatic Daily Reset- NTPClient:The project uses NTPClient to obtain the current time from an NTP server. The timezone offset (configurable via the captive portal) adjusts the time appropriately (for EST, set to -18000 seconds).
- Reset Logic:Every loop cycle checks the current epoch day and resets the water count at midnight (within the first 10 seconds after 00:00).
- Captive Portal:When the device is first powered up (or if the stored WiFi credentials are cleared), WiFiManager creates an access point (e.g., "WaterTrackerAP") for configuration.
Custom Parameters:In addition to WiFi credentials, the portal provides fields to configure:
- MQTT Server, Username, and Password.
- Timezone Offset: Enter the offset in seconds (for EST, use
-18000
). This value is stored in EEPROM and used to configure the NTPClient.
Comments
Please log in or sign up to comment.