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:
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
Communication rate range: 1200~19200bps, handshaking baud rate:
300bps
Communication protocol: IEC62056-21 E mode, HDLC protocol
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
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.
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.
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?
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.
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.