SML (Smart Meter Language)

SML (Smart Meter Language) is a binary protocol used by smart electricity meters, primarily in Germany. It’s commonly found on meters with an optical interface (the small infrared port with a flashing LED). energy2mqtt can decode SML messages and publish the meter readings to Home Assistant.

Details

SML is standardized in Germany through BSI TR-03109. If your electricity meter has a small optical interface with a blinking LED, it likely supports SML.

How SML Works

Smart meters with SML periodically output data through their optical (infrared) interface. A reading head attached to the meter converts these light pulses into serial data, which is then forwarded to energy2mqtt via MQTT.

Typical Setup

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

Common IR reading heads:

  • Hichi IR reading head (TTL/USB)
  • VolkszΓ€hler IR head
  • Bitshake Smartmeter Interface
  • DIY reading heads with phototransistor

What SML Provides

Depending on your meter model and configuration, SML can provide:

Data Description Typical Update
Total energy consumed Meter reading (kWh) Every message
Total energy delivered For solar feed-in (kWh) Every message
Current power Instantaneous power (W) Every 1-2 seconds
Voltage per phase L1, L2, L3 (V) Every message
Current per phase L1, L2, L3 (A) Every message
Power factor cos(Ο†) Every message
Frequency Grid frequency (Hz) Every message
Details

Not all data is available by default. Some meters require a PIN from your utility to unlock detailed readings. Contact your energy provider to request the PIN.

Protocol Details

Message Structure

SML messages are wrapped in a specific frame format:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Start Sequence  β”‚  SML Content β”‚  End Sequence   β”‚ Padding β”‚
β”‚ 1B 1B 1B 1B     β”‚  (variable)  β”‚  1B 1B 1B 1A    β”‚         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Message Types

A typical SML transmission contains multiple messages:

Type Description
OpenResponse Start of communication
GetListResponse (0x701) Actual meter data
CloseResponse End of communication
AttentionResponse (0x901) Error or status notifications

energy2mqtt focuses on the GetListResponse which contains the actual readings.

OBIS Codes

Meter values are identified by OBIS codes - a standardized addressing scheme:

Medium-Channel:Indicator.Mode.Tariff.Previous
   1   -  0  :    1    . 8  .  0   .  *

Common OBIS codes:

OBIS Code Description
1-0:1.8.0 Total active energy consumed (kWh)
1-0:2.8.0 Total active energy delivered (kWh)
1-0:16.7.0 Current total power (W)
1-0:36.7.0 Current power L1 (W)
1-0:56.7.0 Current power L2 (W)
1-0:76.7.0 Current power L3 (W)
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:14.7.0 Grid frequency (Hz)
1-0:13.7.0 Power factor

Unit Codes

Values include a unit code that energy2mqtt translates:

Code Unit Description
27 Wh Watt hours
28 kWh Kilowatt hours
30 W Watts
31 kW Kilowatts
37 V Volts
40 A Amperes
48 Hz Hertz
9 Β°C Celsius

Supported Meters

energy2mqtt includes built-in support for these meter types:

EMH Meters

Models: ED300L, ED300S, and similar

Common in many German utility areas. Identified by “EMH” in the meter ID or ID starting with “1E”.

Typical readings:

  • Total energy (consumed/delivered)
  • Current power
  • Voltage and current per phase
  • Frequency

Iskraemeco Meters

Models: MT175, MT631

Popular smart meters with detailed phase information. Identified by “ISK” in the meter ID.

Typical readings:

  • Energy with tariff support (T1/T2)
  • Reactive power
  • Detailed phase measurements

Itron Meters

Models: OpenWay 3.HZ

Identified by “ITR” in the meter ID.

EasyMeter

Various models with SML support. Identified by “EAS” in the meter ID.

Generic Support

If your meter isn’t specifically recognized, energy2mqtt falls back to generic OBIS code parsing. Most standard readings will still work.

Details

You can check which meter type was detected in the energy2mqtt logs. If your meter uses non-standard OBIS codes, please open an issue on GitHub.

Configuration

SML requires minimal configuration in energy2mqtt. The meter type is auto-detected from the data.

MQTT Input

energy2mqtt listens for SML data on the MQTT topic:

sml_input

The message should contain the raw SML data as a hex-encoded string.

Getting Data to MQTT

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

Option 1: sml2mqtt

A dedicated tool for reading SML and publishing to MQTT:

# Install
pip install sml2mqtt

# Configure in sml2mqtt.yaml
mqtt:
  broker: localhost
  port: 1883
  topic: sml_input

serial:
  port: /dev/ttyUSB0
  baudrate: 9600
Details

TODO: Add complete sml2mqtt configuration example and link to installation guide.

Option 2: Custom Script

A simple Python script to read and forward SML data:

import serial
import paho.mqtt.client as mqtt

# Serial port of your IR reading head
ser = serial.Serial('/dev/ttyUSB0', 9600)

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

while True:
    # Read SML frame
    data = ser.read(1024)
    # Publish as hex
    client.publish('sml_input', data.hex())
Details

This is a simplified example. Production code should handle SML framing, error recovery, and reconnection.

No Configuration Needed

Unlike OMS or Modbus, SML doesn’t require explicit meter configuration in e2m.yaml. The protocol is self-describing:

  • Meter ID is included in the message
  • OBIS codes identify each value
  • Units are included with values

energy2mqtt automatically:

  1. Identifies the meter type from the ID
  2. Parses all available values
  3. Creates Home Assistant entities

Output Data

energy2mqtt publishes decoded SML data via MQTT. Example output:

Field Example Value Unit
total_energy_consumed 12345.678 kWh
total_energy_delivered 1234.567 kWh
current_power 1523 W
voltage_l1 230.4 V
voltage_l2 231.2 V
voltage_l3 229.8 V
current_l1 2.34 A
current_l2 1.89 A
current_l3 3.12 A
frequency 50.01 Hz
manufacturer EMH -
device_id 1EMH0012345678 -

PIN Unlock

Many German smart meters require a PIN to unlock detailed readings (like current power and phase values). Without the PIN, you may only see basic energy totals.

Getting Your PIN

  1. Contact your electricity provider (Netzbetreiber)
  2. Request the “Kundenschnittstelle PIN” or “HAN PIN”
  3. They’re legally required to provide it (in Germany)

Entering the PIN

The PIN entry is done on the meter itself, not in energy2mqtt:

  1. Press the button on your meter (or use a flashlight)
  2. Navigate to the PIN entry menu
  3. Enter your 4-digit PIN
  4. The meter unlocks detailed readings

After unlocking, SML messages will include all available data automatically.

Details

Once unlocked, the meter stays unlocked. You don’t need to re-enter the PIN unless the meter is reset or replaced.

Troubleshooting

No Data Received

Check your reading head:

  • Is it properly attached to the meter?
  • Is the LED on the reading head responding to the meter’s flashes?
  • Try repositioning the reading head

Check serial connection:

# Test if data is coming through
cat /dev/ttyUSB0 | xxd

You should see hex data appearing every 1-2 seconds.

Partial Data Only

Only seeing energy totals?

  • Your meter is likely PIN-locked
  • Request the PIN from your utility provider

Missing phases?

  • Single-phase meters don’t report L2/L3
  • Some meters need firmware updates

CRC Errors

“CRC verification failed”

  • Interference on the serial line
  • Reading head not properly aligned
  • Try a shielded USB cable

Wrong Values

Values seem off?

  • Check if the scaler is being applied correctly
  • Verify the unit (Wh vs kWh, W vs kW)
  • Compare with your meter’s display

Hardware Recommendations

IR Reading Heads

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

Connection Tips

  • Use a short USB cable (< 2m) to avoid signal issues
  • Magnetic mounting helps with alignment
  • Shield the reading head from ambient light
Details

If you’re getting intermittent data, try adding a small piece of dark tape around the reading head to block ambient light.

Example: Complete Setup

Here’s a complete example of reading a German smart meter with energy2mqtt:

1. Hardware Setup

  1. Attach IR reading head to meter’s optical interface
  2. Connect reading head to Raspberry Pi via USB
  3. Note the serial port (usually /dev/ttyUSB0)

2. Install sml2mqtt

pip install sml2mqtt

3. Configure sml2mqtt

Create /etc/sml2mqtt.yaml:

mqtt:
  broker: localhost
  port: 1883
  publish_topic: sml_input
  raw: true  # Send raw hex data

serial:
  port: /dev/ttyUSB0
  baudrate: 9600
Details

TODO: Verify exact sml2mqtt configuration parameters and add systemd service file example.

4. Start Reading

sml2mqtt

5. Verify in Home Assistant

After a few seconds, new entities should appear in Home Assistant under the auto-discovered meter device.