IEC 62056-21 (D0)

IEC 62056-21 (formerly IEC 61107) is an international standard for exchanging data with utility meters using ASCII protocol over an optical interface. It’s commonly referred to as “D0” protocol in Germany and is widely used by electricity meters with an infrared (IR) port.

Details

IEC 62056-21 is sometimes called D0 protocol, Flag protocol, or IEC 61107 (the previous standard name). If your meter has an optical port and outputs readable ASCII text, it likely uses this protocol.

How IEC 62056-21 Works

Unlike SML (which uses binary encoding), IEC 62056-21 transmits data as human-readable ASCII text. The meter sends data in a structured format with an identification line followed by OBIS-coded values.

Typical Setup

[Smart Meter] ---(Infrared)---> [IR Reading Head] ---(USB/Serial)---> [Raspberry Pi] ---(MQTT)---> [energy2mqtt]

The setup is similar to SML, but the data format is different:

  • SML: Binary protocol, requires decoder
  • IEC 62056-21: ASCII text, human-readable

Communication Modes

IEC 62056-21 supports four communication modes:

Mode Description Baud Rate Direction
Mode A Basic ASCII communication Fixed 300 baud Bidirectional
Mode B Extended Mode A Variable Bidirectional
Mode C Handshake with baud rate change Variable (up to 19200) Bidirectional
Mode D Unidirectional push Fixed (2400 or 9600) Meter β†’ Reader
Details

Most modern meters support Mode C (bidirectional with handshake) or Mode D (continuous push). Mode D is common for meters that broadcast data every few seconds without needing a request.

Protocol Details

Message Structure

An IEC 62056-21 telegram looks like this:

/ESY5Q3D\@V5.3
0-0:1.0.0(210101120000W)
1-0:1.8.0(000123.456*kWh)
1-0:2.8.0(000012.345*kWh)
1-0:15.7.0(001.234*kW)
1-0:32.7.0(230.5*V)
!

Identification Line

The first line identifies the meter:

/ESY5Q3D\@V5.3
 │││└─────────── Model/Version info
 ││└──────────── Baud rate identifier (5 = 9600 baud)
 │└───────────── Manufacturer code (3 letters)
 └────────────── Start character

Manufacturer codes:

Code Manufacturer
ESY EasyMeter
EAS EasyMeter (alternate)
EBZ eBZ GmbH
ELS Elvaco
ISK Iskraemeco

Baud rate identifiers:

ID Baud Rate
0 300
1 600
2 1200
3 2400
4 4800
5 9600
6 19200

Data Lines

Each data line follows the format:

OBIS-Code(Value*Unit)

Example:

1-0:1.8.0(000123.456*kWh)
β”‚         β”‚         └─── Unit
β”‚         └───────────── Value (leading zeros preserved)
└─────────────────────── OBIS code

End of Telegram

The telegram ends with an exclamation mark:

!

Some meters include a checksum after the ! character.

OBIS Codes

OBIS (Object Identification System) codes identify each measurement. The format is:

Medium-Channel:Indicator.Mode.Tariff

Common OBIS codes:

OBIS Code Description Unit
0-0:1.0.0 Timestamp -
1-0:0.0.0 Equipment identifier -
1-0:1.8.0 Total energy consumed kWh
1-0:1.8.1 Energy consumed (Tariff 1) kWh
1-0:1.8.2 Energy consumed (Tariff 2) kWh
1-0:2.8.0 Total energy delivered kWh
1-0:15.7.0 Absolute active power kW
1-0:16.7.0 Sum active power (signed) kW
1-0:21.7.0 Active power L1 kW
1-0:41.7.0 Active power L2 kW
1-0:61.7.0 Active power L3 kW
1-0:32.7.0 Voltage L1 V
1-0:52.7.0 Voltage L2 V
1-0:72.7.0 Voltage L3 V
1-0:31.7.0 Current L1 A
1-0:51.7.0 Current L2 A
1-0:71.7.0 Current L3 A
1-0:13.7.0 Power factor -
1-0:14.7.0 Frequency Hz
1-0:36.7.0 Reactive power kvar

Supported Meters

energy2mqtt includes built-in support for these meter families:

EasyMeter

Models: Q3D, Q3B series

Feature Details
Communication 9600 baud, 7E1
Modes C (bidirectional), D (push)
Measurements Energy, power, voltage, current, frequency
Special Voltage sag counters

Example telegram:

/ESY5Q3D\@V5.3
0-0:1.0.0(210101120000W)
1-0:1.8.0(000123.456*kWh)
1-0:2.8.0(000012.345*kWh)
1-0:15.7.0(001.234*kW)
1-0:32.7.0(230.5*V)
1-0:52.7.0(231.2*V)
1-0:72.7.0(229.8*V)
1-0:31.7.0(05.34*A)
1-0:51.7.0(04.89*A)
1-0:71.7.0(05.12*A)
1-0:14.7.0(50.0*Hz)
!

EBZ (eBZ GmbH)

Models: DD3 series (three-phase meters)

Feature Details
Communication 9600 baud, 7E1
Modes C (bidirectional), D (push)
Measurements Energy with tariffs, per-phase power, reactive power
Special Power factor, detailed three-phase data

Example telegram:

