Skip to content

Commit

Permalink
changing the pulse_meter to pulse_counter + some logic to restore the…
Browse files Browse the repository at this point in the history
… total value
  • Loading branch information
mhendriks committed Mar 9, 2024
1 parent 2cfa18c commit 8d8e6bf
Showing 1 changed file with 40 additions and 21 deletions.
61 changes: 40 additions & 21 deletions p1-dongle-pro-h2o-v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 8d8e6bf

Please sign in to comment.