Energy dashboard Water tank wrong consumption on utility meter (on rain refill)

I’m struggling with this correct watter tank consumption for quite a time.
Firstly I had problem that there was no sensor for water:
https://community.home-assistant.io/t/water-sensor-template-water-tank-for-energy-dashboard/486456/12
Then there was problem that consumption was not detected corretly because sometimes water tank sensor is flipping between two measured values, and HA detected this as consumption.
This was resolved by the new template sensor which read data based on trigger (in my case when water pump is activated).
https://community.home-assistant.io/t/fixed-sensor-based-on-real-sensor-for-energy-dashboard-use/490149/7

Now here is probably my last problem which is that on refilling water tank HA detect this also as consumption.


(sensor - created by template)


(sensor - utility meter)

So the question is, did anybody succed to resolve this, probably with some kind of template sensor which is utility meter, which is used as base for consumption.

At the end why there is no utility meter which predics that source is water tank which can be refilled?

Thank you anybody for helping me…

This just came in …seems similar
I still don’t understand how to use the trend sensor for humidity - Community Guides - Home Assistant Community (home-assistant.io)

Similar but completly different… don’t know how to help with that…

I know exact values… but utility meter need to set new value as base from which count consumption when water tank refill…

example…

  • now is 2000L in tank…
  • consumption made 100L - this must be set as energy water consumption
  • now is 1900l in tank.
  • now is rain (+ 200L) and in tank is 2100L
  • new base from which consumption is made must be set to 2100L…

etc… but currently is is that refill (+ 200L in example) is detected also as energy consumption which is wrong in my case…

UM takes all values as consumption. e.g. solar panels: when sun power rises or decreases…it still produces.
So you probably need a sensor in-between to indicate it the level is falling and only then use UM
Take a look at Trend and what Finity wrote in that piece
I have nothing here that does the same so cannot help other than with view/idea :slight_smile:
Other option (but that seems not needed) is to install a water flow meter.

Other idea…
create a helper / input_number
create a automation that triggers on the level of takn (assume this is a ‘state’)
update the input_number only when trigger.from_state > trigger.to_state, you could update the input number with the difference between these two states (there are examples on the forum)
The input_number can then serve for your utility meter sensor

great idea… I will dig into this…

check this one
New Filters: Increasing & Decreasing (including concrete examples) - Feature Requests - Home Assistant Community (home-assistant.io)

So, I crack this problem.

Solution was / is:

1: TEMPLATE SENSOR: which is actually using water level from actual tank, but filtered and no UP/DOWN value in case of middle of measurement.
slika

template:
  - trigger:
      platform: numeric_state
      entity_id: sensor.pp_tw
      above: 10
      for:
        hours: 0
        minutes: 0
        seconds: 10
    sensor:
      name: "Vodostanje (trenutni nivo vode)"
      unit_of_measurement: "L"
      state: "{{ states('sensor.trenutni_nivo_vode') | float(0)}}"

2: Input number, which is used as consumption value.
slika

input_number:
    vodostanje_poraba_vode:
      name: Vodostanje (poraba vode)
      min: 0
      max: 3680
      step: 1
      unit_of_measurement: "L"

3: SENSOR for enery dashboard use

  - platform: template
    sensors:
      vodostanje_povratna_voda:
        unit_of_measurement: "m³"
        device_class: water
        friendly_name: "Vodostanje (povratna voda)"
        value_template: '{{ states("input_number.vodostanje_poraba_vode") | float(0) * 0.001 }}'

4: Fix for total increase for energy sensor.

customize:
sensor.vodostanje_povratna_voda:
  state_class: total_increasing

5: AUTOMATION

A: Event on water pump (which is used for using water from water tank) activated…

- id: '704'
  alias: 'Izračun porabe vode - vodostanje'
  trigger:
  - platform: numeric_state
    entity_id: sensor.pp_tw
    above: 10
    for:
      hours: 0
      minutes: 0
      seconds: 5
  condition:
  - condition: state
    entity_id: switch.povratna_pumpa
    state: 'on'
  - condition: template
    value_template: >-
      {{ (states('sensor.trenutni_nivo_vode')) | float(0) < (states('sensor.vodostanje_trenutni_nivo_vode')) | float(0) }}
  - condition: template
    value_template: >-
      {% if states('sensor.trenutni_nivo_vode') == 'unknown' %}
        False
      {% else %}
        True
      {% endif %}
  action:
  -  service: input_number.set_value
     data_template:
       entity_id: input_number.vodostanje_poraba_vode
       value: >-
         {% if (states('sensor.vodostanje_trenutni_nivo_vode')) | float(0) <= (states('sensor.trenutni_nivo_vode')) | float(0) %}
           {{ 0 }}
         {% else %}
           {{ (states('sensor.vodostanje_trenutni_nivo_vode')) | float(0) - (states('sensor.trenutni_nivo_vode')) | float(0) }}
         {% endif %}
  mode: single

B: Simply check every 5 minutes and change input_number back to 0.

- id: '705'
  alias: 'Izračun porabe vode - vodostanje (časovnik)'
  trigger:
      platform: time_pattern
      minutes: "/5"
  condition:
  - condition: state
    entity_id: switch.povratna_pumpa
    state: 'on'
  - condition: template
    value_template: >-
      {% if states('sensor.trenutni_nivo_vode') == 'unknown' %}
        False
      {% else %}
        True
      {% endif %}
  - condition: template
    value_template: >-
      {{ (states('sensor.trenutni_nivo_vode')) | float(0) <= (states('sensor.vodostanje_trenutni_nivo_vode')) | float(0) }}
  action:
  -  service: input_number.set_value
     data_template:
       entity_id: input_number.vodostanje_poraba_vode
       value: >-
         {% if (states('sensor.vodostanje_trenutni_nivo_vode')) | float(0) >= (states('sensor.trenutni_nivo_vode')) | float(0) %}
           {{ 0 }}
         {% else %}
           {{ (states('sensor.vodostanje_trenutni_nivo_vode')) | float(0) - (states('sensor.trenutni_nivo_vode')) | float(0) }}
         {% endif %}
  mode: single

That it’s… All code published if somebody would need to use for own water tank consuption.
In case of any improvement please publish changed code. Thank you…

And this is how it looks with public water consumption…

And in case of rain no consumption detected. I have luck because it was raining :wink: So really only consumption detected…

Why not directly in 3.? this is how I did it

Because I create sensor as “L” - liter and I want to convert it to m3…

But directly would probably also work… never tried…

Mine is this, input is in M3

      - name: "Water Usage"
        unique_id: Water_Main
        unit_of_measurement: "m³"
        device_class: water
        state_class: total_increasing
        state: "{{ states('input_number.watermeter') |float(0) }}"

Same as point 3… so you control not using water level going UP as consumption in case of rain with automation as my example?

I donot have up/down…I manually type it in … yeah…applause for automation… but my meter is too far away and has no electricity next to it and although I’d rather be lazy than tired… I also donot need daily figures