Universal P1 Port Dongle for Smart Meter

Moderator: leecollings

Post Reply
User avatar
waltervl
Posts: 7027
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2026.3
Location: NL
Contact:

Universal P1 Port Dongle for Smart Meter

Post by waltervl »

This is just for information. No questions, but you are free to ask one on this subject.

I got a smart electricity meter recently (one of the last to be transfered in the Netherlands :) ). To connect my smart meter to Domoticz I decided to use the Universal P1 Port Dongle for Smart Meter - ESP32-S3 and have it send the P1 telegrams over wifi.
It can be bought at tinytronics.nl for a small fee (currently in backorder).

There is a HA integration availabale but no Domoticz as the firmware in https://github.com/Leotro-Engineering/U ... ort-Dongle does not support it yet.

So I made a PR https://github.com/Leotro-Engineering/U ... gle/pull/9 that adds a ESPHOME configuration that forwards the P1 telegram over wifi on port 6638 (configurable). In Domoticz you can add the P1 meter by entering the IP adress and the port for the "P1 smart meter with LAN interface" hardware gateway (see also https://wiki.domoticz.com/Dutch_DSMR_sm ... th_P1_port )

After installing ESPHOME and using the example yaml file you have to modify it to with the wifi SSID and password to connect to your homenetwork. Then you can create the firmware for the Dongle and flash the device over USB for the first time.
Note: To program the module for the first time, it must be put into programming mode. Connect the module to the computer, hold down the boot button, and briefly press the reset button. Then release the boot button.
After the first time flashing the firmware you can update over Wifi if needed.

When flashing is done you can connect the dongle with a special RJ12 6P6C P1 Port Cable to the P1 Port on the smart meter, these can be bought at tinytronics.nl too.
The dongle will be powered by the P1 port so no need to add an extra USB power supply. The dongle can also relay the P1 telegram messages over the other P1 port so you can use an extra P1 splitter when you have to install an extra dongle eg for a specific home battery or other energy control device.

The firmware also has a small webpage in it that you can reach at http://<Dongle-IP> so you can see if it works.
On your wifi router it should appear as device universal-p1-port-dongle-wifi
If it cannot connect to your home wifi you can have your phone or laptop connect to it as it serves then as fallback hotspot. Then you can set your home network SSID and password.

.
universal-p1-port-dongle-esp32-s3-600x600h.jpg
universal-p1-port-dongle-esp32-s3-600x600h.jpg (30.75 KiB) Viewed 1032 times
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Gravityz
Posts: 761
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2026.3
Location: Netherlands
Contact:

Re: Universal P1 Port Dongle for Smart Meter

Post by Gravityz »

Nice.
i currently have the rfxtrx433xl which has a p1 meter.
however after a recent meter swap i get an invalid data error once in a while.
nothing serious but when i get the error the reading stops so that is irritating.
i was about to order the homewizard p1 meter but this looks more promising because it can be customized.

in the current setup i have a P1 energy meter which shows the total energy.
the tarif1 and 2 counters are buried in the report section
the tarif1 and 2 are not seperate devices so i made them myself so i can instantly see the counters.

looking at this esphome code it is the other way around, devices for tarif 1 and 2 are created through mqtt-ad but the total energy device is not.
is this correct.
if this is the case tan i think a device ehich shows the total energy can be added without any problems.

love to hear from you.

thanks
User avatar
waltervl
Posts: 7027
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2026.3
Location: NL
Contact:

Re: Universal P1 Port Dongle for Smart Meter

Post by waltervl »

Oh, I did nothing special with ESPHome, just forwarded the P1 telegram message to Domoticz over wifi and Domoticz will do the rest.

I did not use the MQTT code. As Domoticz has excellent P1 device integration on the telegram I did not had the need to change something.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Gravityz
Posts: 761
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2026.3
Location: Netherlands
Contact:

Re: Universal P1 Port Dongle for Smart Meter

Post by Gravityz »

ok. i understand now. i thought the sensors would also be discovered by mqtt-ad if i added mqtt but i understand now the solution is way easier. will order this to see if i can make it work

