substitutions:
  name: "waassercompteur"
  friendly_name: "Waassercompteur"

esphome:
  name: "${name}"
  friendly_name: "${friendly_name}"
  name_add_mac_suffix: false
  project:
    name: wmbus.UltimateReader
    version: "1.2.5"

esp32:
  board: lilygo-t3-s3
  framework:
    type: esp-idf

external_components:
  - source: github://SzczepanLeon/esphome-components@main
    refresh: 0d

dashboard_import:
  package_import_url: github://SzczepanLeon/esphome-components/UltimateReader_v5.yaml@main
  import_full_config: true

logger:
  id: component_logger
  level: WARN
  baud_rate: 115200

psram:

wifi:
  ap:

captive_portal:

time:
  - platform: homeassistant

api:
  reboot_timeout: 0s

ota:
  - platform: esphome

web_server:
  version: 3 

spi:
  clk_pin:
    number: GPIO5
  mosi_pin: GPIO6
  miso_pin:
    number: GPIO3
    ignore_strapping_warning: true

debug:

wmbus_radio:
  radio_type: SX1276
  cs_pin: GPIO7
  reset_pin: GPIO8
  irq_pin: GPIO33
  on_frame:
    - then:
        - logger.log:
            format: "RSSI: %ddBm T: %s (%d) %s"
            args: [ frame->rssi(), frame->as_hex().c_str(), frame->data().size(), toString(frame->link_mode()) ]
    - then:
        - repeat:
            count: 3
            then:
              - output.turn_on: status_led
              - delay: 100ms
              - output.turn_off: status_led
              - delay: 100ms

wmbus_common:
    drivers: all
output:
  - platform: gpio
    id: status_led
    pin:
      number: GPIO37

wmbus_meter:
  - id: water_meter
    meter_id: 0x[ID VUM SENSUS iPERL Compteur]
    type: iperl
    key: "E6C88800DEB868C0D6A84880CE982840"

sensor:
  - platform: wmbus_meter
    parent_id: water_meter
    field: total_m3
    name: Waasser Compteur total m3
    accuracy_decimals: 3
    unit_of_measurement: "m³"
    device_class: "water"
    state_class: "total_increasing"
    icon: "mdi:water"

  - platform: wifi_signal
    name: "WiFi Signal dB"
    id: wifi_signal_db
    internal: true
    update_interval: 60s
    entity_category: "diagnostic"

  - platform: copy
    source_id: wifi_signal_db
    name: "WiFi Signal %"
    icon: mdi:wifi
    filters:
      - lambda: return {min(max(2 * (x + 100.0), 0.0), 100.0)};
    unit_of_measurement: "%"
    entity_category: "diagnostic"

  - platform: uptime
    type: seconds
    name: Uptime

text_sensor:
  - platform: wmbus_meter
    parent_id: water_meter
    name: "Zäitstempel"
    field: "timestamp"
    icon: mdi:clock
  - platform: debug
    reset_reason:
      name: "Reset Reason"