Arduino (ESP32)¶
The WattWächter TTL is a pure IR reading head: it outputs your meter's data stream 1:1 as a TTL serial signal. On a microcontroller such as the ESP32 you only need to read this stream on a UART interface and decode it.
Most modern meters (eHZ, smart meter gateways) send their data in the SML format (Smart Message Language) at 9600 baud, 8N1. This page shows an Arduino sketch as a building block for your own projects. It uses the ready-made SML-Parser library, which decodes the stream byte by byte and verifies the CRC checksum automatically.
Home Assistant? Use ESPHome
If the ESP32 only needs to deliver the values to Home Assistant, ESPHome is the faster way: SML decoding is already built in, and you don't have to write any code.
How the communication works
Most meters send their telegram on their own at regular intervals (push) – for those, the receive line (green / RXD) is sufficient for read-out. The TX line (white, yellow on the older TTL) is only needed for the remaining meters that have to be requested to send — marked with footnote ⁴ in the Supported meters table. Which wire goes where is shown in the wiring diagram under Connection → Wiring.
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 obtain the PIN from your grid operator. How to do that is described under Meter preparation.
Wiring¶
Connect the WattWächter TTL as described under Connection → Wiring. The sketch uses GPIO16 (RX2) on the ESP32 for the green wire and GPIO17 (TX2) for the white wire (yellow on the older TTL). Power the head with 3.3 V on the ESP32, see Connection → Pins per board.
ESP8266 / D1 Mini
The ESP8266 has only one full hardware UART, which is shared with the USB-to-serial converter. Read the meter data there via Serial (RX = GPIO3) and send debug output via Serial1 (TX = GPIO2). SoftwareSerial is usually too slow at 9600 baud and leads to reception errors.
Install the library¶
Open Tools → Manage Libraries…, search for SML-Parser (by olliiiver) and install it.
In platformio.ini:
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
lib_deps =
olliiiver/SML Parser@^0.29
Sketch¶
#include <Arduino.h>
#include "sml.h" // "SML-Parser" library by olliiiver
// --- UART to the WattWächter TTL -------------------------------------------
// ESP32 hardware UART2: RX2 = GPIO16, TX2 = GPIO17
#define TTL_RX_PIN 16 // -> green wire (RXD) of the WattWächter TTL
#define TTL_TX_PIN 17 // -> white wire (TXD), only needed for meters you must request
#define TTL_BAUD 9600
HardwareSerial MeterSerial(2); // UART2
// --- Values we want to read from every SML telegram ------------------------
double importWh = -1; // 1-0:1.8.0 energy drawn from grid (Wh)
double exportWh = -1; // 1-0:2.8.0 energy fed into grid (Wh)
double powerW = -1; // 1-0:16.7.0 current active power (W)
void handleImport() { smlOBISWh(importWh); }
void handleExport() { smlOBISWh(exportWh); }
void handlePower() { smlOBISW(powerW); }
// OBIS code (6 bytes) -> matching handler function
typedef struct {
const unsigned char OBIS[6];
void (*Handler)();
} OBISHandler;
OBISHandler handlers[] = {
{{ 0x01, 0x00, 0x01, 0x08, 0x00, 0xff }, &handleImport}, // 1-0:1.8.0 import (Wh)
{{ 0x01, 0x00, 0x02, 0x08, 0x00, 0xff }, &handleExport}, // 1-0:2.8.0 export (Wh)
{{ 0x01, 0x00, 0x10, 0x07, 0x00, 0xff }, &handlePower}, // 1-0:16.7.0 active power (W, signed)
{{ 0x01, 0x00, 0x0f, 0x07, 0x00, 0xff }, &handlePower}, // 1-0:15.7.0 active power (magnitude) – fallback
{{ 0, 0 }}
};
void setup() {
Serial.begin(115200);
MeterSerial.begin(TTL_BAUD, SERIAL_8N1, TTL_RX_PIN, TTL_TX_PIN);
Serial.println(F("WattWaechter TTL reader started"));
}
void loop() {
while (MeterSerial.available() > 0) {
unsigned char c = MeterSerial.read();
sml_states_t state = smlState(c);
// A list inside the telegram finished:
// check whether it carried one of the OBIS values we want.
if (state == SML_LISTEND) {
for (uint8_t i = 0; handlers[i].Handler != 0; i++) {
if (smlOBISCheck(handlers[i].OBIS)) {
handlers[i].Handler();
break;
}
}
}
// Full telegram received and CRC verified -> print the values.
if (state == SML_FINAL) {
Serial.printf("Import: %.3f kWh\n", importWh / 1000.0);
Serial.printf("Export: %.3f kWh\n", exportWh / 1000.0);
Serial.printf("Power: %.0f W\n\n", powerW);
}
}
}
Reading additional values
Simply extend the handlers table with more OBIS codes. The convenience functions smlOBISW() (watts), smlOBISVolt(), smlOBISAmpere() and smlOBISHertz() already return the value correctly scaled. Examples of common OBIS codes can be found under Additional OBIS codes.
Troubleshooting¶
| Problem | Possible cause / solution |
|---|---|
| No data received | Reading head not positioned correctly over the IR diode; green wire (RXD) not connected to the RX pin |
| Only energy counters, no power/phases | Disable the PIN and set Inf → On on the meter |
Checksum error / Unexpected byte |
Wrong baud rate/parity – check 9600 8N1; on the ESP8266 use the hardware UART instead of SoftwareSerial |
| Values off by a factor of 10/100 | Scaler not taken into account – use smlOBISWh()/smlOBISW(), they apply the scaler |