thanks
Gravityz
Posts: 761
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2026.3
Location: Netherlands
Contact:

Re: Universal P1 Port Dongle for Smart Meter

Post by Gravityz »

got it up and running. getting data when looking on the webserver.
however when configuring in domoticz as p1 meter with lan interface nothing happens
i create the entry but no new devices are discovered. i thought it would create new devices besides the p1 ones i already have (through rfxtrx433)
accept new hardware is on.
Gravityz
Posts: 761
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2026.3
Location: Netherlands
Contact:

Re: Universal P1 Port Dongle for Smart Meter

Post by Gravityz »

ok. got it working with the help of AI. all domoticz devices are created now
it seems the code you shared can not handle both dsmr (local devices in the gui) and stream_server.

to get both working a the same time you have to use different uarts for dsmr and stream_server.

still i find it strange that i had to change the code to get it to work while you got it working on your end.

maybe i created the problem by enabling the webserver, not sure

before i migrate to the new p1 i wil let it run for a couple of weeks.
i made some improvements to the code.
you now see when data is being send(both in gui as well as green led on the p1 hardware) and it also shows if there is a client connected
User avatar
waltervl
Posts: 7027
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2026.3
Location: NL
Contact:

Re: Universal P1 Port Dongle for Smart Meter

Post by waltervl »

I indeed have the same issue that I did not see the webserver data change, only in Domoticz. Please share your ESPHome yaml file so I can update it with your your changes.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Gravityz
Posts: 761
Joined: Wednesday 16 December 2015 19:13
Target OS: NAS (Synology & others)
Domoticz version: 2026.3
Location: Netherlands
Contact:

Re: Universal P1 Port Dongle for Smart Meter

Post by Gravityz »

here it is.
seems to working very stable.
all the devices are created in domoticz and you can also use the local web gui
i am using esphome 2026.4.5
i believe when going to 2026.11 there is a native stream_server implemented

Code: Select all

esphome:
  name: esp32-p1-wifi-dongle
  friendly_name: ESP32-P1-wifi-dongle

esp32:
  board: esp32-s3-devkitc-1
  framework:
    type: esp-idf

# Enable logging
logger:

ota:
  - platform: esphome
    password: "xxxxxxxxxxxxxxxxxxxxxx"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  min_auth_mode: WPA2
  power_save_mode: none

  manual_ip:
    static_ip: 192.168.1.149
    gateway: 192.168.1.1
    subnet: 255.255.255.0

api:
  reboot_timeout: 0s
  encryption:
    key: "xxxxxxxxxxxxxxxxxxxxxxx"


web_server:
  local: true
  include_internal: True
  version: 3

button:
  - platform: restart
    id: restart_button
    name: "Restart"
    entity_category: diagnostic

#captive_portal:

# add external stream_server component
external_components:
  - source: github://oxan/esphome-stream-server
    components: [ stream_server ]

# 2 seperate UART-busses on the same physical RX pin(GPIO1) creates a hw seperation between dsmr and streamserver
uart:
  - id: uart_voor_esphome_dsmr
    baud_rate: 115200
    rx_buffer_size: 1700
    rx_pin:
      number: GPIO1
      allow_other_uses: true   # <--- Solves dual usage error

  - id: uart_voor_domoticz_stream
    baud_rate: 115200
    rx_buffer_size: 1700
    rx_pin:
      number: GPIO1
      allow_other_uses: true   # <--- Solves dual usage error

  - id: uart_tx_p1
    tx_pin: GPIO42
    baud_rate: 115200

# connect stream_server exclusive to second virtual uart  port and creates remote acces on port 6638
stream_server:
  - uart_id: uart_voor_domoticz_stream
    port: 6638
    id: ss


output:
  - platform: gpio
    pin:
      number: GPIO9
      inverted: false
    id: onboard_led


dsmr:
  request_pin: GPIO2
  request_interval: 2s
  uart_id: uart_voor_esphome_dsmr   # <--- has it's own buffer
  max_telegram_length: 3000
  crc_check: true

