HEM (Home Electrical Measurement) is a personal IoT project for monitoring home electrical consumption in real-time using ESP8266 microcontrollers. The system detects LED blinks from electrical meters (such as French Linky meters) using light-dependent resistors (LDR) and transmits consumption data over a wireless mesh network with MQTT integration for data visualization and analysis.
- Real-time electrical consumption monitoring via LDR sensor detecting meter blinks
- Wireless mesh network communication between ESP8266 nodes using painlessMesh
- MQTT integration for data publishing and integration with home automation systems
- Multi-version evolution showing project development from v0.1 to v0.3
- Instant power calculation in VA (Volt-Ampere)
- Consumption tracking per 15 minutes and per hour
- Client-Server architecture with multiple nodes support
- NodeMCU v3 or similar ESP8266-based boards
- Witty Cloud module (for some versions with RGB LED support)
- LDR (Light Dependent Resistor) - Connected to A0 (analog pin)
- LEDs - RGB LEDs (pins 15/RED, 12/GREEN, 13/BLUE on Witty Cloud)
- Button - Optional (pin 4)
- USB cable for programming and power
- Electrical meter with LED indicator (e.g., Linky meter in France)
LDR: A0 (Analog pin)
RED: GPIO 15
GREEN: GPIO 12
BLUE: GPIO 13
BUTTON: GPIO 4
- Arduino IDE 1.8.x or higher, OR
- PlatformIO IDE (VS Code extension)
- painlessMesh - Mesh network communication library
- ArduinoJson (v5 or v6) - JSON parsing and serialization
- PubSubClient - MQTT client library (for server versions with MQTT)
- ESP8266WiFi - WiFi connectivity (included in ESP8266 core)
- ESP8266 Core for Arduino (install via Board Manager)
For Arduino IDE:
- Install Arduino IDE from arduino.cc
- Add ESP8266 board support:
- Go to File โ Preferences
- Add to "Additional Board Manager URLs":
http://arduino.esp8266.com/stable/package_esp8266com_index.json - Go to Tools โ Board โ Board Manager
- Search for "ESP8266" and install "ESP8266 by ESP8266 Community"
For PlatformIO:
- Install VS Code and PlatformIO extension
- The ESP8266 platform will be installed automatically with the project
Arduino IDE:
- Go to Sketch โ Include Library โ Manage Libraries
- Search and install:
- painlessMesh
- ArduinoJson
- PubSubClient
PlatformIO:
Add to platformio.ini:
[env:esp12e]
platform = espressif8266
board = esp12e
framework = arduino
lib_deps =
painlessmesh/painlessMesh
bblanchon/ArduinoJson
knolleary/PubSubClient- Create a configuration file (e.g.,
config.h) in each project folder:
// config.h - DO NOT COMMIT THIS FILE
#ifndef CONFIG_H
#define CONFIG_H
// Mesh Network Configuration
#define MESH_PREFIX "YourMeshName"
#define MESH_PASSWORD "YourSecurePassword"
#define MESH_PORT 5555
// WiFi Station Configuration (for Server with MQTT)
#define STATION_SSID "YourWiFiSSID"
#define STATION_PASSWORD "YourWiFiPassword"
// MQTT Configuration
#define MQTT_BROKER_IP "192.168.1.xxx" // Your MQTT broker IP
#define MQTT_USER "your_mqtt_user"
#define MQTT_PASSWORD "your_mqtt_password"
#endif- Update the .ino files to include your config file:
#include "config.h"- Never commit your
config.hfile (it's listed in.gitignore)
- Connect your ESP8266 board via USB
- Select the correct board and port in Arduino IDE / PlatformIO
- Choose the appropriate sketch for your node type:
- HEM_Server_v0.3 - Main server node with MQTT bridge
- HEM_Client_v0.2 - Client node for additional monitoring points
- HEM_MACFinder - Utility to find your ESP8266 MAC address
- Test_LDR - Test program for LDR sensor calibration
- Upload the sketch
HomeElectricalMeasurement/
โโโ HEM_Server_v0.1/ # Initial server version (basic mesh)
โโโ HEM_Server_v0.2/ # Server v0.2 with improvements
โโโ HEM_Server_v0.3/ # Latest server with MQTT integration
โโโ HEM_Client_v0.1/ # Initial client version
โโโ HEM_Client_v0.2/ # Improved client version
โโโ HEM_BlinkSimulator/ # LED blink simulator for testing
โโโ HEM_MACFinder/ # Utility to find ESP MAC address
โโโ Test_LDR/ # LDR sensor test program
โโโ README.md # This file
โโโ LICENSE # MIT License
โโโ .gitignore # Git ignore patterns
- Main node that collects data from LDR sensor
- Calculates instant power consumption (VA)
- Tracks consumption per 15 minutes and per hour
- Broadcasts data over mesh network
- v0.3: Acts as MQTT bridge to WiFi network
- Secondary nodes that receive data from server
- Display consumption information
- Can be placed in different rooms for monitoring
- Communicate via mesh network
- HEM_BlinkSimulator: Simulates electrical meter LED blinks for testing
- HEM_MACFinder: Finds the MAC address of your ESP8266
- Test_LDR: Calibrates and tests the LDR sensor
-
Position the LDR sensor on your electrical meter's LED indicator
- Ensure good contact and light seal
- The LDR should clearly detect the blinks
-
Power on the Server node (HEM_Server)
- It will create the mesh network
- Start monitoring the LDR
- If using v0.3, it connects to WiFi and MQTT broker
-
Power on Client nodes (optional)
- They will automatically join the mesh network
- Start receiving consumption data
-
Monitor via Serial (115200 baud)
- Open Serial Monitor in Arduino IDE
- View real-time consumption data
The server publishes to the following MQTT topics:
linky/ServerAlive # Server heartbeat (0/1)
linky/LDR # Raw LDR value
linky/ConsoInstVA # Instantaneous consumption in VA
linky/maxConsoInstVA # Maximum consumption recorded
linky/WhPer15Minute # Wh consumed in last 15 minutes
linky/WhPerHour # Wh consumed in last hour
- ConsoInstVA: Current power consumption calculated from blink frequency
- Formula:
3600 / (time_between_blinks_in_seconds) - Typical values: 100-3000 VA
- Formula:
- WhPer15Minute: Number of Wh consumed in 15-minute period
- WhPerHour: Total Wh consumed per hour
- maxConsoInstVA: Peak consumption recorded
Before deploying this project, you MUST replace the following:
-
Mesh Network Credentials
MESH_PREFIX: Change from default "whateverYouLike"MESH_PASSWORD: Change from default "somethingSneaky"
-
WiFi Credentials (HEM_Server_v0.3)
STATION_SSID: Your WiFi network nameSTATION_PASSWORD: Your WiFi password
-
MQTT Credentials (HEM_Server_v0.3)
MQTT_USER: Your MQTT broker usernameMQTT_PASSWORD: Your MQTT broker passwordmqttBrokerIP address: Your MQTT broker IP
- โ
Create a separate
config.hfile with your credentials (see Installation section) - โ
Add
config.hto.gitignoreto prevent committing credentials - โ Use strong passwords for mesh and MQTT
- โ Change default MQTT credentials
- โ Use a secure WiFi network
- โ Consider using MQTT over TLS if exposing to internet
This is a personal project, but suggestions and improvements are welcome!
If you'd like to contribute:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.
- painlessMesh library for easy ESP8266 mesh networking
- ArduinoJson for efficient JSON parsing
- PubSubClient for MQTT functionality
- ESP8266 community for excellent documentation and support
This is a personal project by MatGros.
For questions or issues, please open an issue on the GitHub repository.
Potential enhancements for this project:
- Web interface for real-time monitoring
- Data logging to SD card or cloud storage
- Mobile app integration
- Support for multiple electrical meters
- Historical data analysis and graphs
- Alert system for high consumption
- Integration with Home Assistant or other home automation platforms
- Over-the-air (OTA) firmware updates
- Encrypted mesh communication
- Battery backup support
โก Happy Monitoring! โก