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.
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.
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…