Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save KrzysztofHajdamowicz/199c815c3a7fe7d2b445ee801d70f90e to your computer and use it in GitHub Desktop.
Save KrzysztofHajdamowicz/199c815c3a7fe7d2b445ee801d70f90e to your computer and use it in GitHub Desktop.
Home Assistant + ESPHome + wmbusmeters
substitutions:
ssid: !secret wifi_ssid
password: !secret wifi_password
esphome:
name: esp_wmbus
esp8266:
board: nodemcuv2
# Enable logging
logger:
level: DEBUG
# Enable Home Assistant API
api:
encryption:
key: "redacted"
ota:
password: "redacted"
external_components:
- source: github://SzczepanLeon/esphome-components@main
components: [ wmbus ]
wifi:
ssid: ${ssid}
password: ${password}
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Esp-Wmbus Fallback Hotspot"
password: "redacted"
captive_portal:
web_server:
port: 80
time:
platform: sntp
wmbus:
mosi_pin: GPIO13
miso_pin: GPIO12
clk_pin: GPIO14
cs_pin: GPIO15
gdo0_pin: GPIO5
gdo2_pin: GPIO4
clients:
- name: "wmbusmeters"
ip_address: "192.168.0.2"
port: 9022
format: RTLWMBUS
transport: TCP

This manual will show you how to acheive "remote" wmbus metering.

ESP stick

You will need to grab NodeMCU V2 development board and CC1101 radio transceiver.
Feel free to use something like this:
https://forum.arturhome.pl/t/komponent-do-esphome-umozliwiajacy-odczyt-miernikow-wm-bus-i-transmisje-wyniku-do-ha/7548

ESPHome configuration

Use config esp_wmbus.yaml.
In this configuration, ESP stick will stream all received telegrams to wmbusmeters running as your Home Assistant addon.

HA Addon Configuration

Current wmbusmeters addon configuration is somehow broken.
I created a pull request fixing this issue, but it's a breaking change for current users.
wmbusmeters/wmbusmeters#838
For now, you can use my forked repo.

  1. Go to Home Assistant → SettingsAdd-ons
  2. Click ADD-ON STORE
  3. Upper-right corner click 3 dots → Repositories
  4. Add Repository https://github.com/KrzysztofHajdamowicz/wmbusmeters
  5. Install wmbusmeters addon
  6. Configure Your instance:
    enable_mqtt_discovery set to true
    conf:
loglevel: normal
device: rtlwmbus:CMD(nc -lk 9022)
donotprobe: /dev/ttyAMA0
logtelegrams: false
format: json
logfile: /dev/stdout
shell: /wmbusmeters/mosquitto_pub.sh "wmbusmeters/$METER_NAME" "$METER_JSON"

meters

  - name: ElectricityMeter
    driver: amiplus
    id: "12345678" #Note "123" casts number as string
    key: DEADBEEF1337DEADBEEF1337DEADBEEF
  - name: WaterMeter
    driver: apator162
    id: "87654321" #Note "123" casts number as string
    key: "00000000000000000000000000000000"  #Note "123" casts number as string
  1. in Network section, add port 9022 as TCP listener
@Woodpeckercz
Copy link

Hi,

thanks for putting this together.
I'm having some issues with compiling this.
I use the ESPHome addon in homeassistant and when I try to compile this, I'm getting the following error.

`In file included from /data/esp_wmbus/.piolibdeps/esp_wmbus/wMbus-lib/rf_mbus.cpp:6:
/data/esp_wmbus/.piolibdeps/esp_wmbus/wMbus-lib/tmode_rf_settings.hpp:8:10: fatal error: ELECHOUSE_CC1101_SRC_DRV.h: No such file or directory



8 | #include <ELECHOUSE_CC1101_SRC_DRV.h>
  |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

compilation terminated.
*** [/data/esp_wmbus/.pioenvs/esp_wmbus/lib521/wMbus-lib/rf_mbus.cpp.o] Error 1
========================= [FAILED] Took 52.25 seconds =========================`

Can you please help me?

@mortenx
Copy link

mortenx commented Apr 19, 2024

What this means ..."Can't get value" ?
it seems like only some telegrams are working

`[15:18:22][D][sntp:080]: Synchronized time: 2024-04-18 15:16:19
[15:18:54][D][mbus:023]: Processing C1 B frame
[15:18:54][D][wmbus:097]: Using driver 'multical21' for ID [0x76395254] RSSI: -72 dBm LQI: 168 Frame: C1 B T: 21442D2C545239761B168D281AA830C820E00023BCF54216DCC001B0D4202FB106F0 (34)
[15:18:54][D][wmbus:104]: Decrypted T : 21442D2C545239761B168D281AA830C8203AB97934DD82AF71000600000002000000 (34)
[15:18:54][D][wmbus:161]: Can't get value(s) from telegram for ID [0x76395254]

[15:21:51][D][mbus:034]: Processing T1 A frame
[15:22:09][D][mbus:023]: Processing C1 B frame
[15:22:09][D][wmbus:097]: Using driver 'multical21' for ID [0x76395254] RSSI: -72 dBm LQI: 156 Frame: C1 B T: 21442D2C545239761B168D281CD030C820D96CD99578EA9173DC08789CD761993124 (34)
[15:22:09][D][wmbus:104]: Decrypted T : 21442D2C545239761B168D281CD030C8203AB97934DD82AF71000600000002000000 (34)
[15:22:09][D][wmbus:161]: Can't get value(s) from telegram for ID [0x76395254]`

@mortenx
Copy link

mortenx commented May 9, 2024

(The Multical21 and other meters use compressed telegrams, which means that you might have to wait up to 8 telegrams (8*16 seconds) until you receive a full length telegram which gives all the information needed to decode the compressed telegrams.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment