A Power Meter for use in Home Assistant, using the Pulse Meter component in ESPHome, with the added functionally of tracking costs.
I've used Home Assistant Glow for a while without problems. I decided that it would be cool to also have the ESP track costs as well. That way I could do away with Rieman Sum and Utility Meter integrations in HA. This is the result of having that initial idea and a lot of hammering on the keyboard.
The kWh price is imported as a sensor from Home Assistant, which is running the Nordpool Custom Component, but the price can also be set 'manually' with a Number component. Ideally the price should be fetched directly from NordPool using their API.
I've added a method to track the Average kWh Price and an option to use it when reporting costs. It will still track the 'real' costs and you can toggle between the two. Remember to push the Reset kWh Price Average button at the start of the billing period.
I have had some weird power spikes (faulty photodiode, it turned out), so I included a Power Problem Level number and a Power Problem Status binary sensor in the ESPHome config. You set the level and subsequently, if power consumption goes over (or equals) the level, the binary sensor will indicate that you have a problem. The history in HA of this sensor was very useful to track the problem I had, so I have left it in.
I have also included a RGB led which, instead of blinking (I do not like blinking LEDs), will indicate power consumption level in relation to the set power problem level. Turn it on, set the brightness and the color will be set automatically at each power pulse.
To test the accuracy of the Power Meter, I created a simple Arduino Sketch to simulate the blinking LED on a 'real' Power Meter. A simple LED blinking at specific intervals to simulate power consumption. You'll find it here. I also disabled the kWh Price sensor import from HA, temporarily in the code, so the price stayed fixed during testing.
- This was made just for fun, to see what you could accomplish in an ESPHome configuration, using Globals and Lambdas all over the place.
- If this was to have any proper value, it should probably be in the form of a ESPHome Custom Component.
- I take absolutely no responsibility for any suprisingly large electricity bills.
- An ESP32. I'm using a nodemcu-32s, but any ESP32 should do. An ESP8266 might work too, if you change pin designations.
- LM393 Photodiode Sensor module
- WS2818 LED
MODULE | ESP32 |
---|---|
D0 | 26 |
A0 | NC |
VCC | VCC |
GND | GND |
LED | ESP32 |
---|---|
D0 | 17 |
VCC | VCC |
GND | GND |