ESPHome Energy meter reading from P1/HAN port

I thought i would share some findings and my solution on reading data from my energy meter using the HAN / P1 port.

I found a hardware kit “SmartyReader” from weigu which i purchased. It is based on Wemos D1 Mini Pro and can be extended in many variations.
The code weigu uses is for encrypted data, which is not active in Swedish meters.

So i based my configuration on esphome code already existing and created by @svanstrom.

The hardware from weigu is a bit different and rather minimalistic (which is good) so it is dependant on setting the flag inverted on the serial port instead of relying on a transistor to invert.
This setting was just made available in esphome version 2021.12.0 for ESP8266 devices.

Instructions

Download the code for esphome-p1reader follow the steps to set up the secrets as described in the instructions for p1reader then do the following adjustments in the yaml file for SmartyReader P1:

  1. Set the board to Wemos D1 mini pro
board: d1_mini_pro
  1. Adjust the UART section to invert the RX pin (removed TX pin config since it is not used).
uart:
    id: uart_bus
    rx_pin:
      number: 3
      inverted: true
    baud_rate: 115200

Put the .yaml file and the .h file in your esphome directory and upload.

Then it is good to go, 26 sensors populated and works just great. :slight_smile:

Here is a glimpse from some initial testing on visualising the data - the sensors can also be added in to the energy dashboard in home assistant.

Lovelace yaml from this example can be found here:
Example Home assistant lovelace YAML for presenting consumption energy data from HAN port (github.com)

9 Likes

In some cases for cold startup of the wemos card there seem to be too little power output to boot fully.
This could be showing up that the wemos is not booting nor connecting, or connecting to wifi but not parsing and passing the data received on the rx pin…

My power meter is the infamous Landis Gyr E360. But i do not experience any issues that it stop sending data after a period of time, as some users has reported.

I managed to override this by plugging in a usb powerbank to the micro usb port on the wemos and then hit the reset button. Once it is up and running i can unplug the powerbank and it continues to run without problems OTA and normal reboots works fine with the power provided from the meter.

I noticed in weigu:s code that he has a 2-second delay in the setup function of the arduino code.
I have added a delay in the on_boot section in to my esphome yaml file, but i have not been able to test if it makes any difference for this problem.

esphome:
  name: esp-p1reader
  platform: ESP8266
  board: d1_mini_pro
  on_boot:
    priority: -100.0
    then:
      - delay: 2s
  includes:
    - p1reader.h

I followed your description above with the hardware from weigu and your code. I had the same problem with unreliable cold start but it works fine after a kick from a powerbank. No problems with OTA or reboots.
Many thanks for sharing your design and experiences.

Just wanted to write here and thank you for your summary. I got everything up and running real smooth thanks to this!

I noticed now after a day or two that my energy card has not populated any data. Any tips from you guys?

Thanks for this post, did exactly the same setup and it works perfectly, on a Landis+Gyr meter (Eon). No problem with the booting so far.

1 Like

This looks really tempting but a few hours of tinkering cannot get the code to work with a Kamstrup module that uses an RJ-45 for connector and only two pins. 1 comm and 2 gnd. Any tips would be appreciated.