New IEC62056-21 Component

Hi,

I created a new ESPHome component for IEC62056-21 compatible meters.

The iec62056 component allows you to read data from any compatible meter. The component requires a serial port and an external optical interface . Data exchange uses an infrared optical channel. Compatible meters are equipped with a characteristic round metal plate with two opto-elements inside.

It supports both bidirectional and unidirectional communication.

  • bidirectional - you need optical interface with IR diode and phototransistor that can send and receive data. This is for modes A,B, and C.
  • unidirectional - only IR phototransistor is required. This is for mode D - meter periodically sends data to the interface.

The component does not support binary encoded data (HDLC)…

Hardware required: Optical interface connected to a serial port of ESP32/ESP8266.

IEC 62056-21 term is used for multiple protocols (with the same hardware layer but different data encoding). The component supports meters that provides ASCII encoded data, something like that:

1-0:15.8.1(00000009999.567*kWh)
1-0:15.8.2(00000000000.000*kWh)
1-0:15.8.3(00000000000.000*kWh)
1-0:15.8.4(00000000000.000*kWh)

The meter must be compatible with this specification IEC 62056-21:2002 | IEC Webstore | cyber security, smart city
(not SML, not DSML)

Detailed description of the component:
https://aquaticus.info/iec62056.html

3 Likes

Hello aquaticus and thank you for your work.

I am triying to get readings from an elecricity meter Type:DTSD545, using an IR sensor connected to ESP8266 d1_mini. The meter is from HOLLEY and claims:

