Landis & Gyr E320 not with IEC 62056-21 component but with SML component

Hi,
I want to read my Landis & Gyr E320 electricity meter with the component provided by aquaticus.

https://aquaticus.info/iec62056.html

Until now I’ve been doing this using an ESP8266 (Wemos D1 mini pro) with Tasmota. However, it seems to me that with the iec62056 component is better integrated into HA. Since it was running with Tasmota, I was naively thinking that it would be a piece of cake to make the transition. But no. :frowning:

The script in Tasmota looks like:

>D
>B
=>sensor53 r
>M 1
+1,5,s,20,9600,E320
1,77070100020800ff@1000,Total Delivered,kWh,Total_out,1
1,77070100010800ff@1000,Total Consumed,kWh,Total_in,1
1,77070100100700ff@1,Current power,W,Power_in,0
1,77070100600100ff@#,Server-ID,,Meter_Number,0    
#    

https://tasmota.github.io/docs/Smart-Meter-Interface/#descriptor-syntax

The datasheet says 9600 Baud, 8-N-1.
At first I tried with the same hardware setup, i.e. GPIO5 as RX. But I received only a garbeled mess. As aquaticus recommends using the HW UART, I switched to the HW RX, i.e. GPIO3.

My yaml looks like:

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

uart:
    rx_pin: GPIO3
    tx_pin: GPIO1 # unused
    baud_rate: 9600
    data_bits: 8
    parity: NONE
    stop_bits: 1

iec62056:
  mode_d: True

What I receive is the same/similar mess as with GPIO5:

[14:57:10][D][iec62056.component:174]: Meter identification: '/b'
[14:57:10][D][iec62056.component:232]: Connection start
[14:57:10][D][iec62056.component:323]: Data: 'R\x94'
[14:57:10][E][iec62056.component:338]: Invalid frame format: 'R\x94'
[14:57:10][D][iec62056.component:323]: Data: '\xbe\xad	tw'
[14:57:10][E][iec62056.component:338]: Invalid frame format: '\xbe\xad	tw'
[14:57:10][D][iec62056.component:323]: Data: 'R\x94w'
[14:57:10][E][iec62056.component:338]: Invalid frame format: 'R\x94w'
[14:57:10][D][iec62056.component:323]: Data: '\xbe\xad	bR'
[14:57:10][E][iec62056.component:338]: Invalid frame format: '\xbe\xad	bR'
[14:57:10][D][iec62056.component:323]: Data: ''
[14:57:10][D][iec62056.component:323]: Data: '
[14:57:10][E][iec62056.component:338]: Invalid frame format: '
[14:57:10][D][iec62056.component:323]: Data: '\xbe\xad	bR'
[14:57:10][E][iec62056.component:338]: Invalid frame format: '\xbe\xad	bR'
[14:57:10][D][iec62056.component:323]: Data: ''
[14:57:10][E][iec62056.component:338]: Invalid frame format: ''
[14:57:10][D][iec62056.component:323]: Data: 'qc1\xa7'
[14:57:10][E][iec62056.component:338]: Invalid frame format: 'qc1\xa7'
[14:57:11][D][iec62056.component:323]: Data: '<q)21b'
[14:57:11][E][iec62056.component:338]: Invalid frame format: '<q)21b'
[14:57:11][D][iec62056.component:323]: Data: 'R\x94rb'
[14:57:11][E][iec62056.component:338]: Invalid frame format: 'R\x94rb'
[14:57:11][D][iec62056.component:323]: Data: '\xbe\xad
cC\xb9'
[14:57:11][E][iec62056.component:338]: Invalid frame format: '\xbe\xad
cC\xb9'
and so on

From the logs I would assume that the baud rate or the transmission parameters would be wrong. But I had checked with the datasheet. And 7-E-1 produces a similar mess.

Has anyone successfully used the IEC 62056-21 component with this meter?

Matthias.

P.S.
The raw output from the Tasmota console looked like:

11:11:47.011 : 77 07 01 00 60 32 01 01 01 01 01 01 04 4c 47 5a 01
11:11:47.013 : 77 07 01 00 60 01 00 ff 01 01 01 01 0b 0a 01 4c 47 5a 00 03 d5 52 94 01
11:11:47.061 : 77 07 01 00 01 08 00 ff 65 00 1c 41 04 72 62 01 65 02 80 81 4a 62 1e 52 03 69 00 00 00 00 00 00 0e 72 01
11:11:47.915 : 77 07 01 00 02 08 00 ff 01 72 62 01 65 02 80 81 4a 62 1e 52 03 69 00 00 00 00 00 00 1c 7b 01 01 01 63 6b 44 00 76 05 04
11:11:47.964 : 77 07 ff ff ff ff ff ff 0b 0a 01 4c 47 5a 00 03 d5 52 94 07 01 00 62 0a ff ff 72 62 01 65 02 80 81 4b 74 

Maybe your RX data is inverted.

For that baud rate I would go with GPIO5.
Hardware serial on D1 mini might/might not work, depends on the usb serial circuit of the specific board. In any case, you need to set logger baud_rate to 0 if you want to use pins 1 / 3 for uart component.

Oh, it was my own stupidity.

From the Tasmota skript:

+1,5,s,20,9600,E320

The “s” means “SML binary smart message coding”. So, the IEC 62056-21 component is simply the wrong one. Carefully reading the related https://aquaticus.info/meter.html I noticed that there is a “SML component” in ESPhome. After I switched to that everything worked as expected.

For completeness the working yaml:

logger:
 baud_rate: 0

uart:
   rx_pin: GPIO3
   tx_pin: GPIO1 # unused
   id: uart_bus
   baud_rate: 9600
   data_bits: 8
   parity: NONE
   stop_bits: 1

sml:
 id: mysml
 uart_id: uart_bus

sensor:
 - platform: sml
   name: "Total energy import"
   sml_id: mysml
   obis_code: "1-0:1.8.0"
   unit_of_measurement: kWh
   accuracy_decimals: 1
   device_class: energy
   state_class: total_increasing
   filters:
     - multiply: 0.0001

 - platform: sml
   name: "Total energy export"
   sml_id: mysml
   obis_code: "1-0:2.8.0"
   unit_of_measurement: kWh
   accuracy_decimals: 1
   device_class: energy
   state_class: total_increasing
   filters:
     - multiply: 0.0001
     
 - platform: sml
   name: "Current power"
   sml_id: mysml
   obis_code: "1-0:16.7.0"
   unit_of_measurement: W
   accuracy_decimals: 0
   device_class: power
   state_class: measurement   

I did not try switching back to GPIO5 but I assume it would also work.

Matthias