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.
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 D1Mini (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. - Now (Sep 2022) also supports the binary format used by some meters.
This project has recently been rewritten from beeing a custom component, because these are deprecated, into an external component. As a result there are some differences and there could be bugs introduced by the rewrite.
Changes as a result of the rewrite include:
- The update period can no longer be changed dynamically. A rebuild is needed to change it.
- When passing data to a secondary P1-port, the RTS signal of the secondary reader is ignored. When the secondary port is enabled, data is allways passed on, even if the secondary device is not requesting it.
The custom component based code is available in the custom-component
branch.
The current version is tested with ESPHome version 2024.3.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
- Itron A300 / Borås Elnät
- KAIFA MA304H4E / Nacka Energi
- 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.
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 D1Mini.
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.
It is possible to attach another P1 reading device in case you need to connect a car charger (or a second p1-mini...) etc. If you have no need for this, you can skip this section and continue with "Installation" below.
Warning
Currently, the RTS signal of the secondary device is ignored. If you are using the secondary port and this is a problem, let me know and I will try to fix it!
- Female connector for the RJ12 cable.
- White (or blue) LED
- Resistor 1 - 3 kΩ
The LED will, in addition to providing visual indication that updates are beeing requested on the port, ensure that the voltage on D0 will not get high enough to damage the D1mini. The LED needs to have a high enough voltage drop for it to work and some colors may not work.
The value of the resistor is not very critical. I have tested with 3 kΩ and anything down to 1 kΩ should be fine.
A p1mini wired up with a secondary port (unpowered) on an experimental board:
Power to the secondary port needs to be supplied from a secondary source (such as an USB charger). Unless the secondary device is already powered (like a car charger etc) in which case it may not be necessary to supply any power at all to the secondary port.
The RTS signal of the secondaty port is ignored and all data is passed along as soon as it is received, regardless if the secondary device is ready to receive or not.
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>
p1mini_name: <The name you want to use>
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 p1mini_name
field can be set to any name, it will be used when accessing the web server, for example p1mini will result in http://p1mini.local/
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
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.
If you do not receive any data, make sure that the P1 port is enabled on your meter and try setting the log level to DEBUG
in ESPHome for more feedback.
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/