Assumes your power meter has a flashing LED that flashes every e.g 1/1000th of a kWh and that you can place an optotransistor over the LED to trigger a pulse on a pin on the ESP8266.
Features
- Web page at
/
to get and set the kWh remaining on your prepaid electricity meter - Prometheus
/metrics
endpoint to get details about power usage for display in Grafana - Link to Home Assistant and Node-Red by publishing on the MQTT
powermeter
topic
Tested with
- MicroPython 1.13
- Wemos D1 Mini ESP8266
https://learn.sparkfun.com/tutorials/how-to-install-ch340-drivers/all
From https://docs.micropython.org/en/latest/esp8266/tutorial/intro.html Downloaded latest MicroPython 1.13: esp8266-20200911-v1.13.bin pip3 install esptool
esptool.py --help
esptool.py erase_flash
esptool.py --port /dev/tty.wchusbserial1410 --baud 460800 write_flash --flash_size=detect 0 ~/Downloads/esp8266-20200911-v1.13.bin
http://micropython.org/webrepl/#10.0.0.146:8266
Command line tool for upload/download of files. Installation instructions at https://github.com/scientifichackers/ampy
- List files
ampy -p /dev/tty.wchusbserial1410 -b 115200 ls
- Run a file (even if it's not yet uploaded)
ampy -p /dev/tty.wchusbserial1410 -b 115200 run main.py
- Upload a file
ampy -p /dev/tty.wchusbserial1410 -b 115200 put main.py
- Upload all the files:
boot.py
,main.py
,config.json
,index.html
,metrics
- Note you will need to edit
config_example.json
to suit your requirements, and save asconfig.json
screen /dev/tty.wchusbserial1410 115200
- To exit from Screen:
CTRL+A
CTRL+\
- To abort the currently running program, get back to REPL:
CTRL+C
- To restart micro:
CTRL+D
- Communica or Micro Robotics supply a cheap D1 Mini board
- Ambient light sensor, also from Communica, but pretty much any light dependent resistor (LDR) or optotransistor board will work
I made a full presentation on Home Automation with MicroPython, the ESP8266 and Google Home at Google DevFest 2020. It includes my slides and YouTube presentation for building this Power Meter, as well as a short intro to MicroPython.