New IEC62056-21 Component

Hi
can you post debug log with data that is received from the device?

Hello aquaticus, enclose the logs direkt from ESPHOme HA Window,or are there more detailed logs on file system?
For a better understanding, i tried to extract the two enteties like “LUGCUH50 total Flow” via a text sensor. But even with this I only get the value from the first OBIS

  - platform: iec62056
    id: LUGCUH50_6_8
    name: "LUGCUH50 6.8"
    obis: "6.26"
    internal: True
    on_value:
      lambda: |-
        std::string str = id(LUGCUH50_6_8).state;
        int startPos = str.find_first_of("6.26") + 4; // Find the position of the first space and add 1
        int endPos = str.find_first_of("*m") + startPos; // Find the position of the next space 
        if (endPos > 0) {
         std::string figureStr = str.substr(startPos, endPos); // Wert extrahieren
         float fcc1 = std::stof(figureStr);
         id(LUGCUH50_total_Flow).publish_state((float)fcc1);
         ESP_LOGI("IEC62056.component","converted STR: %s to Dez. %u",figureStr, fcc1);
        }

Thanks

[11:41:55][D][iec62056.component:174]: Meter identification: '/LUGCUH50'
[11:41:55][D][iec62056.component:412]: Meter reported protocol: B
[11:41:55][D][iec62056.component:414]: Meter reported max baud rate: 2400 bps ('C')
[11:41:55][D][iec62056.component:443]: Using negotiated baud rate 2400 bps.
[11:41:56][D][iec62056.component:475]: Switching to new baud rate 2400 bps ('C')
[11:41:56][D][iec62056.component:487]: Meter started readout transmission
[11:41:56][D][iec62056.component:529]: Data: 6.8(0007.772*MWh)6.26(00234.96*m3)9.21(00258920)
[11:41:56][D][iec62056.component:625]: Set sensor 'LUGCUH50 Zaehlerstand' for OBIS '6.8'. Value: 7.772000
[11:41:56][D][iec62056.component:529]: Data: 6.26*01(00154.46*m3)6.8*01(0004.308*MWh)
[11:41:57][D][iec62056.component:529]: Data: F(0)9.20(68583706)6.35(15*m)
[11:41:57][D][iec62056.component:529]: Data: 6.6(0009.2*kW)6.6*01(0008.8*kW)6.33(000.144*m3ph)9.4(112.5*C&102.5*C)
[11:41:57][D][iec62056.component:625]: Set sensor 'LUGCUH50 heizleistung_max' for OBIS '6.6'. Value: 9.200000
[11:41:57][D][iec62056.component:529]: Data: 6.31(0014549*h)6.32(0000010*h)9.22(R)9.6(000&00258920&0&000&00258920&0)
[11:41:57][D][iec62056.component:625]: Set sensor 'LUGCUH50 Betriebsstunden Flow' for OBIS '6.31'. Value: 14549.000000
[11:41:58][D][iec62056.component:529]: Data: 9.7(20000)6.32*01(0000000*h)6.36(01-01&00:00)6.33*01(000.144*m3ph)
[11:41:58][D][iec62056.component:529]: Data: 6.8.1()6.8.2()6.8.3()6.8.4()6.8.5()
[11:41:58][D][iec62056.component:529]: Data: 6.8.1*01()6.8.2*01()6.8.3*01()
[11:41:58][D][iec62056.component:529]: Data: 6.8.4*01()6.8.5*01()
[11:41:58][D][iec62056.component:529]: Data: 9.4*01(112.5*C&102.5*C)
[11:41:58][D][iec62056.component:625]: Set sensor 'LUGCUH50 Tem. Vorlauf_max' for OBIS '9.4*01'. Value: 112.500000
[11:41:58][D][iec62056.component:529]: Data: 6.36.1(2024-01-08)6.36.1*01(2023-12-07)
[11:41:59][D][iec62056.component:529]: Data: 6.36.2(2023-03-25)6.36.2*01(2023-03-25)
[11:41:59][D][iec62056.component:529]: Data: 6.36.3(2023-03-28)6.36.3*01(2023-03-28)
[11:41:59][D][iec62056.component:529]: Data: 6.36.4(2023-03-28)6.36.4*01(2023-03-28)
[11:41:59][D][iec62056.component:529]: Data: 6.36.5()6.36*02(01&00:00)9.36(2024-05-20&11:38:12)9.24(0.6*m3ph)
[11:42:00][D][iec62056.component:529]: Data: 9.17(0)9.18()9.19()9.25()
[11:42:00][D][iec62056.component:529]: Data: 9.1(0&1&0&0017&CECV&CECV&1&5.22&5.22&F&101008&1>1>04&08&0&00&:5&00&20)
[11:42:00][D][iec62056.component:529]: Data: 9.2(&&)9.29()9.31(0005478*h)
[11:42:00][D][iec62056.component:529]: Data: 9.0.1(00000000)9.0.2(00000000)9.34.1(000.00000*m3)9.34.2(000.00000*m3)
[11:42:01][D][iec62056.component:529]: Data: 8.26.1(00000000*m3)8.26.2(00000000*m3)
[11:42:01][D][iec62056.component:529]: Data: 8.26.1*01(00000000*m3)8.26.2*01(00000000*m3)
[11:42:01][D][iec62056.component:529]: Data: 6.26.1()6.26.4()6.26.5()
[11:42:01][D][iec62056.component:529]: Data: 6.26.1*01()6.26.4*01()6.26.5*01()0.0(00258920)
[11:42:01][D][iec62056.component:529]: Data: !
[11:42:01][D][iec62056.component:502]: Total connection time: 11223 ms
[11:42:01][D][iec62056.component:507]: BCC verification is OK
[11:42:01][D][iec62056.component:234]: Connection end
[11:42:01][E][iec62056.component:646]: Not all sensors received data from the meter. The first one: OBIS '6.26'. Verify sensor is defined with valid OBIS code.
[11:42:01][D][iec62056.component:519]: Start of sensor update
[11:42:01][D][sensor:093]: 'LUGCUH50 Betriebsstunden Flow': Sending state 14549.00000 h with 1 decimals of accuracy
[11:42:01][D][sensor:093]: 'LUGCUH50 Tem. Vorlauf_max': Sending state 112.50000 C° with 1 decimals of accuracy
[11:42:01][D][sensor:093]: 'LUGCUH50 heizleistung_max': Sending state 9.20000 kWh with 1 decimals of accuracy
[11:42:01][D][sensor:093]: 'LUGCUH50 Zaehlerstand': Sending state 7.77200 MWh with 3 decimals of accuracy
[11:42:01][D][iec62056.component:562]: End of sensor update
[11:42:01][D][iec62056.component:828]: Waiting 588708 ms for the next scheduled readout (every 600000 ms).

