ESPHome¶
With ESPHome you bring the meter values into Home Assistant over Wi-Fi via an ESP32, without writing a single line of code. SML decoding is already built into ESPHome. You plug the WattWächter TTL onto the ESP32, add a few lines to the configuration and flash it.
You need:
- An ESP32 with a pin header, e.g. an ESP32-DevKitC with ESP32-WROOM-32
- Home Assistant with the ESPHome Builder app/add-on (or ESPHome on your computer)
- A prepared meter that sends SML and is unlocked with the PIN
SML meters only
The ESPHome sml component reads meters that send SML on their own. That is almost all modern meters. It does not read meters that have to be requested first (IEC 62056-21, footnote ⁴ under Supported meters). For those, use Arduino, Python or a WattWächter Plus.
1. Connect¶
Plug the cable into the reading head with its USB-C plug and put the wires onto the ESP32:
| Wire | ESP32 |
|---|---|
| Red | 3V3 |
| Black | GND |
| Green | GPIO16 (RX2) |
| White | not needed |
Red to 3V3, not to 5V
The TTL's data line carries the level of its supply. The ESP32 only tolerates 3.3 V on its pins. So connect the red wire to 3V3, not to 5V or VIN.
ESP32-WROVER
On modules with PSRAM (ESP32-WROVER), GPIO16 is occupied. Use e.g. GPIO25 there and enter it as rx_pin below.
2. Configuration¶
Create a new device in the ESPHome Builder (+ New device, type ESP32). The wizard generates the base configuration with Wi-Fi, API key and OTA. Add the uart, sml and sensor blocks below it:
uart:
id: uart_zaehler
rx_pin: GPIO16 # green wire (RXD) of the WattWächter TTL
baud_rate: 9600
sml:
id: zaehler
uart_id: uart_zaehler
sensor:
- platform: sml
name: "Import total"
sml_id: zaehler
obis_code: "1-0:1.8.0"
unit_of_measurement: kWh
accuracy_decimals: 3
device_class: energy
state_class: total_increasing
filters:
- multiply: 0.0001
- platform: sml
name: "Export total"
sml_id: zaehler
obis_code: "1-0:2.8.0"
unit_of_measurement: kWh
accuracy_decimals: 3
device_class: energy
state_class: total_increasing
filters:
- multiply: 0.0001
- platform: sml
name: "Power"
sml_id: zaehler
obis_code: "1-0:16.7.0"
unit_of_measurement: W
accuracy_decimals: 0
device_class: power
state_class: measurement
Complete configuration for comparison
This is what the whole file looks like. The wizard generates the header up to and including wifi; the credentials are in secrets.yaml.
esphome:
name: wattwaechter-ttl
friendly_name: WattWächter TTL
esp32:
board: esp32dev
framework:
type: esp-idf
logger:
api:
ota:
- platform: esphome
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
uart:
id: uart_zaehler
rx_pin: GPIO16
baud_rate: 9600
sml:
id: zaehler
uart_id: uart_zaehler
sensor:
- platform: sml
name: "Import total"
sml_id: zaehler
obis_code: "1-0:1.8.0"
unit_of_measurement: kWh
accuracy_decimals: 3
device_class: energy
state_class: total_increasing
filters:
- multiply: 0.0001
- platform: sml
name: "Export total"
sml_id: zaehler
obis_code: "1-0:2.8.0"
unit_of_measurement: kWh
accuracy_decimals: 3
device_class: energy
state_class: total_increasing
filters:
- multiply: 0.0001
- platform: sml
name: "Power"
sml_id: zaehler
obis_code: "1-0:16.7.0"
unit_of_measurement: W
accuracy_decimals: 0
device_class: power
state_class: measurement
If your meter has no export, the "Export total" sensor stays empty. You can then leave it out.
3. Flash¶
The first time, you flash via USB: connect the ESP32 to your computer and choose Install → Plug into this computer in the ESPHome Builder (Chrome or Edge). With ESPHome on your computer, use esphome run wattwaechter-ttl.yaml. ESPHome installs all later changes over Wi-Fi.
4. Check that data arrives¶
Attach the head to the meter (cable pointing up) and open the Logs in the ESPHome Builder. If everything is right, new values usually arrive every second:
[D][sml:078]: OBIS info:
[D][sml:084]: (0a015341472001711c3f) 1-0:1.8.0 [0x00000000000cdf82]
[D][sml:084]: (0a015341472001711c3f) 1-0:2.8.0 [0x000000000000e896]
[D][sml:084]: (0a015341472001711c3f) 1-0:16.7.0 [0x0000000000000028]
[D][sensor:093]: 'Import total': Sending state 84.36500 kWh with 3 decimals of accuracy
[D][sensor:093]: 'Export total': Sending state 5.95420 kWh with 3 decimals of accuracy
[D][sensor:093]: 'Power': Sending state 40.00000 W with 0 decimals of accuracy
The lines under OBIS info show all values your meter sends, with the raw value in square brackets. The Sending state lines are the finished sensor values.
Compare the factor with the meter display
ESPHome passes on the raw value from the telegram without applying the meter's scaler. Compare "Import total" with the reading on the display. In the example above, the raw value 0xcdf82 = 843,650, times 0.0001 gives 84.365 kWh. If your value is off by a factor of 10, 100 or 1000, adjust multiply. The power in W fits without a factor on most meters.
5. Add to Home Assistant¶
Home Assistant discovers the new ESPHome device automatically and shows it under Settings → Devices & services. After Add, the three sensors are available.
For the Energy dashboard, go to Settings → Dashboards → Energy and enter "Import total" as grid consumption and "Export total" as return to grid.
Troubleshooting¶
| Problem | Possible cause / solution |
|---|---|
No OBIS info in the log, green LED dark |
Red on 3V3 and black on GND? USB-C plug fully inserted in the head? Center the head, cable pointing up |
No OBIS info in the log, green LED flashes |
Green on GPIO16? Use another pin on an ESP32-WROVER. Does the meter send D0 instead of SML (see above)? |
Only 1.8.0, no 16.7.0 |
Meter not unlocked, see Meter preparation |
| Values off by a factor of 10/100/1000 | Adjust multiply, see above |
ESP32 keeps restarting (POWERON_RESET), USB connection drops |
The power supply collapses as soon as Wi-Fi starts. Use a different USB cable or power supply, don't run it from a passive USB hub |