/EBZ5DD3BL10-112
0-0:1.0.0(210101120000W)
1-0:1.8.1(000234.567*kWh)
1-0:1.8.2(000123.456*kWh)
1-0:2.8.1(000012.345*kWh)
1-0:2.8.2(000001.234*kWh)
1-0:16.7.0(001.500*kW)
1-0:36.7.0(000.250*kvar)
1-0:21.7.0(000.500*kW)
1-0:41.7.0(000.480*kW)
1-0:61.7.0(000.520*kW)
1-0:32.7.0(230.1*V)
1-0:52.7.0(231.5*V)
1-0:72.7.0(229.3*V)
1-0:31.7.0(02.17*A)
1-0:51.7.0(02.09*A)
1-0:71.7.0(02.24*A)
1-0:13.7.0(0.95)
1-0:14.7.0(50.0*Hz)
!

Generic Support

Meters not specifically recognized are handled with generic OBIS code parsing. Standard measurements will work automatically.

Configuration

IEC 62056-21 requires minimal configuration. energy2mqtt auto-detects the meter type from the identification line.

MQTT Input

energy2mqtt listens for IEC 62056-21 telegrams on the MQTT topic:

iec62056_input

The message should contain the complete telegram as a plain text string (not hex-encoded like SML).

Getting Data to MQTT

You need a tool to read from your IR reading head and publish to MQTT.

Using ser2net

For a simple setup, use ser2net to forward serial data:

# Install ser2net
sudo apt install ser2net

# Configure /etc/ser2net.conf
# 3000:raw:0:/dev/ttyUSB0:9600 7E1

Then use a script to read and publish:

import socket
import paho.mqtt.client as mqtt

# Connect to ser2net
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('localhost', 3000))

# MQTT client
client = mqtt.Client()
client.connect('localhost', 1883)

buffer = ""
while True:
    data = sock.recv(1024).decode('ascii', errors='ignore')
    buffer += data

    # Check for complete telegram
    if '!' in buffer:
        # Find start and end
        start = buffer.find('/')
        end = buffer.find('!') + 1

        if start >= 0 and end > start:
            telegram = buffer[start:end]
            client.publish('iec62056_input', telegram)
            buffer = buffer[end:]

Serial Settings

Most IEC 62056-21 meters use these serial settings:

Setting Value
Baud rate 9600 (or as indicated in ID line)
Data bits 7
Parity Even (E)
Stop bits 1
Flow control None

In short notation: 9600 7E1

Details

IEC 62056-21 typically uses 7 data bits with even parity (7E1), which is different from SML’s common 8N1 setting. Make sure your serial configuration matches!

Output Data

After processing, energy2mqtt publishes the parsed meter data. Example output:

Field Example Value Description
total_energy_consumed 123.456 Total energy (kWh)
energy_consumed_t1 234.567 Tariff 1 energy (kWh)
energy_consumed_t2 123.456 Tariff 2 energy (kWh)
current_power 1.234 Current power (kW)
voltage_l1 230.5 Phase 1 voltage (V)
voltage_l2 231.2 Phase 2 voltage (V)
voltage_l3 229.8 Phase 3 voltage (V)
current_l1 5.34 Phase 1 current (A)
frequency 50.0 Grid frequency (Hz)
power_factor 0.95 Power factor
timestamp 210101120000W Meter timestamp

IEC 62056-21 vs SML

Both protocols are used by German smart meters with optical interfaces. Here’s how they compare:

Feature IEC 62056-21 SML
Encoding ASCII text Binary
Readability Human-readable Requires decoder
Serial settings 7E1 (typically) 8N1 (typically)
Data format OBIS(value*unit) Binary TLV structure
Checksum Optional CRC Always included
Meter support Older meters, specific brands Newer German meters
Details

If you’re unsure which protocol your meter uses, connect with a serial terminal and check:

  • IEC 62056-21: You’ll see readable text starting with /
  • SML: You’ll see binary garbage (starts with 1B 1B 1B 1B)

Troubleshooting

No Data Received

Check serial settings:

  • Try both 7E1 and 8N1 configurations
  • Verify the baud rate (usually 9600)

Check IR reading head:

  • Ensure proper alignment with meter’s optical port
  • Some meters require activation (press button or shine flashlight)

Garbled Data

Wrong serial settings:

Expected: /ESY5Q3D\@V5.3
Got:      ?????@?????

β†’ Check data bits and parity (try 7E1 vs 8N1)

Wrong baud rate:

Expected: /ESY5Q3D\@V5.3
Got:      (random characters)

β†’ Try different baud rates (300, 2400, 9600, 19200)

Incomplete Telegrams

Mode D meters send continuously. If you’re missing data:

  • Check your buffer handling
  • Ensure you’re capturing the complete telegram from / to !

Mode C meters require a request first:

  • Send /?! followed by CR LF to request data
  • Wait for the response

PIN-Locked Meters

Like SML meters, some IEC 62056-21 meters require a PIN to show detailed data:

  • Basic readings (energy totals) usually available without PIN
  • Detailed readings (power, voltage, current) may require PIN
  • Contact your utility provider for the PIN

Hardware Recommendations

The same IR reading heads work for both IEC 62056-21 and SML:

Product Price Range Notes
Hichi IR USB ~€15 Popular, works well
Bitshake ~€30 High quality, good support
VolkszΓ€hler ~€10 DIY-friendly

Connection Tips

  • Position reading head directly over the meter’s IR port
  • Use magnetic mounting for stable connection
  • Shield from ambient light (especially sunlight)
  • Keep USB cable short (< 2m) to reduce interference