I was stuck, I do not find the solution, I have a water flow meter, my need is to measure how long the pump stays on to calculate how much water has entered the cistern, I created two sensors one is history_stats called “utilizzo_pompa” that should give the ignition time and this does not happen.
- platform: history_stats
name: utilizzo_pompa
entity_id: sensor.flusso
state: 'pump on'
type: time
start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) | float * 60 }}'
end: '{{ now() }}'
and one that measures the calculated time previously “utilizzo_pompa” multiplied by 5.0 (liters per minute) which is the average of the water flow of which they are already aware of it.
- platform: template
sensors:
pompa:
friendly_name: litri
icon_template: mdi:water-percent
value_template: "{{ states('sensor.utilizzo_pompa') | float * 5.0 }}"
unit_of_measurement: 'Lt'
but given my limited knowledge does not work, but the problem is in the first sensor that should start counting the time elapsed when the sensor is greater than zero (ie 5.0 when the water passes) until it returns to zero when the pump is stop, what do you think?