Utility water sensor

hi all, i am tring to set up a sensor that give me the Liters that my water pump is using so i can add it to the energy dashboard.
I know that when my pump is working it pumps 5 l/s in my house. i have created this template for using it with a utility helper. I have no errors in the log but the sensor dows not diaplay in ha. Any ideas?

template:
  - sensor:
    - name: "litri_consumati"
      state: >-
         {{ state_attr('sensor.meross_smart_plug_1_power') | float) * 5 | round(2) }}       
      unit_of_measurement: L
      device_class: water
      state_class: measurement

You have an extra close parenthesis after float.

While you are there be sure to add (0) after that float instead of the close parenthesis so if it errors it returns a default of zero rather than crashing out without a return :slight_smile:

Also you are rounding the number 5. You need some parentheses around the whole thing.

Filters get applied first in the order of operations.

      state: >-
         {{ ( state_attr('sensor.meross_smart_plug_1_power')|float(0) * 5 )|round(2) }}

now i can see the sensor in ha but the state in unavailable.
i correct the code with yours, nao is this:

  - sensor:
    - name: "litri_consumati" 
      unit_of_measurement: "L"
      device_class: water
      state_class: total_increasing
      state: >-
         {{ ( state_attr('sensor.meross_smart_plug_1_power')|float(0) * 5 )|round(2) }}  

You did not specify an attribute. Iā€™m guessing you actually want this:

      state: >
         {{ ( states('sensor.meross_smart_plug_1_power')|float(0) * 5 )|round(2) }}
1 Like

now it works, but i have made a big mistake, i need the sensor to calculate the L for second as an incremente when the power sensor is not 0.