Skip to content

Beaky2000/esphome-p1mini

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

esphome-p1mini

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 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.
  • Rewritten as an external component since custom components are deprecated.

ESPHome version

The current version is tested with ESPHome version 2024.6.4 and the yaml will not work with versions earlier than 2024.6.0.

Verified meter hardware / supplier

Meters verified with esphome-p1reader, which should work too...

Meters with issues

Hardware

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.

Parts

  • 1 (Wemos) D1 mini or clone.
  • 1 RJ12 cable (6 wires)
  • Optionally, hot melt glue and large heat shrink tubing.

Wiring D1Mini

Wiring is simple. Five of the pins from the connector (one pin is not used)...

RJ12 pins

... are connected to four of the pads on the D1Mini.

D1mini pins

And that is it. The result could look something like this:

Soldered

Some hot-melt glue and heat shrink tubing will make it more robust though.

Completed

P1 Passthrough

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!

Parts

  • Female connector for the RJ12 cable.
  • White (or blue) LED
  • Resistor 1 - 3 kΩ

Secondary port pins

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:

Secondary port

Power to the secondary port

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.

Limitations

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.

Installation

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.

Standalone

If you are making substantial changes to the config it may make more sense to use the component only in your config file.

The full experience

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

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.

Technical documentation

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/

About

ESPHome custom component for reading P1 data from electricity meters

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 86.7%
  • Python 13.3%