ESPHome Smart Meter OBIS D0 Component

Are you guys using that with an ESP8266 or ESP32?

I tried two different ESP8266 boards and got “Connection error occurred: EOF received” in logs.

Update:
I took the eZB DD3 template which has a lot of lines of code. After commenting out the most of it, I could get it working with a esp8266.
Maybe too less power to be able to use so much sensors?

I’m using an ESP32. Indeed, the ESP8266 has to less resources (RAM) to run a configuration with a lot of sensors.

That’s true. I reduced it to a minimum for now and it’s working!

Hi Steffen,

First of all, thanks a lot for your excellent ESPHome OBIS implementation!

I just recently got a eBZ DD3 smart meter and had to integrate it into HA of course. Stumbled across your github, figured, why use it when there’s a native ESPHome SML component… Took me a day of cursing to realize that SML != OBIS… Lol. Didn’t realize at first that there’re different versions of the DD3 (although the manual clearly states it).

Anyway, just wanted to let you and others know that the ESP8266 (I’m using a NodeMCU v2) is well capable of dealing with all the sensors. I did have plenty of issues with incomplete telegrams in the beginning as well, but finally sorted them out.

  1. Placement of the photo diode on top of the DD3 is very important. 1mm off (in X/Y/Z) and it might not work properly.

  2. After everything was working fine with my rigged setup, I installed the reader assembly into my 3D printed housing (wll publish it later for anyone who’s interested) and it was working quite unreliably, although placement of the phote diode was perfect. Thought it was an intermittent issue with a broken wire or something like that, but after replacing everything, it was still not working properly. Then I remembered that I’ve blocked the port for the sending LED of the reader head with some tape with my first test setup, just for good measures. Turned out when the sending LED is not connected to the ESP, it would always emit light. Dunno if that was causing interference with the receiving diode or if the DD3 got confused. After connecting it, all was golden again (or just block it with tape)…

  3. Not sure if this is important, but I guess it’s better to use the hardware UART. On the ESP8266 that’s GPIO3 for RX and GPIO1 for TX. Just make sure to use UART1 for logging. Also, I set the receive buffer to 512 (again, no clue if this is required), since the max telegram size is ~400 bytes if I’m not mistaken.

I’ve included my yaml below for anyone who might be interested (basically the one Steffen provided)…

Thanks!

esphome:
  name: eg-flur-powermeter

esp8266:
  board: nodemcuv2

# Enable logging
logger:
  level: DEBUG
  hardware_uart: UART1

# Enable Home Assistant API
api:
  encryption:
    key: "secret"

ota:
  password: "secret"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  domain: .mydomain.com

external_components:
  - source: github://mampfes/esphome_obis_d0

uart:
  id: uart_bus
  tx_pin: GPIO1 # hardware_uart
  rx_pin: GPIO3 # hardware_uart
  rx_buffer_size: 512
  baud_rate: 9600
  data_bits: 7
  parity: EVEN
  stop_bits: 1
  # debug:
    # direction: BOTH
    # dummy_receiver: false
    # after:
      # delimiter: "\r\n"
    # sequence:
      # - lambda: UARTDebug::log_string(direction, bytes);

obis_d0:
  id: sm_obis
  uart_id: uart_bus

sensor:
  - platform: obis_d0
    name: "Consumed Energy"
    obis_d0_id: sm_obis
    obis_code: "1-0:1.8.0*255"
    unit_of_measurement: kWh
    accuracy_decimals: 4
    state_class: total_increasing
    device_class: energy
    value_regex: "\\d{6}\\.\\d{8}\\*kWh"

  - platform: obis_d0
    name: "Power"
    obis_d0_id: sm_obis
    obis_code: "1-0:16.7.0*255"
    unit_of_measurement: W
    accuracy_decimals: 2
    state_class: measurement
    device_class: power
    value_regex: "-?\\d{6}\\.\\d{2}\\*W"

  - platform: obis_d0
    name: "Power L1"
    obis_d0_id: sm_obis
    obis_code: "1-0:36.7.0*255"
    unit_of_measurement: W
    accuracy_decimals: 2
    state_class: measurement
    device_class: power
    value_regex: "-?\\d{6}\\.\\d{2}\\*W"

  - platform: obis_d0
    name: "Power L2"
    obis_d0_id: sm_obis
    obis_code: "1-0:56.7.0*255"
    unit_of_measurement: W
    accuracy_decimals: 2
    state_class: measurement
    device_class: power
    value_regex: "-?\\d{6}\\.\\d{2}\\*W"

  - platform: obis_d0
    name: "Power L3"
    obis_d0_id: sm_obis
    obis_code: "1-0:76.7.0*255"
    unit_of_measurement: W
    accuracy_decimals: 2
    state_class: measurement
    device_class: power
    value_regex: "-?\\d{6}\\.\\d{2}\\*W"

  - platform: obis_d0
    name: "Voltage L1"
    obis_d0_id: sm_obis
    obis_code: "1-0:32.7.0*255"
    unit_of_measurement: V
    accuracy_decimals: 1
    state_class: measurement
    device_class: voltage
    value_regex: "\\d{3}\\.\\d{1}\\*V"

  - platform: obis_d0
    name: "Voltage L2"
    obis_d0_id: sm_obis
    obis_code: "1-0:52.7.0*255"
    unit_of_measurement: V
    accuracy_decimals: 1
    state_class: measurement
    device_class: voltage
    value_regex: "\\d{3}\\.\\d{1}\\*V"

  - platform: obis_d0
    name: "Voltage L3"
    obis_d0_id: sm_obis
    obis_code: "1-0:72.7.0*255"
    unit_of_measurement: V
    accuracy_decimals: 1
    state_class: measurement
    device_class: voltage
    value_regex: "\\d{3}\\.\\d{1}\\*V"

  - platform: obis_d0
    name: "Time of operation"
    obis_d0_id: sm_obis
    obis_code: "0-0:96.8.0*255"
    format: hex
    disabled_by_default: true
    entity_category: diagnostic
    value_regex: "[0-9a-fA-F]{8}"

1 Like

Thanks for the info!

Hi, I am a new user of home assistant and I’d like to get the results of my eBZ DD3 Drehstromzähler too. My setup differs, I do use an ir sensor connected via USB to my computer. I can access the results of the smart meter. A simple ‘cat /dev/ttyUSB0’ shows the results, like “1-0:1.8.0255(000229kWh)”. Of course, my smart meter does not yet show all data, I am still waiting for the pin.
Can you please help me what do I have to change in your code to get the results from the serial port without using ESPHome?

I tried the setup at Reading data from a smart meter speaking D0, but do only get errors, yaml check already complains.

As I said, I am new to home assistant and will probably need some more help than an experienced user.

Hi Frank,

No offense and don’t get me wrong, but don’t you think it would be easier to just spend 30 bucks on an UART sensor and an ESP8266 to have a working template instead of asking for detailed help on a kinda different subject in apparently the wrong thread?

Just my 2 cents…

I agree, this sounds like a completely different project. What you can do is to try to reuse the code from SmartMeterD0.h/.cpp.

Sorry for asking here, but for me it looked like it’s an “easy” task to adapt the configuration.yaml to use a serial port instead of the esp8266 stuff.
On the other hand, I#d like to learn about home assistant and saw that this project uses a complete other configuration.yaml syntax than the one mentioned. My hope was to understand the project as good as necessary to adopt the configuration.yaml to use a serial port instead of ESP8266.
And reusing available resources is imho better than buying new ones.

Thanks for the component!
Works perfectly!
Any chance to get this included in esphome?

Hi, do you mean as an official component of esphome (instead of an external component)?

Well, I have some experience with that and it always caused me a lot of extra work, with less flexiblity. As I do this in my rare spare time I don’t want to spend more time at the moment. Sorry.

1 Like

Quick note for anyone trying this on an esp8266:
The regex checking is very slow, when using it for all sensors (in my case 9 sensors, 2 for energy, 4 for current power (total + 1 for each phase), 3 for voltage on each phase), the esphome device (esp8266) loses Wifi from time to time and will fail to show logs in esphome and also fail to update via OTA.

Easiest solution is just to use the regex checking on the “important” sensors (e.g. the energy sensors) and not use it on the instantaneous sensors (power, voltage) as those don’t tend to cause issues if they might show a wrong value once in a while (although so far it seems to be rock-solid)
(or of course you could use an esp32 to get the required horse power :smiley: )

Hi there,

nice component, worked directly out of the box - thank you.

But I have a problem,
the entity for “power” does not provide a value.
yes, i unlocked it with the PIN and the actual power value
is shown on die Display of the smart meter.
The software runs on an d1 mini (az delivery).

Any suggestions?

@JWSK This could have several reasons:

  • Does your meter provide 1-0:16:7.0? Which meter do you use?
  • Is the value_regex matching? You can (temporarily) remove the value_regex to check whether this causes the problem.

Do you have access to the esphome logs? If yes you can check the available OBIS codes and the format in the log output.


So this is the Smartmeter.
for testing I deactivated the regex parameter

those are the sensors:

sensor:

  • platform: obis_d0
    name: “Consumed Energy”
    obis_d0_id: my_sm
    obis_code: “1-0:1.8.0*255”
    unit_of_measurement: kWh
    accuracy_decimals: 0
    state_class: total_increasing
    device_class: energy
    value_regex: “\d{6}\.\d{4}\*kWh”

  • platform: obis_d0
    name: “Provided Energy”
    obis_d0_id: my_sm
    obis_code: “1-0:2.8.0*255”
    unit_of_measurement: kWh
    accuracy_decimals: 0
    state_class: total_increasing
    device_class: energy
    value_regex: “\d{6}\.\d{4}\*kWh”

  • platform: obis_d0
    name: “Power”
    obis_d0_id: my_sm
    obis_code: “1-0:16.7.0*255”
    unit_of_measurement: W
    accuracy_decimals: 0
    state_class: measurement
    device_class: power
    #value_regex: “-?\d{6}\*W”`

and this is one logfile segment:

[14:39:59][D][obis_d0:157]: Identification: LOG5XXxXXXXXXXXXXXXXXXXXXXX
[14:39:59][D][obis_d0:201]: OBIS info: 1-0:96.1.0255 → 001LOGXXXXXXXXXXX
[14:39:59][D][obis_d0:201]: OBIS info: 1-0:1.8.0
255 → 034914.9953kWh
[14:39:59][D][sensor:093]: ‘Consumed Energy’: Sending state 34914.99609 kWh with 0 decimals of accuracy
[14:39:59][D][obis_d0:201]: OBIS info: 1-0:2.8.0
255 → 006139.1373kWh
[14:39:59][D][sensor:093]: ‘Provided Energy’: Sending state 6139.13721 kWh with 0 decimals of accuracy
[14:39:59][D][obis_d0:201]: OBIS info: 1-0:0.2.0
255 → ver.03,432F,20170504
[14:39:59][D][obis_d0:201]: OBIS info: 1-0:96.90.2255 → 0F66
[14:39:59][D][obis_d0:201]: OBIS info: 1-0:97.97.0
255 → 00000000
[14:39:59][W][component:204]: Component obis_d0 took a long time for an operation (0.22 s).
[14:39:59][W][component:205]: Components should block for at most 20-30ms.

so there is no 1-0:16:7.0, how could I fix it? I am sure the energy supplier won’t install a new smartmeter.

Thanks for your help


Maybe thats is the problem.
INF on has to be activated after pin input.

I will try when I visit the smart meter next Time :slight_smile:

Yes, that’s the problem.

FYI: My smart meter (different vendor) has the following problem: It forgets the INF configuration when there is a power outage. So I always have to reconfigure…

Hello mampfes,

thanks for your help.

i will check about the blackouts there.
I already know the the entered pin stays active after blackout.

Give me some days and I will be safe to say what is possible and what not

We were right, it was the inf on parameter!
Thank you!

Dear all,
thx for this nice component - unfortunately it does not work for me :frowning:
Hope you could help me: No matter what I do, I always get
"[22:30:00][D][obis_d0:152]: abort"
in the logger. I tried different things, but apparently the data is not comming through. Using NodeMCUv2 (ESP 8266) with the exact example as given by judges.
Any idea where I should be looking at?

Update: Found that my meter uses SML and code 1_8D_0P_N_1S for serial coms.
Meter name: ebz dd3 2r06 dta smz1
How do I activate that in the above example? Thx!

Update 2: The link provided by mampfes in the post below was helpful (THX!) - now the IR readout works without problems.
Further reference: https://www.mittelstedt.net/?tag=esphome (german website)

Thx!