Python¶
With Python you can read the WattWächter USB on any computer, whether Raspberry Pi, Linux, Windows or Mac. We use pyserial for the serial port and smllib to decode the SML telegrams.
pip install pyserial smllib
Find the serial port¶
This script lists all WattWächter USB heads currently plugged into the computer, with port and serial number:
from serial.tools import list_ports
for port in list_ports.comports():
if (port.vid, port.pid) == (0x10C4, 0xEA60): # Silicon Labs CP210x
print(f"{port.device:40s} serial number {port.serial_number}")
/dev/ttyUSB0 serial number <serial>
On macOS this is the only way to tell several heads apart, because the port name there depends on the USB port. The query finds every device with a CP210x converter. If another such device is plugged in besides the WattWächter, tell them apart by the serial number.
SML meters¶
Almost all modern meters send SML at 9600 baud, 8N1 on their own:
import serial
from smllib import SmlStreamReader
from smllib.errors import CrcError
# Linux: /dev/serial/by-id/usb-Silicon_Labs_CP2102N_..._<serial>-if00-port0
# macOS: /dev/cu.usbserial-<number>, e.g. /dev/cu.usbserial-10
# Windows: COM3
PORT = "/dev/ttyUSB0"
# OBIS codes we are interested in (short form -> label)
OBIS = {
"1.8.0": "Import", # Wh, drawn from the grid
"2.8.0": "Export", # Wh, fed into the grid
"16.7.0": "Power", # W, current active power (signed)
}
ser = serial.Serial(PORT, baudrate=9600, bytesize=8,
parity="N", stopbits=1, timeout=2)
stream = SmlStreamReader()
print(f"Reading WattWächter USB on {PORT} ...")
while True:
data = ser.read(ser.in_waiting or 1)
if not data:
continue
stream.add(data)
try:
frame = stream.get_frame()
except CrcError:
continue # skip a corrupted telegram
if frame is None:
continue # telegram not complete yet
for entry in frame.get_obis():
name = OBIS.get(entry.obis.obis_short)
if name is None:
continue
value = entry.get_value() # already scaled (value × 10^scaler)
if entry.obis.obis_short in ("1.8.0", "2.8.0"):
print(f"{name:8s}: {value / 1000:.3f} kWh")
else:
print(f"{name:8s}: {value:.0f} W")
print("-" * 30)
Example output:
Reading WattWächter USB on /dev/ttyUSB0 ...
Import : 12345.678 kWh
Export : 4321.000 kWh
Power : 437 W
------------------------------
Reading more values
Add more codes to the OBIS dictionary, e.g. 36.7.0, 56.7.0, 76.7.0 for the phase power or 32.7.0, 52.7.0, 72.7.0 for the phase voltages. An overview is under Readings.
D0 meters that send on their own¶
Some meters send their values as D0 text on their own, without a request, usually at 9600 baud, 7E1, e.g. eBZ DD3, EasyMeter Q3D or Hager EHZ161/EHZ361. Whether yours is one of them is shown by the test in the setup: it then reports D0 telegram detected. For these meters pyserial is all you need:
import re
import serial
PORT = "/dev/ttyUSB0" # Windows: "COM3", macOS: "/dev/cu.usbserial-XXXX"
# Known codes get a name, all others are printed with their code
NAMES = {
"1.8.0": "Import",
"2.8.0": "Export",
"16.7.0": "Power",
"0.0.0": "Meter number",
}
# Data lines like 1-0:1.8.0*255(012345.678*kWh) or 1.8.0(012345.678*kWh)
LINE = re.compile(r"^(?:\d+-\d+:)?([0-9A-Z]+(?:\.[0-9A-Z]+)+)(?:\*\d+)?\(([^)*]*)(?:\*([^)]*))?\)")
ser = serial.Serial(PORT, baudrate=9600, bytesize=serial.SEVENBITS,
parity=serial.PARITY_EVEN, stopbits=serial.STOPBITS_ONE, timeout=5)
print(f"Reading WattWächter USB on {PORT} (D0, 9600 baud, 7E1) ...")
while True:
line = ser.readline().decode("ascii", "replace").strip()
if line.startswith("/"): # identification, starts every telegram
print(f"Meter: {line}")
elif line.startswith("!"): # end of the telegram
print("-" * 30)
else:
match = LINE.match(line)
if match:
code, value, unit = match.groups()
print(f"{NAMES.get(code, code):14s}: {value} {unit or ''}")
Example output from an eBZ DD3:
Reading WattWächter USB on /dev/ttyUSB0 (D0, 9600 baud, 7E1) ...
Meter: /EBZ5DD3LZ06ETA_107
Meter number : 1EBZ0101267463
96.1.0 : 1EBZ0101267463
Export : 000001 kWh
96.5.0 : 00050104
96.8.0 : 008250CD
------------------------------
Which codes arrive depends on the meter and whether it is unlocked; without a PIN this meter only sends the export. The meaning of the codes is explained under Readings.
D0 meters that need a request (IEC 62056-21)¶
Older meters (marked with footnote ⁴ in the Supported meters table) only send when asked: request at 300 baud, 7E1, then a switch to the baud rate the meter offers. The script for this is on the WattWächter TTL page under Python → Example script 2. It works unchanged with the WattWächter USB; just enter your head's port as PORT. During the request the yellow LED lights up briefly.
Several meters¶
Every WattWächter USB has its own serial number. With several heads on one computer, for example for the house and the heat pump meter, open each one via its fixed path:
METERS = {
"House": "/dev/serial/by-id/usb-Silicon_Labs_CP2102N_..._<serial-1>-if00-port0",
"Heat pump": "/dev/serial/by-id/usb-Silicon_Labs_CP2102N_..._<serial-2>-if00-port0",
}
On Windows these are the fixed COM numbers of the two heads; on macOS look up the port by serial number at start-up (see Find the serial port). This keeps the assignment correct after a reboot or re-plugging.
Troubleshooting¶
| Problem | Possible cause / solution |
|---|---|
Permission denied on /dev/... |
Add the user to the dialout group: sudo usermod -aG dialout $USER, then log in again |
Device or resource busy / access denied (Windows) |
Another program has the port open |
No data / frame stays None |
Is the green LED flashing? If not, the head is not centred or the meter is not sending. If it is: wrong port, or the meter speaks D0 instead of SML. |
| Energy readings only, no power/phases | Disable the PIN on the meter and set Inf → On |
| Values off by a factor of 10/100 | In rare cases replace get_obis() with parse_frame() (see the smllib docs) |