Rounding down power consumption

Hehey
I got a dashboard showing some device’s state and theri power consumption (in a gauge).
I got a design problem with my Thirdreallity plugs.
If the device is off, I see a power consumption of 0.4 to 0.7W (I suppose its the comsumption of the plug itself). I want it to be 0 if the device is powered off.
So I created a template helper with following code:

{% if states('sensor.steckdose_seerosen_leistung') | float > 0 %}
  0
{% else %}
  {{ states('sensor.steckdose_seerosen_leistung') }}
{% endif %}

This works, but is there any easier way to do this?

Does it though?

The way you have it the plug will always report 0 for any value greater than 0.

You want something like this:

{% if states('sensor.steckdose_seerosen_leistung') | float < 1 %}
  0
{% else %}
  {{ states('sensor.steckdose_seerosen_leistung') }}
{% endif %}

You should also use an availability template, as you are not supplying a default value for your float filter.

state: >
  {% if states('sensor.steckdose_seerosen_leistung') | float < 1 %}
    0
  {% else %}
    {{ states('sensor.steckdose_seerosen_leistung') }}
  {% endif %}
availability: "{{ has_value('sensor.steckdose_seerosen_leistung') }}"

hmm. Ofcourse you are right.
I only tested with a device turned off and watched if the 0.4W consumption is gone, but didnt turn the device on :o)

But giving my float a default should do, shouldnt it? So there is no need for an availability template:

{% if states('sensor.steckdose_seerosen_leistung') | float(0) < 1 %}
  0
{% else %}
  {{ states('sensor.steckdose_seerosen_leistung') }}
{% endif %}

If there is an error with the device its “leistung” is converted to 0, which is smaller 1 and 0 is displayed.

Sure, if you don’t care about the difference between unavailable and 0.

As long as you are not feeding this sensor to a Riemann sum integrator and then utility meter, then having 0 instead of unknown will not cause any issues.

Thank you!