sensor:
  - platform: dsmr
    energy_delivered_tariff1:
      name: Energy Delivered Tariff 1
      state_class: total_increasing
      icon: "mdi:meter-electric"

    energy_delivered_tariff2:
      name: Energy Delivered Tariff 2
      state_class: total_increasing
      icon: "mdi:meter-electric"

    energy_returned_tariff1:
      name: Energy Returned Tariff 1
      icon: "mdi:lightning-bolt"

    energy_returned_tariff2:
      name: Energy Returned Tariff 2
      icon: "mdi:lightning-bolt"

    power_delivered:
      name: Power Delivered
      icon: "mdi:lightning-bolt-circle"
      on_value: 
        then:
          - script.execute: blink_data_received

    power_returned:
      name: Power Returned
      icon: "mdi:lightning-bolt-circle"

    electricity_failures:
      name: Electricity Failures
      icon: "mdi:alert"

    electricity_long_failures:
      name: Electricity Long Failures
      icon: "mdi:alert"

    voltage_l1:
      name: Voltage L1
      icon: "mdi:flash-triangle"

    voltage_l2:
      name: Voltage L2
      icon: "mdi:flash-triangle"

    voltage_l3:
      name: Voltage L3
      icon: "mdi:flash-triangle"

    current_l1:
      name: Current L1
      icon: "mdi:current-ac"

    current_l2:
      name: Current L2
      icon: "mdi:current-ac"

    current_l3:
      name: Current L3
      icon: "mdi:current-ac"

    power_delivered_l1:
      name: Power Delivered L1
      icon: "mdi:lightning-bolt-circle"

    power_delivered_l2:
      name: Power Delivered L2
      icon: "mdi:lightning-bolt-circle"

    power_delivered_l3:
      name: Power Delivered L3
      icon: "mdi:lightning-bolt-circle"

    power_returned_l1:
      name: Power Returned L1
      icon: "mdi:lightning-bolt-circle"

    power_returned_l2:
      name: Power Returned L2
      icon: "mdi:lightning-bolt-circle"

    power_returned_l3:
      name: Power Returned L3
      icon: "mdi:lightning-bolt-circle"

    gas_delivered:
      name: Gas Delivered
      icon: "mdi:gas-burner"

  - platform: wifi_signal
    name: "-WiFi Signal Sensor"
    update_interval: 60s
    
    icon: "mdi:wifi"
  - platform: internal_temperature
    name: "-ESP32 CPU Temperatuur"
    icon: "mdi:thermometer"

text_sensor:
  - platform: dsmr
    identification:
      name: Identification
      icon: "mdi:identifier"
    p1_version:
      name: Version

    electricity_tariff:
      name: Tariff
      icon: "mdi:currency-eur"
      on_value:
        then:
          - lambda: |-
              if (x == "0001") {
                id(tariff_text).publish_state("Low");
              } else if (x == "0002") {
                id(tariff_text).publish_state("High");
              }

  - platform: template
    id: tariff_text
    name: "Tariff Level"
    icon: "mdi:currency-eur"

  # Keep telegram text for optional wired relay path
  - platform: dsmr
    telegram:
      name: "telegram"
      on_value:
        then:
          
          - lambda: |-
              id(telegram) = x;

binary_sensor:
  - platform: template
    id: Data_Received
    name: "Data-Received"
    icon: "mdi:cable-data"
    lambda: |-
      return false;

  - platform: stream_server
    stream_server: ss
    connected:
      name: "Data-Client-Connected"
      icon: "mdi:wifi"


script:
  - id: blink_data_received
    mode: single
    then:
      - output.turn_on: onboard_led
      - binary_sensor.template.publish:
          id: Data_Received
          state: ON
      - delay: 50ms
      - output.turn_off: onboard_led
      - binary_sensor.template.publish:
          id: Data_Received
          state: OFF


globals:
  - id: telegram
    type: std::string
    restore_value: no
User avatar
waltervl
Posts: 7027
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2026.3
Location: NL
Contact:

Re: Universal P1 Port Dongle for Smart Meter

Post by waltervl »

Thank you!
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply