Skip to content

Instantly share code, notes, and snippets.

@thomasvt1
Created October 30, 2022 09:07
Show Gist options
  • Save thomasvt1/c358bd47fcb41b1f814c01c73b140a3e to your computer and use it in GitHub Desktop.
Save thomasvt1/c358bd47fcb41b1f814c01c73b140a3e to your computer and use it in GitHub Desktop.
esphome:
name: water-meter
esp8266:
board: d1_mini
restore_from_flash: true
# Enable logging
logger:
web_server:
port: 80
ota: false
# Enable Home Assistant API
api:
encryption:
key: "Iq9Ra08fClC04eo5pLMP+13+rkvFZ1K93D3YyOtehVA="
ota:
password: "d05d9fd7a1fc71d6e6f99398b47969a9"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Water-Meter Fallback Hotspot"
password: "xxxxx"
captive_portal:
binary_sensor:
- platform: gpio
id: internal_pulse_counter
name: Pulse sensor
internal: true
pin:
number: D2
inverted: true
mode:
input: true
pullup: true
on_press:
- then:
- number.increment: water_meter_pulses
- component.update: water_meter_total
number:
- platform: template
id: water_meter_pulses
name: Pulses
min_value: 0
max_value: 1000
step: 1
optimistic: true
restore_value: true
on_value_range:
above: 1000
then:
- number.increment: water_meter_reading
- number.to_min: water_meter_pulses
- component.update: water_meter_total
- platform: template
id: water_meter_reading
name: Reading
icon: mdi:water
unit_of_measurement: m3
min_value: 0
max_value: 99999
step: 1
optimistic: true
restore_value: true
sensor:
- platform: template
id: water_meter_total
name: Total
state_class: "total_increasing"
icon: mdi:water
unit_of_measurement: m3
accuracy_decimals: 3
lambda: return id(water_meter_reading).state + (id(water_meter_pulses).state * 0.001);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment