From 8d8e6bf5c72f441cb38e9a3c195453eb63623473 Mon Sep 17 00:00:00 2001 From: mhendriks Date: Sat, 9 Mar 2024 22:25:14 +0100 Subject: [PATCH] changing the pulse_meter to pulse_counter + some logic to restore the total value --- p1-dongle-pro-h2o-v2.yaml | 61 +++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/p1-dongle-pro-h2o-v2.yaml b/p1-dongle-pro-h2o-v2.yaml index 605d8f4..0d882f9 100644 --- a/p1-dongle-pro-h2o-v2.yaml +++ b/p1-dongle-pro-h2o-v2.yaml @@ -2,7 +2,7 @@ substitutions: device_name: p1-dongle-pro-h2o device_description: "P1 Dongle Pro + H2O v2" friendly_name: P1 Dongle Pro H2O - prj_version: "2024.02.02" + prj_version: "2024.03.01" esphome: name: ${device_name} @@ -26,13 +26,19 @@ api: then: - button.press: id: reboot - - service: set_water_total + - service: set_water_reading variables: - new_total: int + meter_value: int then: - - pulse_meter.set_total_pulses: - id: h2o_pulse - value: !lambda 'return new_total;' + - globals.set: + id: totalWaterUsage + value: !lambda "return ( meter_value );" + +globals: + - id: totalWaterUsage + type: int + restore_value: true # aanpassen naar no indien de nieuwe waarde onder de oude ligt + initial_value: '0' # beginstand van je watermeter -> aanpassen via Home Assistant services ota: captive_portal: @@ -70,6 +76,13 @@ button: id: reboot - platform: factory_reset name: "_Restart with Factory Default Settings" + - platform: template + name: "_Reset - Total Water Counter" + id: button_reset_total + on_press: + - globals.set: + id: totalWaterUsage + value: "0" binary_sensor: - platform: gpio @@ -85,28 +98,34 @@ binary_sensor: - button.press: reboot sensor: - - platform: pulse_meter - name: "Watermeter pulse" + - platform: pulse_counter pin: number: 3 mode: input: true - pullup: true - id: h2o_pulse + pullup: true + id: watermeter_pulse + name: "Watermeter pulse" + count_mode: + rising_edge: DISABLE + falling_edge: INCREMENT state_class: measurement - unit_of_measurement: 'L' - device_class: water + update_interval: 1s internal_filter: 13us - internal_filter_mode: EDGE - icon: mdi:flash-outline accuracy_decimals: 0 - total: - name: "Watermeter total" - state_class: total_increasing - device_class: "water" - icon: mdi:water - unit_of_measurement: L - accuracy_decimals: 0 + unit_of_measurement: 'L/min' + + - platform: template + name: "Watermeter total" + state_class: "total_increasing" + device_class: "water" + icon: mdi:water + update_interval: 1s + unit_of_measurement: L + accuracy_decimals: 0 + lambda: |- + if (id(watermeter_pulse).state > 0) id(totalWaterUsage) += 1; + return id(totalWaterUsage); - platform: dsmr # energy_delivered_lux: