Power sensor has stuck high value when offline - how to make it zero when unavailable?

I’ve created a Power sensor (sensor.ups_used_watts) for a CyberPower UPS connected via USB to a PC that returns Watts and it seems to function correctly, but when the PC is shut down, it loses connection and the “Watts” value becomes stuck on it’s last value and never goes to zero.

My goal is to make it: Preferably return an estimated value of my choice like ‘10w’ while the sensor is unavailable - or if that’s not possible or too difficult, simply return a 0 value while the sensor is unavailable.

I thought a template might work, and I tried making something with the helper, but I’m new to Home Assistant and I can’t seem to figure out how to do it or if it’s even possible.
I do have a sensor called “sensor.ups_status” that goes onLine or Unknown if that’s helpful.

Hi robuck,

You need an availability key in your template. search this page for availability.

1 Like

Thanks! I think I have it figured out. It seems to work correctly and return a 0 value when the UPS is offline. Here’s what I ended up with for a Power template.


{% if states('sensor.ups_status') == 'unknown' %}
            0
          {% else %}
            {{ states('sensor.ups_used_watts') | float(0) }}
          {% endif %}