2.2.13.1 Optical communication

  1. Communication rate range: 1200~19200bps, handshaking baud rate:
    300bps
  2. Communication protocol: IEC62056-21 E mode, HDLC protocol
  3. Special handling of optical communication ((IEC readout)
    Optical communication must support mode E and mode A simultaneously,
    and data will return orderly according to given contents and formats.
    Returned configurable data include current energy, demand energy, historical
    energy and real-time information of power grid and so on.
    Returned data can be set separately by PC software.
    Configuration to historical returned data can decrease the amount of
    returned data and improve efficiency

The integrations works, but only up to a point:

[13:24:37][V][iec62056.component:771]: BEGIN
[13:24:37][V][iec62056.component:841]: Begin retry
[13:24:37][D][iec62056.component:232]: Connection start
[13:24:37][V][iec62056.component:252]: Baudrate set to: 300 bps
[13:24:37][V][iec62056.component:771]: SEND_REQUEST
[13:24:37][V][iec62056.component:771]: GET_IDENTIFICATION
[13:24:37][D][uart_debug:114]: >>> 2F:3F:21:0D:0A
[13:24:38][D][iec62056.component:174]: Meter identification: '/HLY5\2DTSD545'
[13:24:38][D][iec62056.component:407]: Meter reported protocol: C
[13:24:38][D][iec62056.component:409]: Meter reported max baud rate: 9600 bps ('5')
[13:24:38][V][iec62056.component:771]: SET_BAUD_RATE
[13:24:38][D][iec62056.component:438]: Using negotiated baud rate 9600 bps.
[13:24:38][D][iec62056.component:452]: Decreased baud rate for retry 1 to: 4800 bps ('4').
[13:24:38][V][iec62056.component:771]: WAIT
[13:24:38][D][uart_debug:114]: >>> 06:30:34:30:0D:0A
[13:24:38][D][iec62056.component:470]: Switching to new baud rate 4800 bps ('4')
[13:24:38][V][iec62056.component:252]: Baudrate set to: 4800 bps
[13:24:38][V][iec62056.component:771]: WAIT_FOR_STX
[13:24:41][E][iec62056.component:268]: No transmission from meter.
[13:24:41][D][iec62056.component:234]: Connection end
[13:24:41][D][iec62056.component:784]: Retry 2 of 2. Waiting 10000 ms before the next try
[13:24:41][V][iec62056.component:771]: WAIT
[13:24:51][V][iec62056.component:771]: BEGIN
[13:24:51][V][iec62056.component:841]: Begin retry
[13:24:51][D][iec62056.component:232]: Connection start
[13:24:51][V][iec62056.component:252]: Baudrate set to: 300 bps
[13:24:51][V][iec62056.component:771]: SEND_REQUEST
[13:24:51][V][iec62056.component:771]: GET_IDENTIFICATION
[13:24:52][D][uart_debug:114]: >>> 2F:3F:21:0D:0A
[13:24:52][D][iec62056.component:174]: Meter identification: '/HLY5\2DTSD545'
[13:24:52][D][iec62056.component:407]: Meter reported protocol: C
[13:24:52][D][iec62056.component:409]: Meter reported max baud rate: 9600 bps ('5')
[13:24:52][V][iec62056.component:771]: SET_BAUD_RATE
[13:24:52][D][iec62056.component:438]: Using negotiated baud rate 9600 bps.
[13:24:52][D][iec62056.component:452]: Decreased baud rate for retry 2 to: 2400 bps ('3').
[13:24:52][V][iec62056.component:771]: WAIT
[13:24:52][D][uart_debug:114]: >>> 06:30:33:30:0D:0A
[13:24:52][D][iec62056.component:470]: Switching to new baud rate 2400 bps ('3')
[13:24:52][V][iec62056.component:252]: Baudrate set to: 2400 bps
[13:24:52][V][iec62056.component:771]: WAIT_FOR_STX
[13:24:55][E][iec62056.component:268]: No transmission from meter.
[13:24:55][D][iec62056.component:234]: Connection end
[13:24:55][D][iec62056.component:780]: Exceeded retry counter.
[13:24:55][D][iec62056.component:822]: Waiting 27898 ms for the next scheduled readout (every 60000 ms).
[13:24:55][V][iec62056.component:771]: WAIT

Relevant sections of the configuration are:

external_components:
  # IEC62056 component
  - source: github://aquaticus/esphome@aquaticus-iec62056
    components: [ iec62056 ]


uart:
  - id: uart_hardware
    rx_pin: GPIO3
    tx_pin: GPIO1
    baud_rate: 300
    data_bits: 7
    parity: EVEN
    stop_bits: 1
    debug:


iec62056:
  update_interval: 60s
  baud_rate_max: 9600
  receive_timeout: 3s
  battery_meter: False
  retry_counter_max: 2
  retry_delay: 10s

The IR sensor is aligned with the electricity meter LEDs and I have checked the connections. I don’t know how to troubleshoot this further.

Any pointers on how to make this work?
Thank you

Hi

The component doesn’t support protocol E (HDLC). It won’t work with your meter.

Logs shows you have successfully connected to the meter but the component is unable to decode binary data of protocol E.

Regards
Aquaticus

Hello,

any other way to get readings from the meter, into Home Assistant, preferaby with ESPHome? I would also consider Tasmota, but I can’t find what could get it working.

Thank you

I have in works of ESP-01 hardware and Iskra MT372. Should it be possible by this component? So far I get nothing:

[E][iec62056.component:268]: No transmission from meter.

From Iskra technical manual: The communication protocol complies with IEC 62056-21, mode C or DLMS-HDLC IEC 62056-46. The communication is serial asynchronous with data transmission rate from 300 bit/sec to 19,200 bit/sec.

It should work.
Check if your serial port configuration in iec62056 component match pins you connected optical interface.
You can use you phone camera to watch IR emitter on your optical interface. You should see IR LED blinking for a moment.

1 Like

Got it working, thank you for the component :slight_smile:

So you are confirming the component works with Iskra MT372 meter?

I’m creating a list of compatible meters and that would help.

Yes, I can confirm it works as intended :+1:

@aquaticus, your meter kit looks very nice!

I would be interested in one, but it’s a bit too expensive to buy the full kit without having a good idea that the sensor is compatible with my meter. I might buy the sensor by itself and test it, but I don’t see an option to buy the housing afterwards if it turns out to work.

Have you considered some kind of deal to encourage testing and validation of new meter types? For instance, selling the housing kit at a discount to the first 2-3 people to verify compatibility of each new brand of meter?

Hi

Many thanks and kudos to you Aquaticus for this project!

I’m trying to get this to work with a Iskra MT372. The very first message seems to have been successful as the reply is correct. After that however, nothing.

It looks odd to me that after using negotiated baud rate, the baud rate seems to have been changed again.

[10:33:30][D][iec62056.component:438]: Using negotiated baud rate 9600 bps.
[10:33:30][D][iec62056.component:453]: Decreased baud rate for retry 3 to: 1200 bps ('2').

Log:

[10:33:29][D][iec62056.component:174]: Meter identification: '/ISk5\2MT372-1032'
[10:33:29][D][iec62056.component:407]: Meter reported protocol: C
[10:33:29][D][iec62056.component:410]: Meter reported max baud rate: 9600 bps ('5')
[10:33:30][D][iec62056.component:438]: Using negotiated baud rate 9600 bps.
[10:33:30][D][iec62056.component:453]: Decreased baud rate for retry 3 to: 1200 bps ('2').
[10:33:30][D][iec62056.component:470]: Switching to new baud rate 1200 bps ('2')
[10:33:31][D][iec62056.component:485]: No STX. Got 0x61
[10:33:31][D][iec62056.component:784]: Retry 4 of 7. Waiting 15000 ms before the next try
[10:33:46][D][iec62056.component:232]: Connection start
[10:33:46][E][iec62056.component:402]: Invalid identification frame
[10:33:46][D][iec62056.component:784]: Retry 5 of 7. Waiting 15000 ms before the next try
[10:34:01][D][iec62056.component:232]: Connection start
[10:34:04][E][iec62056.component:268]: No transmission from meter.

Any tips and ideas are warmly welcome!

Kind regards, Esa

Hi Termitebug

I have same meter but after the first message I loose conneciton.

Would you share your configuration yaml file?

Thank you!

Kind regards, Esa

Hi,

I’ll think about this. Thanks.
What’s your meter type? Maybe it could be possible to tell if it’s compatible.

The meter is by E-Distribuzione. It has the circular window but they don’t give any details about protocols in the documentation that accompanies it.

Hi esajaatinen.

I assume you have tried cleaning the meter probe point surface and positioning the magnet sensor side carefully, as it can be very accurate.

Also try different baud rates (300-9600), as you found from logs.

Very important is to set a correct read interval delay, I had problems with too quick polling time.

I haven’t experimented on how narrow the update interval can be, I’m satisfied between 15 minutes.

Here is my configuration:

esphome:
  name: "esp-reader"
  friendly_name: "ESP-Reader"

esp8266:
  board: esp01_1m

# Enable logging
logger:
  baud_rate: 0

# Enable Home Assistant API
api:
  encryption:
    key: **redacted**

ota:

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "ESP-Reader Fallback Hotspot"
    password: **redacted**

captive_portal:

external_components:
    # IEC62056 component
    - source: github://aquaticus/esphome-iec62056

iec62056:
  update_interval: 15min
  baud_rate_max: 9600
  battery_meter: False
  mode_d: False

uart:
    rx_pin: GPIO03
    tx_pin: GPIO01
    baud_rate: 9600
    data_bits: 7
    parity: EVEN
    stop_bits: 1

sensor:
  - platform: iec62056
    obis: 1.6.0
    name: Positive active maximum demand (A+) total (kW)
    unit_of_measurement: kW
    accuracy_decimals: 3
    device_class: energy
    state_class: total

  - platform: iec62056
    name: Positive active energy (A+) total (kWh)
    obis: 1.8.0
    unit_of_measurement: kWh
    accuracy_decimals: 0
    device_class: energy
    state_class: total_increasing

  - platform: iec62056
    name: Positive active energy (A+) in tariff T1 (kWh)
    obis: 1.8.1
    unit_of_measurement: kWh
    accuracy_decimals: 0
    device_class: energy
    state_class: total_increasing

  - platform: iec62056
    name: Positive active energy (A+) in tariff T2 (kWh)
    obis: 1.8.2
    unit_of_measurement: kWh
    accuracy_decimals: 0
    device_class: energy
    state_class: total_increasing

  - platform: iec62056
    name: Positive active energy (A+) in tariff T3 (kWh)
    obis: 1.8.3
    unit_of_measurement: kWh
    accuracy_decimals: 0
    device_class: energy
    state_class: total_increasing

  - platform: iec62056
    name: Positive active energy (A+) in tariff T4 (kWh)
    obis: 1.8.4
    unit_of_measurement: kWh
    accuracy_decimals: 0
    device_class: energy
    state_class: total_increasing

  - platform: iec62056
    name: Meter address 1
    obis: 0.0.0
    device_class: energy
    state_class: measurement
      
  - platform: iec62056
    name: Meter serial number
    obis: C.1.0
    device_class: energy
    state_class: measurement

  - platform: iec62056
    name: Meter time
    obis: 0.9.1
    state_class: measurement

  - platform: iec62056
    name: Meter date
    obis: 0.9.2
    state_class: measurement

switch:
  - platform: gpio
    pin: GPIO2
    name: Internal LED
    id: led_switch
    internal: True
  - platform: iec62056
    name: 'Readout Trigger'

binary_sensor:
  - platform: iec62056
    id: meter_status
    name: Meter Connection Status
    on_press:
      then:
      - switch.turn_on: led_switch
    on_release:
      then:
      - switch.turn_off: led_switch

Sorry for the long delay, didn’t get the notification on time.

Best Regards,
Kalle

Hi Kalle

No worries. My problem was that the default 3s timeout was just too short for the meter. Increasing it made the communication work… at 300 baud. Any faster doesn’t get proper 0x02 reply, and the integration doesn’t realize it’s getting data ok.

[10:33:31][D][iec62056.component:485]: No STX. Got 0x61

Anyway, this gives me the data I need fast enough so I’m not going to spend more time with it.

Kind regards, Esa

1 Like

I need little help with the hardware design. I’ve attached the optical head to 3V3 output of the Wemos D1 Mini. The chip does not start after that. The test shows the voltage dropped to 1.8V at the 3V3 power bus, so that’s the reason. The optical head is from Aliexpress, uses a UM3232E (analog to MAX232 and MAX242 for bi-directional RS232 communication. I’m tempted to try connecting the head to 5V, but that would mean it will use 5V levels at RX,TX outputs, which could damage ESP8266 chip, which operates on 3.3V levels.
I don’t understand what causes such voltage drop or if it is normal. I know that 3V3 voltage regulator on board of Wemos D1 Mini can be very weak and infra-red LEDs can drain two digit milliamps current, but still it shall be ok.
How you did it with the hardware guys? Thanks in advance! :pray:

UPDATE: Well, the optical head only drains 60-70mA and the 3.3 voltage bus does NOT drop (sorry for the inaccurate measurement at the beginning). If I power on the optic head AFTER ESP8266 loads, it works perfect. But if the optical head is powered on (via 3.3v bus), the ESP does not boot. It is not a power drain problem, but looks like levels at GPIO1/GPIO2 (TX/RX) prevent ESP to start. Very much similar to ESP8266 not functioning when UART connected. Connecting after power up works fine. · Issue #4904 · esphome/issues · GitHub.

UPDATE2: It turned out switching TX and RX connectors to optical head caused ESP826 to boot normally. The optical head also visibly lights the IR led and blinks in sync with “Connection start” of the iec62056 component. Spec for the optical head has mentioned the swapped UART lines (the spec probably oriented to people, who need to know TOWARD which pins they have to connect them, not WHAT they are).

8266 gpios are known to be 5V tolerant (that is not “powering the ESP with 5V”) so don’t worry about this.

I’ve bought a TTL to IR Converter (4 wires, RX / TX / 3.3V / GND) which I will connect to a esp8266 d1 mini board after setting up the IEC62056-21 Component via ESPHome
Unfortunately I have very limited experience with ESPHome and I’m struggling a bit.
After I do the initial basic setup of my board and it connects to my wifi what files do I add to my .yaml.

UPDATE
I’ve copied Termitebug’s yaml file and got things up and running in ESPhome but havent actually connected the reader head yet
This is the head I have


so I’m going to try connecting…
VCC - Red 3.3v
GND - Black - Ground
TXD - White - GPIO1
RXD - Yellow - GPIO3

Which way round do you currently have them connected

Hello together,

I have a small problem with the integration of a Landis+Gyr T550 district heating meter. I use an IR Smart Meter with an ESP01s for reading. I receive the T550 data and can also see it in HA. Unfortunately the T550 sends several data in one package “Data: 6.6(0009.2kW)6.601(0008.8kW)6.33(000.144m3ph)9.4(112.5C&102.5C)” and I don’t know how to get the next data sets like OBIS: 6.6*01.

Best regards
Thomas

substitutions:
  devicename: "esp-01s-fernwaermezaehler"

esphome:
  name: ${devicename}
  friendly_name: esp-01s-fernwaermezaehler
  comment: "Fernwärmezähler"

esp8266:
  board: esp01_1m

# Enable logging
logger:
  baud_rate: 0
  

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

ota:
  password: ""

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "${devicename}"
    password: !secret fallback_password

web_server:
  port: 80
  auth:
    username: !secret web_user
    password: !secret web_password



external_components:
    # IEC62056 component
    - source: github://aquaticus/esphome-iec62056

captive_portal:

uart:
  
  - id: uart_02
    tx_pin: GPIO1
    rx_pin: GPIO3
    baud_rate: 9600 
    data_bits: 7
    parity: EVEN
    stop_bits: 1

# Example platform configuration entry for bidirectional communication
iec62056:
  update_interval: 600s
  baud_rate_max: 2400
  battery_meter: True
  uart_id: uart_02


sensor:
  - platform: wifi_signal
    name: "${devicename} WiFi Signal"
    device_class: signal_strength
    update_interval: 600s
  - platform: iec62056
    name: "LUGCUH50 Zaehlerstand"
    obis: "6.8"
    unit_of_measurement: MWh
    accuracy_decimals: 3
    device_class: energy
    state_class: total_increasing
  - platform: iec62056
    name: "LUGCUH50 heizleistung_max"
    obis: "6.6"
    unit_of_measurement: kWh
    accuracy_decimals: 1
    device_class: energy
    state_class: total_increasing
  - platform: iec62056
    name: "LUGCUH50 Tem. Vorlauf_max"
    obis: "9.4*01"
    unit_of_measurement: C°
    accuracy_decimals: 1
    device_class: temperature
    state_class: total_increasing
  - platform: iec62056
    name: "LUGCUH50 Betriebsstunden Flow"
    obis: "6.31"
    unit_of_measurement: h
    accuracy_decimals: 1
    device_class: duration
    state_class: total_increasing

  - platform: template
    id: LUGCUH50_total_Flow
    name: "LUGCUH50 total Flow"
#    obis: "6.26"
    unit_of_measurement: mÂł
    accuracy_decimals: 1
    device_class: volume
    state_class: total_increasing
    filters:
      - multiply: 1
  - platform: template
    name: "LUGCUH50 durchlauf_max"
#    obis: "6.33"
    unit_of_measurement: mÂłh
    accuracy_decimals: 1
    device_class: volume
    state_class: total_increasing
    filters:
      - multiply: 1