zibous / ha-watermeter

Data provider for smartmeter watermeter.
GNU General Public License v3.0
157 stars 27 forks source link

fault since last esphome update #46

Closed evilmumi closed 6 days ago

evilmumi commented 6 days ago

some I could fix but now:

INFO ESPHome 2024.6.4
INFO Reading configuration /config/esphome/testtestesp32.yaml...
INFO Updating https://github.com/SzczepanLeon/esphome-components.git@main
INFO Updating https://github.com/zdzichu6969/esphome-components.git@None
INFO Updating https://github.com/TheStaticTurtle/esphome_syslog.git@None
WARNING GPIO5 is a strapping PIN and should only be used for I/O with care.
Attaching external pullup/down resistors to strapping pins can cause unexpected failures.
See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins
INFO Generating C++ source...
INFO Backup config will take: 5400 bytes
INFO Compiling app...
Processing water-meter-esp (board: az-delivery-devkit-v4; framework: arduino; platform: espressif32)
--------------------------------------------------------------------------------
HARDWARE: ESP32 240MHz, 520KB RAM, 4MB Flash
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
Dependency Graph
|-- AsyncTCP-esphome @ 2.1.3
|-- WiFi @ 2.0.0
|-- FS @ 2.0.0
|-- Update @ 2.0.0
|-- ESPAsyncWebServer-esphome @ 3.2.2
|-- DNSServer @ 2.0.0
|-- ESPmDNS @ 2.0.0
|-- ArduinoJson @ 6.18.5
|-- Syslog @ 2.0.0
|-- WiFiClientSecure @ 2.0.0
|-- HTTPClient @ 2.0.0
|-- SPI @ 2.0.0
|-- SmartRC-CC1101-Driver-Lib @ 2.5.7+sha.b8c6af4
|-- wmbus-drivers @ 0.0.0+20240226111441.sha.1ad30e4
|-- noise-c @ 0.1.4
Compiling .pioenvs/water-meter-esp/src/main.cpp.o
Archiving .pioenvs/water-meter-esp/lib64d/libWiFi.a
Compiling .pioenvs/water-meter-esp/lib01c/FS/FS.cpp.o
Compiling .pioenvs/water-meter-esp/lib01c/FS/vfs_api.cpp.o
Compiling .pioenvs/water-meter-esp/libbc6/Update/HttpsOTAUpdate.cpp.o
Compiling .pioenvs/water-meter-esp/libbc6/Update/Updater.cpp.o
Compiling .pioenvs/water-meter-esp/libc0f/ESPAsyncWebServer-esphome/AsyncEventSource.cpp.o
Archiving .pioenvs/water-meter-esp/lib01c/libFS.a
Compiling .pioenvs/water-meter-esp/libc0f/ESPAsyncWebServer-esphome/AsyncWebSocket.cpp.o
Archiving .pioenvs/water-meter-esp/libbc6/libUpdate.a
Compiling .pioenvs/water-meter-esp/libc0f/ESPAsyncWebServer-esphome/WebAuthentication.cpp.o
/config/esphome/testtestesp32.yaml: In lambda function:
/config/esphome/testtestesp32.yaml:573:11: error: 'status_code' was not declared in this scope
                         if (status_code == 200) {
           ^          
/config/esphome/testtestesp32.yaml:573:11: note: suggested alternative: 'statusled'
                         if (status_code == 200) {
           ^          
           statusled
Compiling .pioenvs/water-meter-esp/libc0f/ESPAsyncWebServer-esphome/WebHandlers.cpp.o
Compiling .pioenvs/water-meter-esp/libc0f/ESPAsyncWebServer-esphome/WebRequest.cpp.o
*** [.pioenvs/water-meter-esp/src/main.cpp.o] Error 1
========================== [FAILED] Took 5.48 seconds ==========================`

I think it is about:
#45 `## ---------------------------------------------------
## COMPONENT SCRIPTS
## ---------------------------------------------------
script:

  # id(set_status_message).execute();
  - id: set_status_message
    then:
        - lambda: |-
            int msgcode = int(id(cc1101_state));
            std::string message = id(cc1101_state_message)[msgcode];
            ESP_LOGD("wmbus", "cc1101 state message: %s, error code: %d", message.c_str(), msgcode);
            id(watermeter_status_message).publish_state(message);

  # id(post_device_state).execute();
  - id: post_device_state
    then:
      - if:
          condition:
            lambda: return "${service_enabled} =='true'";
          then:
            - logger.log:
                tag: "system"
                level: INFO
                format: "Post new data to the ${service_url}${device_name_short}, service enabled: ${service_enabled}"
            - http_request.post:
                url: "${service_url}/${device_name_short}"

                headers:
                  Content-Type: application/json
                json: |-
                  root["device"] = "${device_name_short}";
                  root["waterdisplay"] = id(waterdisplay).state;
                  root["current"] = id(id(watercurrent)).state;
                  root["hour"] = id(waterhour).state;
                  root["day"] = id(waterday).state;
                  root["yesterday"] = id(wateryesterday).state;
                  root["week"] = id(waterweek).state;
                  root["month"] = id(watermonth).state;
                  root["lastmonth"] = id(waterhour).state;
                  root["year"] = id(wateryear).state;
                  root["bootcounter"] = id(bootcounter).state;
                  root["version"] = "${device_name_short} ${appversion}";
                  root["time"] = id(time_sntp).now().strftime("%Y-%m-%d %H:%M:%S");
                on_response:
                  then:
                    - lambda: |-
                        if (status_code == 200) {
                           ESP_LOGI ("system", "HTTP POST o.k");
                        } else {
                            ESP_LOGI ("system", "HTTP POST failed");
                        }
zibous commented 6 days ago

hi,

Try this:

## ---------------------------------------------------------------------------
## WMBUS METER az-delivery-devkit-v4 + CC1101 for Diehl IZAR RC 868 I R4 PL
## Hardware: ESP32 240MHz, 520KB RAM, 4MB Flash
##
## this version shows all watermeters. Use this for the first test
##
##  1. uses the latest wmbusmeter component from github
##
## ---------------------------------------------------------------------------
substitutions:

  ## device settings
  device_name_short: "water-meter-esp"
  device_description: "Wasserzähler ESP32, CUL - CC1101, IZAR module (Diehl IZAR RC 868 I R4 PL (SzczepanLeon) - all watermeters"
  projectname: "Diehl IZAR RC 868.Watermeter"
  appversion: "2.0.7"

  ## all watermeters   wmid: "0"
  ## your watermeter: wmid: !secret watermeterId
  wmid: "0"

  ## logger settings
  log_level: "VERBOSE"  # not that logging need memory, so in production mode use "WARN"
  log_wmbus: "VERBOSE" # Loglevel for wmbus meters component
  log_baudrate: "0" # 0 disable uart logger messages

## ----------------------------------------------------------------
## APPLICATION ESPHOME
## ----------------------------------------------------------------
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:
    priority: 200
    then:
      - globals.set:
          id: boot_counter
          value: !lambda "return id(boot_counter)+=1;"
      - logger.log:
          level: INFO
          tag: "system"
          format: "BOOTMESSAGE:${device_name_short} API is connected, Device ready!"
      - component.update: bootcounter
  on_shutdown:
    priority: 700
    then:
      - logger.log:
          level: ERROR
          tag: "system"
          format: "BOOTMESSAGE:${device_name_short} is down!"

## ----------------------------------------------------------------
## HARDWARE az-delivery-devkit-v4
##          ESP32 240MHz, 520KB RAM, 4MB Flash
## ----------------------------------------------------------------
esp32:
  board: az-delivery-devkit-v4
  framework:
    type: arduino

## ----------------------------------------------------------------
## EXTERNAL COMPONENTS
## ----------------------------------------------------------------
external_components:

  # uses the latest version 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@main
    refresh: 0s
    components: [wmbus]

## ----------------------------------------------------------------
## Global variables
## ----------------------------------------------------------------
globals:

  - id: boot_counter
    type: int
    restore_value: yes
    initial_value: "0"

  - id: last_value
    type: float
    restore_value: yes
    initial_value: "0.00"

  - id: alarm_error_text
    type: std::vector<std::string>
    restore_value: no
    initial_value: '{"no error", "general_alarm","leakage","meter_blocked","back_flow","underflow","overflow","submarine","sensor_fraud","mechanical_fraud"}'

## ---------------------------------------------------
## WIFI Settings 3 wifis
## ---------------------------------------------------
wifi:
  networks:
    - ssid: !secret ssid3_name
      password: !secret ssid3_pswd
      priority: 0
    - ssid: !secret ssid1_name
      password: !secret ssid1_pswd
      priority: 1
    - ssid: !secret ssid2_name
      password: !secret ssid2_pswd
      priority: 2
  domain: !secret domain

## ---------------------------------------------------
## The captive portal component in ESPHome is a
## fallback mechanism for when connecting to the
## configured WiFi fails.
## ---------------------------------------------------
captive_portal:

## ---------------------------------------------------
## LOGGER COMPONENT
## ---------------------------------------------------
logger:
  id: appslogger
  level: ${log_level}
  baud_rate: ${log_baudrate}
  logs:
    wmbus: ${log_wmbus}
    wMBus-lib: ${log_wmbus}

## ---------------------------------------------------
## OTA COMPONENT
## see: https://esphome.io/components/ota/esphome.html
## ---------------------------------------------------
ota:
  - platform: esphome
    password: !secret ota_pswd

## ---------------------------------------------------
## COMPONENT WEBSERVER
## ---------------------------------------------------
web_server:
  port: 80
  version: 2

## ---------------------------------------------------
## Home Assistant API COMPONENT
## ---------------------------------------------------
api:
  id: espapi_wmbus_esp32
  port: 6053
  reboot_timeout: 0s

## ---------------------------------------------------
## SNTP COMPONENT
## ---------------------------------------------------
time:
  - platform: sntp
    id: time_sntp
    timezone: Europe/Berlin
    servers:
      - 0.at.pool.ntp.org
      - 0.pool.ntp.org
      - 1.pool.ntp.org
    on_time_sync:
      then:
        - logger.log:
            tag: "system"
            level: INFO
            format: "Synchronized sntp clock"

## ------------------------------------------------------------------
##           WMBUS CC1101 --> ESP32 az-delivery-devkit-v4
## ------------------------------------------------------------------
##
##
##                                                               o 1 (3.3V)
##                                                               |
##   ╭――x――x――x――x――x――x――x――x――x――x――x――x――x――x――x――x――x――x――x――o―╮
##   |                                                             |
##   |                                                             |
## - | 5v               az-delivery-devkit-v4                      | -- ANT
##   |                                                             |
##   |                          16 17 5  18 19               23    |
##   ╰――x――x――x――x――x――x――x――x――o――x――o――o――o――o――o――o――o――o――o――o―╯
##                              |  |  |  |  |                 |   |
##                              o  |  |  o  |                 |   ╰-o - 2 (GND)
##                              7  o  |  4  o                 o
##                            GDO0 6  | CLK 5                 3
##                               GD02 o    MISO              M0SI
##                                    8
##                                   CSN
##
## ------------------------------------------------------------------
wmbus:
  mosi_pin: GPIO23    ## SI:   braun
  miso_pin: GPIO19    ## SO:   grün
  clk_pin: GPIO18     ## SCLK: violett
  cs_pin: GPIO05      ## CSN:  orange
  gdo0_pin: GPIO16    ## GD00: gelb (rx)
  gdo2_pin: GPIO17    ## GD02: weiss (tx)

  # log_unknown (Optional): Show telegrams from not configured meters in log.
  # Defaults to False
  log_unknown: True

## ---------------------------------------------------
## SWITCHES
## ---------------------------------------------------
switch:
  # reset boot counter value
  - platform: template
    name: Device Boot Counter 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

  - platform: safe_mode
    name: "Device Restart (Safe Mode)"

  - platform: restart
    name: "Restart"
    id: restart_switch

  - platform: factory_reset
    name: Device Restart Factory

## ---------------------------------------------------
## SENSORS
## ---------------------------------------------------
sensor:

  - platform: wmbus
    # 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
    meter_id: ${wmid}
    type: izar
    add_prefix: true

    # 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"
      unit_of_measurement: "lqi"
      entity_category: "diagnostic"

    # 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.
    rssi:
      id: wmbus_cc1101_rssi
      name: "Watermeter CC1101 RSSI"
      unit_of_measurement: "%"
      entity_category: "diagnostic"

    # reports the watermeter display value
    total_water_m3:
      id: "waterdisplay"
      name: "Watermeter Display"
      unit_of_measurement: "m³"
      state_class: total_increasing
      device_class: "water"
      accuracy_decimals: 3
      icon: mdi:counter
      # update and calulatet all watermeter data values
      on_value:
        then:
          - lambda: |-
              ESP_LOGI("wmbus", "Water Display value: %.3f, last value: %.3f", id(waterdisplay).state, id(last_value));
              id(last_value)=id(waterdisplay).state;

    # get the last month total watermter m3 from the wmbus telegram  (wM-Bus 2.1.10)
    last_month_total_water_m3:
      name: "Water last month"
      id: "waterdisplay_lastmonth"
      unit_of_measurement: "m³"
      state_class: total_increasing
      device_class: "water"
      accuracy_decimals: 3
      icon: mdi:counter

    # 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"
      accuracy_decimals: 2
      unit_of_measurement: "Years"
      icon: mdi:battery

    # get the last transmit periode (wM-Bus v2.1.4)
    transmit_period_s:
      name: "Watermeter transmit periode"
      id: "watermeter_transmit_periode"
      unit_of_measurement: "sec"
      accuracy_decimals: 2
      icon: mdi:timelapse

    ## get the current watermeter alarms and publish the text message (wM-Bus 2.1.10)
    current_alarms:
      id: "watermeter_current_alarms"
      name: "Watermeter current alarm code"
      icon: mdi:alarm-light
      entity_category: "diagnostic"

    ## get the prevois watermeter alarms and publish the text message (wM-Bus 2.1.10)
    previous_alarms:
      id: "watermeter_previous_alarms"
      name: "Watermeter pervious alarm code"
      icon: mdi:alarm-light
      entity_category: "diagnostic"

  # Wifi quality RSSI, internal used to calculate the Wifi quality RSSI in percentage
  - platform: wifi_signal
    id: wifi_signal_db
    update_interval: 60s
    internal: true
    disabled_by_default: true

  # Wifi quality RSSI in percentage
  # Received Signal Strength (RSSI) is a measure of incoherent
  ## (raw) RF power in a channel.
  - platform: copy # Reports the WiFi signal strength in %
    source_id: wifi_signal_db
    name: "Device WLAN Signal"
    filters:
      - lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
    unit_of_measurement: "%"
    entity_category: "diagnostic"

  # device boot counter
  - platform: template
    name: Device Boot counter
    id: bootcounter
    icon: mdi:counter
    accuracy_decimals: 0
    state_class: "measurement"
    entity_category: "diagnostic"
    lambda: return (id(boot_counter));
evilmumi commented 6 days ago

found a solution one line has to be changed if (response->status_code == 200) {

patmtp35 commented 6 days ago

hi thanks working without the http section , as i use it with HA it's ok