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