Water meter on batteries

Hi there

I’m planning to build a water meter based on Peter Brinkman’s design (Build a cheap water usage sensor using ESPhome and a proximity sensor - PieterBrinkman.com) but I want to run it on batteries since my water counter is isolated and there is no way to fit a charger or connect to mains.

I’ve setup one esp8266 with his code but, connected to a 20000mAh battery, barely keeps alive 5 days… I’ve been reading bout deep sleep elements but I don’t really where to begin with Peter’s code to introduce deep sleep nor it will work for this específic piece of work.

Any one has same situation or knows any trick?

Thanks

I don’t have a technical answer to your question, but given the WiFi power draw I don’t think a decent battery life will be achievable; there are plenty on posts on the subject.

I would think the way forward would be a BLE or ZigBee solution. The ESP32 already supports BLE, I guess it would just need WiFi disabling. There are plans to release a ZigBee ESP too. Although range and interference may be an issue.

Obviously then there’s some coding involved to send the data.

Commenting too to keep tabs on the thread :slightly_smiling_face:

1 Like

I think there’s some nice Zigbee reed switch hacks for that kind of thing?

Other idea is maybe you can wake it up on pulse count? Then go back to sleep?

I think you need an esp32 for that though.

wakeup_pin

Thank you all for quick responses!

I really love the idea behind this @Mahko_Mahko : Gas meter from Xiaomi/Aqara door sensor (ZigBee)

I did try already with one spare aqara door sensor and didn’t get it to work without any further wiring (I think my water meter magnetic field is not strong enough). I already order some reed from aliexpress to try “the external version”.

I also order a ESP32 to try the deep sleep + BLE concept from Aliexpress… 10 days… I’ll keep you posted!

2 Likes

I checked the location of my meter, and it’s on the sidewalk down a 60cm hole. I could maybe envisage getting a battery operated radio thing there, but I can’t see how I would ever be able to install a sensor all that way down.

The only feasible option I can see now, for my user case, is to have a second meter installed in the home, negating the need to have a battery powered sensor.

I had a second meter installed in my home just for this. I originally tied it in to a door sensor so it was still battery powered. The meter I got had around 70 pulses per gallon and I was watering the lawn. Basically the battery only lasted 3 days when trying to transmit every pulse. I ended up having to run a wire to the meter and hook it to an ESP32 that was plugged in.

1 Like

Someone just needs to knock-up a self-powered solution that harvests/generates energy from the meter turning;) Basically contactless hydro-power;)

Hi, I finally received my ESP32 unit and I’m making progress with deep sleep state. I’ve been trying combinations of configuration and so far I always have the same problem: when unit is going deep sleep, all “counter” and “meter” states go 0 again. Any clue?


deep_sleep:
  wakeup_pin_mode: KEEP_AWAKE 
  run_duration: 60s
  sleep_duration: 360min
  esp32_ext1_wakeup:
    pins: GPIO34
    mode: ANY_HIGH 

sensor:
- platform: pulse_counter
  pin: GPIO34
  name: "water pulse"
  id: water_pulse

- platform: pulse_meter
  pin: GPIO34
  name: "Water Pulse Meter"
  unit_of_measurement: "liter/min"
  icon: "mdi:water"
  total:
    name: "Water Total"
    unit_of_measurement: "liter"

- platform: pulse_meter
  pin: GPIO34
  name: "Water Pulse Meter"
  unit_of_measurement: "liter/min"
  icon: "mdi:water"
  total:
    name: "Water Meter Total"
    unit_of_measurement: "m³"
    id: water_meter_total
    accuracy_decimals: 3
    device_class: water
    state_class: total_increasing
    filters:
      - multiply: 0.001

- platform: template
  name: "Water Usage Liter"
  id: water_flow_rate
  accuracy_decimals: 1
  unit_of_measurement: "l/min"
  icon: "mdi:water"
  lambda: return (id(water_pulse).state * 10);

I have a hunch, this could be the same issue I’ve been fighting as well: two sensors with same input not work with latest firmware · Issue #3364 · esphome/issues · GitHub

So basically once you use GPIO34 for wake up, it won’t be available for the pulse_counter anymore.
AFAIK the code you’re using doesn’t work in the recent ESPhome (> 2022.5.0) precisely for the same issue.

Hmm maybe they don’t persist across deep sleep?

I think globals do. So you might need to build a DIY counter using globals.

You might be about to reuse parts of this which does a delta sensor across deep sleep cycles.

globals:
  - id: previous_value
    type: float
    restore_value: yes
    initial_value: '0.0'

sensor:
#Track end of day battery (manually updates at the end of the day before sleeping for the night) 
  - platform: template
    name:  End of Day Battery ${friendly_name}
    id: end_of_day_battery_percent
    update_interval: never
    icon: "mdi:solar-power"
    unit_of_measurement: '%'
    on_value:
      then:
        - lambda: id(change_in_end_of_day_battery_percent).publish_state(x - id(previous_value));
        - lambda: |-
            id(previous_value) = x;
                
#Track daily changes in battery
  - platform: template
    # source_id: end_of_day_battery_percent
    id: change_in_end_of_day_battery_percent
    icon: mdi:trending-up
    internal: false
    name: Change in End of Day Battery ${friendly_name} 
    unit_of_measurement: '%'
    accuracy_decimals: 1

Or maybe just send the pulse to HA to do the counting?

But it really counts during sleep/wake times; if only totals and states were “stored” would be fine

I do have a water meter set-up as well, using an ESP32.
In my case it is powered by wire, so I don’t need the Deep Sleep function.
However, to have a preserved water meter counter value, I am using a global variable and some on_boot and on_shutdown actions.
Here it is stated about on_shutdown that:

on_shutdown
This automation will be triggered when the ESP is about to shut down. Shutting down is usually caused by too many WiFi/MQTT connection attempts, Over-The-Air updates being applied or through the Deep Sleep Component.

So it looks like this could help as well with Deep Sleep enabled?
It is not mentioned that on_boot is also triggered by coming out of Deep Sleep, but it is worth a try.

This are some applicable excerpts from my code:

esp32:
  board: ttgo-t7-v13-mini32
  framework:
    type: arduino

esphome:
  name: t7v13-01
  on_boot:
    then:
      - pulse_counter.set_total_pulses:
          id: pulse_counter_water
          value: !lambda 'return id(global_water_total);'
  on_shutdown:
    then:
      - globals.set:
          id: global_water_total
          value: !lambda 'return id(water_total_liter).state;'

interval:
  - interval: 30s
    then:
      - globals.set:
          id: global_water_total
          value: !lambda 'return id(water_total_liter).state;'

preferences:
  flash_write_interval: 60s

# Global variables
globals:
  - id: global_water_total
    type: int
    restore_value: yes

sensor:
  # Water meter setup
  - platform: pulse_counter
    pin: GPIO16
    update_interval : 6s
    name: Water Rate
    id: pulse_counter_water
    use_pcnt: true
    unit_of_measurement: "l/min"
    icon: "mdi:water-outline"
    total:
      name: Water Total Liter
      id: water_total_liter
      device_class: water
      state_class: total_increasing
      accuracy_decimals: 0
      unit_of_measurement: "l"
      icon: "mdi:water-plus-outline"

To ensure that the value is preserved during a power failure I also have an interval option to write the value to flash every 30 seconds (globals.set).
To my understanding this does not wear-out the flash because writing to flash only really happens when the value is really changed.

1 Like

someone can say me the battery life?

https://expo.tuya.com/product/898043