Based on esphome-p1reader, which is an ESPHome custom component for reading P1 data from electricity meters. Designed for Swedish meters that implements the specification defined in the Swedish Energy Industry Recommendation For Customer Interfaces version 1.3 and above.
The component can be used by itself from any config file or with the config file included in the project, which matches the suggested hardware configuration for a D1 mini and is kept up to date with any updates to the component.
Notable differences from esphome-p1reader are:
- More frequent update of sensors with configurable update period (if supported by meter).
- No additional components needed. RJ12 cable connects directly to D1 mini (or equivalent)
- Code rewritten to not spend excessive amounts of time in calls to the
loop
function. This should ensure stable operation of ESPHome and might help prevent some serial communication issues. - Rewritten as an external component since custom components are deprecated.
The current version is tested with ESPHome version 2024.12.2
and the yaml will not work with versions earlier than 2024.6.0
.
- Sagemcom T211 / Ellevio, Skånska Energi
- Aidon 6534 with RJ12/P1-port module (not RJ45/NVE module) / SEVAB
- Landis+Gyr E360 / E.ON - But read this
- S34U18 (Sanxing SX631) / Vattenfall - But read this
- Kamstrup OMNIPOWER
- KAIFA MA304H4E (and MA304T4E) / Nacka Energi - But read this
- Itron A300 / Borås Elnät
- KAIFA CL109 / Öresundskraft
- SWEMET / Shenzhen Star - STZ351: Seems to have an incorrectly formatted message and incorrectly calculated checksum. A possible workaround is discussed here.
I have used a D1 mini clone, but most ESP-based controllers should work as long as you figure out appropriate pins to use. The P1 port on the meter provides 5V up to 250mA which makes it possible to power the circuit directly from the P1 port.
ESP32 based boards draw more power, which may cause a problem with the supply from the meter and generally offer no advantage over ESP8266 based boards. The exception is when connecting the same ESP module to several power meters in which case the multiple UARTs of the ESP32 are needed.
If you have pre built hardware which does not connect the RTS signal to a GPIO, read this.
- 1 (Wemos) D1 mini or clone.
- 1 RJ12 cable (6 wires)
- Optionally, hot melt glue and large heat shrink tubing.
Wiring is simple. Five of the pins from the connector (one pin is not used)...
... are connected to four of the pads on the D1 mini.
And that is it. The result could look something like this:
Some hot-melt glue and heat shrink tubing will make it more robust though.
The component can be used by itself from any config file, or with the included config file, which is kept up to date with any updates and matches the hardware configuration described for a D1 mini.
If you are making substantial changes to the config it may make more sense to use the component only in your config file.
Clone the repository and create a companion secrets.yaml
file with the following fields:
wifi_ssid: <your wifi SSID>
wifi_password: <your wifi password>
p1mini_password: <Your p1mini password (for OTA, etc)>
p1mini_api_key: <Home Assistant API key>
The p1mini_password
field can be set to any password before doing the initial upload of the firmware. A new API key can be generated on this page.
The file structure should include these files:
|- p1mini.yaml
|- secrets.yaml
|- components
|- p1mini
|- __init__.py
|- p1_mini.cpp
|- p1_mini.h
|- sensor
|- __init__.py
|- p1_mini_sensor.cpp
|- p1_mini_sensor.h
|- text_sensor
|- __init__.py
|- p1_mini_text_sensor.cpp
|- p1_mini_text_sensor.h
Flash ESPHome as usual, with the relevant files in place. Don't connect USB and the P1 port at the same time! If everything works, Home Assistant will autodetect the new integration after you plug it into the P1 port.
Things to try if you are having problems:
- Make sure that the P1 port is enabled on your meter
- Set the log level to
DEBUG
in ESPHome for more feedback. - Access the web browser on the P1mini: (usually) http://p1mini.local/
Specification overview: https://www.tekniskaverken.se/siteassets/tekniska-verken/elnat/aidonfd-rj12-han-interface-se-v13a.cleaned.pdf
OBIS codes: https://tech.enectiva.cz/en/installation-instructions/others/obis-codes-meaning/
P1 hardware info (in Dutch): http://domoticx.com/p1-poort-slimme-meter-hardware/