Python (Raspberry Pi · Linux · macOS · Windows)¶
The WattWächter WiFi/USB — both Gen.2 and Gen.1 — can be read directly with Python over its USB-C interface. When USB data output is enabled, the WattWächter outputs the meter's raw SML data stream (9600 baud, 8N1) over USB-C. The USB cable serves as both power supply and data line.
We use pyserial to read the serial interface and smllib to decode the telegrams.
Works with Gen.2 and Gen.1
The USB data output is identical on both generations — only the way you enable it differs (Gen.2 via software command, Gen.1 via jumper). The example script is the same for both.
Meter prerequisites
For the meter to send the full instantaneous values (power, phases), the PIN usually has to be disabled and the extended info mode (Inf → On) enabled. You get the PIN from your grid operator. See Preparing the meter.
Step 1 — Enable USB data output¶
How the data is output over USB depends on your WattWächter's generation. You can identify yours from the product overview.
- Gen.2: Wi-Fi mode is always active. You additionally enable USB data output via a software command (
sensor53 u1) — no jumper configuration is needed. See Getting Started → Enable USB data output (Gen.2). - Gen.1: Move the jumpers on the board to USB mode. See Getting Started → Select Operating Mode (Gen.1).
Step 2 — Connect the WattWächter¶
- Place the WattWächter on the meter (on Gen.1, close the housing first)
- Connect the WattWächter via the USB-C cable to a free USB port on your computer or Raspberry Pi
- The USB cable serves as both power supply and data line
Step 3 — Find the serial port¶
The WattWächter registers with the operating system as a USB serial device (chip 1a86 / CH340).
ls /dev/ttyUSB*
# e.g. /dev/ttyUSB0
Stable device path
For permanent scripts, use the path under /dev/serial/by-id/... (e.g. /dev/serial/by-id/usb-1a86_USB_Serial-if00-port0). It persists across reboots and USB-port changes — unlike /dev/ttyUSB0.
ls /dev/tty.usbserial*
# e.g. /dev/tty.usbserial-XXXX
Open Device Manager → Ports (COM & LPT). The WattWächter appears as USB-SERIAL CH340 (COMx), e.g. COM3.
Step 4 — Install the libraries¶
pip install pyserial smllib
Example script¶
import serial
from smllib import SmlStreamReader
# --- Serial interface -------------------------------------------------------
# Linux / Raspberry Pi: /dev/ttyUSB0
# macOS: /dev/tty.usbserial-XXXX
# Windows: COM3
PORT = "/dev/ttyUSB0"
# OBIS codes we care about (short form -> label)
OBIS = {
"1.8.0": "Consumption", # Wh, drawn from the grid
"2.8.0": "Feed-in", # 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 WiFi/USB on {PORT} ...")
while True:
data = ser.read(ser.in_waiting or 1)
if not data:
continue
stream.add(data)
frame = stream.get_frame()
if frame is None:
continue # telegram not yet complete
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:12s}: {value / 1000:.3f} kWh")
else:
print(f"{name:12s}: {value:.0f} W")
print("-" * 30)
Example output:
Reading WattWächter WiFi/USB on /dev/ttyUSB0 ...
Consumption : 12345.678 kWh
Feed-in : 4321.000 kWh
Power : 437 W
------------------------------
Reading additional values
Extend the OBIS dictionary with more codes (e.g. 36.7.0, 56.7.0, 76.7.0 for the per-phase power or 32.7.0, 52.7.0, 72.7.0 for the per-phase voltages). entry.get_value() returns the value already correctly scaled, and entry.unit holds the unit code. See Further OBIS codes for an overview of common OBIS codes.
Troubleshooting¶
| Problem | Possible cause / solution |
|---|---|
No /dev/ttyUSB* or no COM port |
USB data output not enabled (Gen.2: sensor53 u1, Gen.1: jumpers in USB mode); reconnect the USB cable. On Windows, install the CH340 driver if needed |
Permission denied on /dev/... |
Add your user to the dialout group: sudo usermod -aG dialout $USER, then log in again |
No data / frame stays None |
Reading head not positioned correctly over the meter's IR interface; USB data output not active; wrong port |
| Only energy counters, no power/phases | Disable the PIN at 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) |