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.
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.
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.
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!
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).
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
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.