I do not understand why the meter sends some data without end of line character.
Can you try to decrease maximum serial speed by setting baud_rate_max to 1200?
Check if you still got 6.26*01(00154.46*m3)6.8*01(0004.308*MWh) in one line.
It should be like:

6.26*01(00154.46*m3)
6.8*01(0004.308*MWh)

That way the parser properly extracts data for specific OBIS code.

By the way it you want to get data for 6.26 create text sensor and set group to 0. You should get the entire line not just the first value between ().
See https://aquaticus.info/iec62056.html#text-sensor

Hi, unfortunately it seems that the T550 only transmits at 2400 boad. If I set the max boad to 1200 I do not receive any data from the device.

It was an attempt to get the whole package to obis 6.8 as string and then to extract the other values myself. Many thanks for the hint, thats the solution. Get the entrie line and extract by myself. Thanks for the qick replay and the hint with group 0.

As per your suggestion above for TW-BS I’ve tried to do the same BUT FAILED, can you steer me in the right direction please
I added this to my ESPHome yaml

Note: This is a meter I’m currently testing with the possibility of using on 1 of my Solar arrays.

# Data record:
# 1.6.0(001.860*kW)(24-05-11,12:00)

  - platform: iec62056
    obis: 1.6.0
    group: 2 
    name: Date time

  - platform: iec62056
    obis: 1.6.0
    group: 1 
    name: Value

  - platform: iec62056
    obis: 1.6.0
    group: 0 
    name: The entire record

But it failed to verify

INFO ESPHome 2024.5.2
INFO Reading configuration /config/esphome/esphome-iec62056-reader.yaml...
Failed config

sensor.iec62056: [source /config/esphome/esphome-iec62056-reader.yaml:80]
  platform: iec62056
  obis: 1.6.0
  
  [group] is an invalid option for [sensor.iec62056]. Please check the indentation.
  group: 2
  name: Date time
sensor.iec62056: [source /config/esphome/esphome-iec62056-reader.yaml:85]
  platform: iec62056
  obis: 1.6.0
  
  [group] is an invalid option for [sensor.iec62056]. Please check the indentation.
  group: 1
  name: Value
sensor.iec62056: [source /config/esphome/esphome-iec62056-reader.yaml:90]
  platform: iec62056
  obis: 1.6.0
  
  [group] is an invalid option for [sensor.iec62056]. Please check the indentation.
  group: 0
  name: The entire record

This is a copy of my data from ESPHome when it reads my meter

12:49:14	[D]	[iec62056.component:529]	
Data: 0.1.2*9(00-00-00,00:00)
12:49:14	[D]	[iec62056.component:529]	
Data: 0.1.2*10(00-00-00,00:00)
12:49:15	[D]	[iec62056.component:529]	
Data: 0.1.2*11(00-00-00,00:00)
12:49:15	[D]	[iec62056.component:529]	
Data: 0.1.2*12(00-00-00,00:00)
12:49:15	[D]	[iec62056.component:529]	
Data: 0.2.0(MF81129394 CRC:C0xA12A TEDAS Apr 10 2019)
12:49:15	[D]	[iec62056.component:529]	
Data: 0.8.0(15*min)
12:49:15	[D]	[iec62056.component:529]	
Data: 0.9.1(12:48:35)
12:49:16	[D]	[iec62056.component:529]	
Data: 0.9.2(24-05-22)
12:49:16	[D]	[iec62056.component:529]	
Data: 0.9.5(3)
12:49:16	[D]	[iec62056.component:529]	
Data: 1.6.0(001.860*kW)(24-05-11,12:00)
12:49:16	[D]	[iec62056.component:625]	
Set sensor 'Positive active maximum demand (A+) total (kW)' for OBIS '1.6.0'. Value: 1.860000
12:49:17	[D]	[iec62056.component:529]	
Data: 1.6.0*1(000.000*kW)(00-00-00,00:00)
12:49:17	[D]	[iec62056.component:529]	
Data: 1.6.0*2(000.000*kW)(00-00-00,00:00)
12:49:17	[D]	[iec62056.component:529]	
Data: 1.6.0*3(000.000*kW)(00-00-00,00:00)
12:49:17	[D]	[iec62056.component:529]	
Data: 1.6.0*4(000.000*kW)(00-00-00,00:00)
12:49:17	[D]	[iec62056.component:529]	
Data: 1.6.0*5(000.000*kW)(00-00-00,00:00)
12:49:18	[D]	[iec62056.component:529]	
Data: 1.6.0*6(000.000*kW)(00-00-00,00:00)
12:49:18	[D]	[iec62056.component:529]	
Data: 1.6.0*7(000.000*kW)(00-00-00,00:00)
12:49:18	[D]	[iec62056.component:529]	
Data: 1.6.0*8(000.000*kW)(00-00-00,00:00)
12:49:18	[D]	[iec62056.component:529]	
Data: 1.6.0*9(000.000*kW)(00-00-00,00:00)
12:49:18	[D]	[iec62056.component:529]	
Data: 1.6.0*10(000.000*kW)(00-00-00,00:00)
12:49:19	[D]	[iec62056.component:529]	
Data: 1.6.0*11(000.000*kW)(00-00-00,00:00)
12:49:19	[D]	[iec62056.component:529]	
Data: 1.6.0*12(000.000*kW)(00-00-00,00:00)
12:49:19	[D]	[iec62056.component:529]	
Data: 1.8.0(000041.505*kWh)
12:49:19	[D]	[iec62056.component:625]	
Set sensor 'Positive active energy (A+) total (kWh)' for OBIS '1.8.0'. Value: 41.505001
12:49:19	[D]	[iec62056.component:529]	
Data: 1.8.0*2(000000.000*kWh)
12:49:20	[D]	[iec62056.component:529]	
Data: 1.8.0*8(000000.000*kWh)
12:49:20	[D]	[iec62056.component:529]	
Data: 1.8.1*1(000000.000*kWh)
12:49:20	[D]	[iec62056.component:529]	
Data: 1.8.1*8(000000.000*kWh)
12:49:20	[D]	[iec62056.component:529]	
Data: 1.8.2*1(000000.000*kWh)
12:49:20	[D]	[iec62056.component:529]	
Data: 1.8.2*6(000000.000*kWh)
12:49:21	[D]	[iec62056.component:529]	
Data: 1.8.2*12(000000.000*kWh)
12:49:21	[D]	[iec62056.component:529]	
Data: 1.8.3*5(000000.000*kWh)
12:49:21	[D]	[iec62056.component:529]	
Data: 1.8.3*10(000000.000*kWh)
12:49:21	[D]	[iec62056.component:529]	
Data: 1.8.4*3(000000.000*kWh)
12:49:21	[D]	[iec62056.component:529]	
Data: 1.8.4*10(000000.000*kWh)
12:49:22	[D]	[iec62056.component:529]	
Data: 96.2.5(23-01-05)
12:49:22	[D]	[iec62056.component:529]	
Data: 96.60(11110000)
12:49:22	[D]	[iec62056.component:529]	
Data: 96.71*4(00-00-00,00:00)(00)
12:49:22	[D]	[iec62056.component:529]	
Data: 96.71*8(00-00-00,00:00)(00)
12:49:22	[D]	[sensor:093]	
'Positive active maximum demand (A+) total (kW)': Sending state 1.86000 kW with 3 decimals of accuracy

UPDATE
I’ve just realised I was missing “text_sensor” so I have it working now BUT does anyone know if I can change the way the date is formatted after its read
Currently “Year / Month / Day”
I would like it to be “Day / Month / Year”
Us Brits like it that way

Hi,

The entire section should be part of text_sensor

text_sensor:
  - platform: iec62056
    obis: 1.6.0
    group: 2 
    name: Date time

For Date/Time format conversion see ESPHome IEC 62056-21 Component — Aquaticus documentation
Modify the lambda to reformat date/time string.
Another option is to do the same but on Home Assistant side. You transmit data as is and reformat it in Home Assistant sensor.

Thanks for pointing me in the right direction aquaticus but I’ve read that info and unfortunately its beyond my understanding, would you be kind enough to give me an example of how you think it should be

Hello @aquaticus
are there schematics available for your IEC62056-21 Optical Interface board?
(and mostly, how much do you think i have to wait for the delivery to italy? :slight_smile: it’s 10 days today…)

ok got it.
It works (i can clearly receive echoes of what i transmit), my issue is that i can’t read any answer from the meter.
I’m trying to interface a gas meter that has a IEC62056 port, so i’m surprised it does not respond at all (i’ve set my timeout at 10 seconds)
is this the correct string to transmit to trigger the port?

Serial.write("/?!\r\n");

thanks!

Hi,

  1. Ensure you are reading the data after the echo.
  2. Verify if the meter is transmitting by observing the meter’s transmitter with your mobile camera.
  3. Confirm that the meter uses a compatible protocol.

Dear @aquaticus,

I’ve got the following output and a bit lost with what I do next with it. I see the electric meter reports the total state of the counter Data: 63620101(006341.47) and it is correct (fits the count I see on the display of the meter), but I desperately need separate values for day and night tariffs (which are shown on the display, but not appearing in the data packet. Also momentary current for each phase is very nice to have, but I don’t understand how we technically force electric meter to emit those data. If I look at the protocol I see that the initial as per IEC standard is sent, but it is not a specific request to send any specific data, right?

If I’m getting the total accumulated energy consumption, how can I convert it into Home Assistant sensor, if it is not follwing the OBIS standard?

[21:37:18][D][iec62056.component:232]: Connection start
[21:37:18][D][binary_sensor:036]: 'Meter Connection Status': Sending state ON
[21:37:18][D][uart_debug:114]: >>> 2F:3F:21:0D:0A
[21:37:19][D][iec62056.component:174]: Meter identification: '/TPC5NEVAMT324.1106'
[21:37:19][D][iec62056.component:412]: Meter reported protocol: C
[21:37:19][D][iec62056.component:415]: Meter reported max baud rate: 9600 bps ('5')
[21:37:19][D][iec62056.component:443]: Using negotiated baud rate 9600 bps.
[21:37:19][D][uart_debug:114]: >>> 06:30:35:30:0D:0A
[21:37:19][D][iec62056.component:475]: Switching to new baud rate 9600 bps ('5')
[21:37:20][D][iec62056.component:487]: Meter started readout transmission
[21:37:20][D][iec62056.component:529]: Data: 63620101(006341.47)
[21:37:20][D][iec62056.component:529]: Data: !
[21:37:20][D][iec62056.component:502]: Total connection time: 1670 ms
[21:37:20][D][iec62056.component:507]: BCC verification is OK
[21:37:20][D][iec62056.component:234]: Connection end
[21:37:20][D][binary_sensor:036]: 'Meter Connection Status': Sending state OFF
[21:37:20][D][iec62056.component:519]: Start of sensor update
[21:37:20][D][iec62056.component:562]: End of sensor update
[21:37:20][D][iec62056.component:828]: Waiting 28309 ms for the next scheduled readout (every 30000 ms).

update

I’ve started the serial-2-tcp stream server and attached it to the native software to the electric meter (provided by vendor).
It does not work, probably because of inability to set different bod rates via TCP socket, but I can see at least the same beginnig sequesnce and the successful read out of the ‘/TPC5NEVAMT324.1106’ meter tag. But next command is different from what the IEC component sends - 06:30:35:30:0D:0A (IEC component) vs 06:30:35:31:0D:0A (vendor sofwware). Could it be that this command allows to read-out more values from the meter?

[22:10:36][D][binary_sensor:036]: 'ss_client': Sending state ON
[22:10:37][D][uart_debug:114]: >>> 2F:3F:21:0D:0A
[22:10:37][D][uart_debug:114]: <<< 2F:54:50:43:35:4E:45:56:41:4D:54:33:32:34:2E:31:31:30:36:0D:0A
[22:10:38][D][uart_debug:114]: >>> 06:30:35:31:0D:0A
[22:10:38][D][uart_debug:114]: <<< 74
[22:10:38][D][streamserver:102]: Client 192.168.44.163 disconnected
[22:10:38][D][binary_sensor:036]: 'ss_client': Sending state OFF
[22:10:38][D][uart_debug:114]: >>> 01:42:30:03:71

Hi,

This meter provides only a single data entry and does not support additional measurements like current or voltage.

To integrate it with Home Assistant, you will need to modify the source code of the IEC62056-21 component slightly.
Probably the easiest and not so elegant way is to modify line 695 of iec62056.cpp
from

out_obis.assign(line, open_bracket - line);

to

out_obis.assign(line, "1-0:15.8.0");
1 Like

It looks like the suggested change makes the component to hang.
No log output from the esphome, no any other sensor update (all sensors get the status “unavailable”).

Changed with the commit:

Configuration:

external_components:
  - source: github://0anton/esphome-iec62056

iec62056:
  update_interval: 30sec
  baud_rate_max: 9600
  battery_meter: False


text_sensor:
  - platform: iec62056
    obis: 1-0:1.8.1*255
    group: 0
    name: Total Energy

Partial output:

[01:08:49][I][app:100]: ESPHome version 2024.6.6 compiled on Jul 13 2024, 01:06:08
[01:08:49][C][wifi:599]: WiFi:
[01:08:49][C][wifi:427]:   Local MAC: 64:E8:33:89:27:7C
[01:08:49][C][wifi:432]:   SSID: [redacted]
[01:08:49][C][wifi:435]:   IP Address: 192.168.44.233
[01:08:49][C][wifi:439]:   BSSID: [redacted]
[01:08:49][C][wifi:440]:   Hostname: 'esp32c3-v2'
[01:08:49][C][wifi:442]:   Signal strength: -69 dB ▂▄▆█
[01:08:49][C][wifi:446]:   Channel: 7
[01:08:49][C][wifi:447]:   Subnet: 255.255.255.0
[01:08:49][C][wifi:448]:   Gateway: 192.168.44.1
[01:08:49][C][wifi:449]:   DNS1: 192.168.44.1
[01:08:50][C][wifi:450]:   DNS2: 0.0.0.0
[01:08:50][D][uart_debug:114]: >>> 06:30:35:30:0D:0A
[01:08:50][C][logger:185]: Logger:
[01:08:50][C][logger:186]:   Level: DEBUG
[01:08:50][C][logger:188]:   Log Baud Rate: 115200
[01:08:50][C][logger:189]:   Hardware UART: USB_CDC
[01:08:50][C][uart.arduino_esp32:137]: UART Bus 0:
[01:08:50][C][uart.arduino_esp32:138]:   TX Pin: GPIO3

I’ve asked the vendor about the communication protocol and got this example:

14:59:14.572 >> COM7 2F 3F 21 0D 0A /?!..
14:59:15.728 << COM7 2F 54 50 43 35 4E 45 56 41 4D 54 31 31 34 2E 34 /TPC5NEVAMT114.4
33 30 31 0D 0A 														 301..
14:59:15.735 >> COM7 06 30 35 31 0D 0A 								 .051..
14:59:16.339 << COM7 01 50 30 02 28 30 30 30 30 30 30 30 30 29 03 60 .P0.(00000000).`
14:59:16.339 >> COM7 01 50 31 02 28 30 30 30 30 30 30 30 30 29 03 61 .P1.(00000000).a
14:59:16.561 << COM7 06 											 .
14:59:16.567 >> COM7 01 52 31 02 31 35 30 30 30 32 46 46 28 29 03 65 .R1.150002FF().e
14:59:16.828 << COM7 02 31 35 30 30 30 32 46 46 28 30 31 30 32 30 37 .150002FF(010207
2C 30 31 30 33 30 37 2C 30 33 30 31 30 34 2C 30 					 ,010307,030104,0
33 30 34 30 34 2C 30 34 30 31 30 34 2C 30 34 30 					 30404,040104,040
32 30 34 2C 30 30 30 30 30 30 2C 30 30 30 30 30 					 204,000000,00000
30 2C 30 30 30 30 30 30 2C 30 30 30 30 30 30 2C 					 0,000000,000000,
30 30 30 30 30 30 2C 30 30 30 30 30 30 29 03 2F 					 000000,000000)./
14:59:16.834 >> COM7 01 52 31 02 36 30 30 31 30 31 46 46 28 29 03 65 .R1.600101FF().e
14:59:17.001 << COM7 02 36 30 30 31 30 31 46 46 28 32 32 32 32 32 32 .600101FF(222222
32 32 29 03 04 22)..
14:59:17.006 >> COM7 01 52 31 02 30 30 30 38 30 32 46 46 28 29 03 69 .R1.000802FF().i
14:59:17.173 << COM7 02 30 30 30 38 30 32 46 46 28 30 30 29 03 08 	 .000802FF(00)..

The client sends 051 instead of 050 to request additional configuration.
In additional configuration flow the electric meter asks for the password (P0).
Client provides the password (P1). Meter acknowledges (0x06) it.

The client requests read-out of OBIS codes (R1) and get responses accordingly.

I’m confused by not finding this implementation in iec.cpp.

How can I extent the custom component to support this flow?

It seems the meter is using variation of IEC protocol.
Assuming you got password for the meter, you can rewrite part of the component responsible for packet interchange.

Hi @aquaticus

Can you confirm this will work with an Elster gRex D AMI Meter, pictured below.
I cannot find a model number on the meter anywhere and the closest manual I could find is

AMI AS230 (camax.co.uk)

Thank you!

Hi,

It’s difficult to say for sure. While the optical interface is definitely compatible, there’s a chance that the software might not be able to communicate with the meter properly. Unfortunately, I suspect it may not work.