(Special ?) sensor

I use a binary sensor to monitor how many time my water pump is power on during the day.
it’s works with

   - platform: history_stats
     name: forage ON today
     entity_id: binary_sensor.forage
     state: 'on'
     type: time
     start: '{{ now().replace(hour=0, minute=0, second=0) }}'
    end: '{{ now() }}'

but i would like also to know my water consumption ; how many liters i use, my pump goes out 0.5L/sec
so i would like to multiply my previous ‘binary_sensor.forage’ by 0.5;
i don’t finding,
any help please ?
thx

look up “template sensor” in the docs.

  1. Your spacing is a bit off on that history stats sensor.
   - platform: history_stats
     name: forage ON today
     entity_id: binary_sensor.forage
     state: 'on'
     type: time
     start: '{{ now().replace(hour=0, minute=0, second=0) }}'
     end: '{{ now() }}'

Now that it’s fixed, you can create a template sensor. Remember, the history stats sensor that is created will have hours as the default state. With that being said, you’d have to use the following calculation.

{% set hours = states('sensor.forage_on_today') | float %}
{{ hours / (60 * 60) * 0.5 }}

So, in order to make this a template sensor, you should add the following code below your history_stats sensor.

   - platform: template
     sensors:
       forage_litres_today:
         friendly_name: Forage Litres Today
         value_template: >
           {% set hours = states('sensor.forage_on_today') | float %}
           {{ hours / (60 * 60) * 0.5 }}
         unit_of_measurement: L

Hello,

thanks, it’s works, i learn lot of with this case;
I try to improve an little more the precision.
Often my water pump works only few seconds (5-10s) and
the binary sensor works perfectly (logbook) ; but the history_stats sensor, forage_ON_today (type: time) was update only when full minutes was reached (value seen in developer tools). i would like a value in seconds to be more real-time consumption. anyone knows if it’s possible ? thanks for your time

change the scan_interval to 10. It defaults to 30, which is 30 seconds.