## ------------------------------------------------------------------ ## WMBUS METER D1 MINI + CC1101 for Diehl IZAR RC 868 I R4 PL ## HARDWARE: D1 MINI ESP8266 80MHz, 80KB RAM, 4MB Flash ## ## usage: 1. Using wM-Bus v2.1.4 ## 2. Using Homassistant API (discovery + devices) ## ## This version shows data from the defined watermeter and ## uses the watermeterID (HEX) from the secrets.yaml file. ## ## ------------------------------------------------------------------ substitutions: ## device settings device_name_short: "water-meter-dmini" device_description: "Watermeter Wemos D1 Mini + EBYTE TI CC1101, IZAR module (Diehl IZAR RC 868 I R4 PL (SzczepanLeon) - my Watermeter" projectname: "Diehl IZAR RC 868.Watermeter" friendly_name: "Watermeter" # device name appversion: "3.0.0" ## logger settings log_level: "WARN" # not that logging need memory, so in production mode use "WARN" log_wmbus: "ERROR" # Loglevel for wmbus meters component log_baudrate: "0" # use 115200 to enable serial UART port logging. ## ---------------------------------------------------------------- ## HARDWARE: D1 MINI ESP8266 80MHz, 80KB RAM, 4MB Flash ## ---------------------------------------------------------------- esp8266: board: d1_mini restore_from_flash: true ## ---------------------------------------------------------------- ## ESPHOME APPLICATION ## ---------------------------------------------------------------- esphome: name: ${device_name_short} comment: ${device_description} # Automatically add the mac address to the name # so you can use a single firmware for all devices name_add_mac_suffix: false project: name: ${projectname} version: ${appversion} build_path: ./build/${device_name_short} on_boot: then: - globals.set: id: boot_counter value: !lambda "return id(boot_counter)+=1;" - globals.set: id: send_millisecond value: !lambda "return millis();" - logger.log: level: WARN tag: "system" format: "BOOTMESSAGE:${device_name_short} API is connected, Device ready!" - component.update: bootcounter on_shutdown: then: - logger.log: level: ERROR tag: "system" format: "BOOTMESSAGE:${device_name_short} is down!" ## --------------------------------------------------- ## External components ## --------------------------------------------------- external_components: # uses the version 3 from SzczepanLeon # https://github.com/SzczepanLeon/esphome-components # You can make ESPHome check the repository every time by setting this option to 0s - source: github://SzczepanLeon/esphome-components@version_3 refresh: 0s components: [wmbus] ## --------------------------------------------------- ## LOGGER COMPONENT ## --------------------------------------------------- logger: id: appslogger level: ${log_level} baud_rate: ${log_baudrate} logs: wmbus: ${log_wmbus} wMBus-lib: ${log_wmbus} sensor: WARN sensor.filter: WARN text_sensor: WARN api.service: ERROR json: ERROR mqtt: WARN scheduler: ERROR wifi: WARN component: ERROR api: WARN # internal_temperature: ERROR ## ---------------------------------------------------------------- ## Global variables ## ---------------------------------------------------------------- globals: - id: boot_counter type: int restore_value: yes initial_value: "0" - id: send_millisecond type: int restore_value: no initial_value: "0" - id: current_value type: float restore_value: yes initial_value: "0.00" ## --------------------------------------------------- ## WIFI Settings ## --------------------------------------------------- wifi: networks: # unifi accesspoint 2.4Ghz - ssid: !secret ssid4_name password: !secret ssid4_pswd priority: 1 # office apple capsulate accesspoint 2.4Ghz - ssid: !secret ssid3_name password: !secret ssid3_pswd priority: 2 # living room apple capsulate accesspoint 2.4Ghz - ssid: !secret ssid2_name password: !secret ssid2_pswd priority: 3 domain: !secret domain ## --------------------------------------------------- ## mDNS Component ## --------------------------------------------------- mdns: # if mDNS is disabled, they will no longer be able to automatically find your devices. disabled: false ## --------------------------------------------------- ## COMPONENT CAPTIVE PORTAL ## --------------------------------------------------- captive_portal: ## --------------------------------------------------- ## OTA COMPONENT ## --------------------------------------------------- ota: password: !secret ota_pswd platform: esphome on_begin: then: - logger.log: format: "OTA Start" tag: "OTA" level: WARN on_progress: then: - logger.log: level: WARN tag: "OTA" format: "OTA progress %0.1f%%" args: ["x"] on_end: then: - logger.log: format: "OTA End" tag: "OTA" level: WARN on_error: then: - logger.log: format: "OTA update error %d" tag: "OTA" level: ERROR args: ["x"] ## --------------------------------------------------- ## COMPONENT WEBSERVER ## --------------------------------------------------- web_server: port: 80 version: 2 js_url: !secret webserver_jsurl ## --------------------------------------------------- ## Home Assistant API COMPONENT ## --------------------------------------------------- api: id: espapiwm2_d1 port: 6053 reboot_timeout: 0s # https://esphome.io/components/api.html?highlight=api encryption: key: "inH49O9jBeK5yTGb1X2g4WV/1aS6YKUpu3Vu277fDgw=" ## --------------------------------------------------- ## DEBUG COMPONENT ## --------------------------------------------------- debug: update_interval: 5s ## --------------------------------------------------- ## SNTP Time server ## --------------------------------------------------- time: - platform: sntp id: time_sntp timezone: Europe/Berlin servers: - !secret local_sntp - 0.at.pool.ntp.org - 0.pool.ntp.org on_time_sync: # Components should trigger on_time_sync when they update the system clock. then: - if: condition: lambda: 'return id(device_lastBoot_time).state == "";' then: - text_sensor.template.publish: id: device_lastBoot_time state: !lambda return id(time_sntp).now().strftime("%Y-%m-%dT%H:%M:%S %Z"); - logger.log: level: WARN tag: "system" format: "Synchronized sntp clock" ## --------------------------------------------------- ## WMBUS DEVICE D1MINI WEMOS --> CC1101 ## --------------------------------------------------- ## ## GDO0 ## o ## 7 ## | GD02 ╭-------o 2 (GND) ## | 6 ## | o | ## | | | ## ╭――x――x――o――o――x――x――x――o――╮ ## │ D1 D2 - │ ## │ │ ## │ D1MINI WEMOS │ ## ANT │ │ USB ## │ │ ## │ D5 D6 D7 D8 + │ ## ╰――x――x――x――o――o――o――o――o――╯ ## | | | | | ## | | | | ╰-----o 1 (+3.3V) ## | o | o ## | 5 | 8 ## | MISO| CSN ## o o ## 4 3 ## CLK MOSI ## ## -------------------------------------------------- wmbus: mosi_pin: GPIO13 #D7 MOSI Attached to Hardware SPI controller MOSI SPI Interface miso_pin: GPIO12 #D6 MISO Attached to Hardware SPI controller MISO SPI Interface clk_pin: GPIO14 #D5 SCK Attached to Hardware SPI controller CLK cs_pin: GPIO15 #D8 CSN Attached to Hardware SPI controller, Controls Boot Mode; CS SPI Interface 10k Pull-Down, boot fails if pulled high !!! gdo0_pin: GPIO04 #D1 SDA Clock output. High Impedance ! gdo2_pin: GPIO05 #D2 SCL FIFO status signals. High Impedance ! # log_unknown (Optional): Show telegrams from not configured meters in log. log_unknown: False ## --------------------------------------------------- ## Using wmbusmeters i a pipe ## enable this if you have wmbusmeters installed ## --------------------------------------------------- ## clients: ## - name: "wmbusmeters" ## ip_address: !secret wmbusmeter_host ## port: 7227 ## format: rtlwMBus ## transport: UDP ## --------------------------------------------------- ## BINARY SENSOR ## --------------------------------------------------- binary_sensor: # simulate led state - platform: template name: "Wasseruhr Status Led" id: statusled icon: mdi:led-outline entity_category: "diagnostic" lambda: "return id(current_value) > 0;" ## --------------------------------------------------- ## SENSORS ## --------------------------------------------------- sensor: # watermeter 1: nearly to mine - platform: wmbus meter_id: 0x43410778 type: izar add_prefix: True # get the total watermter m3 from the wmbus telegram total_water_m3: name: "Watermeter" unit_of_measurement: "m³" state_class: total_increasing device_class: "water" accuracy_decimals: 3 icon: mdi:counter # watermeter 2: nearly to mine - platform: wmbus meter_id: 0x43890785 type: izar add_prefix: True # get the total watermter m3 from the wmbus telegram total_water_m3: name: "Watermeter" unit_of_measurement: "m³" state_class: total_increasing device_class: "water" accuracy_decimals: 3 icon: mdi:counter # watermeter 3: My Watermeter - platform: wmbus # My Meter ID (usually from sticker). Can be specified as decimal or hex. # only hex is working for my watermeter ! # see: https://github.com/SzczepanLeon/esphome-components/issues/6 # edit watermeterid in the secrets file ## add_prefix settings to add the watermeterid to the lqi, rssi and total_water_m3 meter_id: !secret watermeterId type: izar add_prefix: false # get the total watermter m3 from the wmbus telegram total_water_m3: name: "Watermeter display" id: "waterdisplay" unit_of_measurement: "m³" state_class: total_increasing device_class: "water" accuracy_decimals: 3 icon: mdi:counter # get the last month total watermter m3 from the wmbus telegram (wM-Bus v2.1.4) last_month_total_water_m3: name: "Watermeter Display last month" id: "waterdisplay_lastmonth" unit_of_measurement: "m³" state_class: total_increasing device_class: "water" accuracy_decimals: 3 # water current month (wM-Bus v2.1.4) current_month_total_water_l: name: Water current month id: "watermonth" accuracy_decimals: 2 unit_of_measurement: "L" state_class: total_increasing device_class: "water" # get the battery life time (wM-Bus v2.1.4) remaining_battery_life_y: name: "Watermeter Battery Life" id: "watermeter_batterie" entity_category: "diagnostic" unit_of_measurement: "Years" accuracy_decimals: 2 icon: mdi:battery # get the last transmit periode (wM-Bus v2.1.4) transmit_period_s: name: "Watermeter Periode" id: "watermeter_last_reading" entity_category: "diagnostic" accuracy_decimals: 2 icon: mdi:timelapse # current alarm code current_alarms: name: "Watermeter current alarm" id: "watermeter_current_alarms" entity_category: "diagnostic" icon: mdi:alarm-light # previous alarm code previous_alarms: name: "Watermeter previous alarm" id: "watermeter_prev_alarms" entity_category: "diagnostic" icon: mdi:alarm-light # The LQI value reported by the CC1101 is a 7 bit unsigned number with a range from 0 to 127. # Note that a lower value indicates a better link. # The LQI of a received packet will be bad (higher number) when there is lot of interference. lqi: id: wmbus_cc1101_lqi name: "Watermeter CC1101 LQI" entity_category: "diagnostic" unit_of_measurement: "lqi" state_class: "measurement" # The RSSI value reported by the CC1101 is a 8 bit signed number with an effective # range from -138 dBm to -10.5 dBm when the CC1101 is operating around 868 MHz. # RSSI stands for received signal strength (power) indication (in dBm). # A higher value indicates higher power. (internal only) rssi: id: wmbus_cc1101_rssi name: "Watermeter CC1101 RSSI" filters: - lambda: return min(max(2 * (x + 100.0), 0.0), 100.0); unit_of_measurement: "%" entity_category: "diagnostic" # Wifi quality RSSI used by wifi_signal_db - platform: wifi_signal name: "Device WLAN RSSI Quality" id: wifi_signal_db update_interval: 60s filters: - lambda: return min(max(2 * (x + 100.0), 0.0), 100.0); unit_of_measurement: "%" entity_category: "diagnostic" # The debug component can be used to debug problems with ESPHome. # At startup, it prints a bunch of useful information like reset reason, # free heap size, ESPHome version and so on. - platform: debug # Reports the free heap size in bytes. free: name: "Device Heap Free" id: heapfreekb filters: - lambda: return x * 0.0009765625; unit_of_measurement: "KB" entity_category: "diagnostic" state_class: "measurement" # Reports the fragmentation metric of the heap (0% is clean, more than ~50% is not harmless). fragmentation: name: "Device Heap Fragmentation" id: curfragm unit_of_measurement: "%" entity_category: "diagnostic" state_class: "measurement" # Reports the largest contiguous free RAM block on the heap in bytes. block: name: "Device Heap Max Block" id: heepmaxblockkb filters: - lambda: return x * 0.0009765625; unit_of_measurement: "KB" entity_category: "diagnostic" state_class: "measurement" # Uptime device in hours - platform: uptime name: "${friendly_name} Online seit" id: uptime_human icon: mdi:clock-start filters: - lambda: return x / 3600; unit_of_measurement: "h" entity_category: "diagnostic" state_class: "measurement" accuracy_decimals: 2 # device boot counter - platform: template name: Device Boot counter id: bootcounter accuracy_decimals: 0 state_class: "measurement" entity_category: "diagnostic" lambda: return (id(boot_counter)); ## --------------------------------------------------- ## SWITCHES ## --------------------------------------------------- switch: # reset boot counter value - platform: template name: "Device Boot Counter Reset" icon: mdi:lock-reset turn_on_action: then: - lambda: |- id(boot_counter) = 0; id(bootcounter).publish_state(id(boot_counter)); - logger.log: level: WARN tag: "system" format: "${device_name_short} reset boot counter o.k!" - component.update: bootcounter # restarts the device - platform: restart name: "Restart Device" id: restart_switch icon: mdi:restart text_sensor: # Last boot timestamp (only on webserver) - platform: template name: "Device Last Boot" disabled_by_default: true id: device_lastBoot_time icon: mdi:clock-start # optional device timestamp (only for webserver) - platform: template id: systime disabled_by_default: true icon: mdi:clock-start lambda: return id(time_sntp).now().strftime("%Y-%m-%dT%H:%M:%S %Z"); # optional device version (only on webserver) - platform: version name: "ESPHome Version" icon: mdi:application-cog-outline id: appver hide_timestamp: true disabled_by_default: true # connected to ssid (only for webserver) - platform: wifi_info ssid: name: ${friendly_name} WLAN SSID id: wlan_ssid disabled_by_default: true icon: mdi:wifi-settings