How does a total_increasing sensor behave when unavailable and float (0) is used?

        - name: fan_energy
          unit_of_measurement: "kWh"
          device_class: energy
          state_class: total_increasing
          state: "{{ (states('sensor.presa_1_tp_link_tp110_today_energy')|float(0) ) }}"
          availability: "{{ (states('sensor.presa_1_tp_link_tp110_today_energy')|is_number ) }}"

I cannot recreate the scenario, but what happens if the sensor becomes unavailable in this case?
Would the total energy go back to zero or a 0 value would be added to the “increasing total”?
Which is the best practice?

Thank you!

If your source sensor becomes unavailable the template sensor state will become unavailable too. Caused by your availability template.

This is good.

The energy dashboard treats total_increasing sensor changes like this:

Value → unavailable-> value : nothing happens. :+1:
Value → 0 → value : add the entire value to the energy total :-1:

1 Like

Ok. So the availability template overrides the float (0) function because if, for some reason, the sensor becomes unavailable then the float doesn’t revert to its default value, in my case 0.
It would have be the same if I have written float without the (0) part.

Am I correct?

If the availability template renders as false the state template is not evaluated and the state is set to unknown.