Is there a way to have a non-numeric “custom value” when a sensor is unavailable?
I’ve got a template which computes how many days of propane are remaining on my fireplace LPG tank. Works great as long as the change is nonzero, but when its warm and the fireplace is shut off I have the problem of it divides “remaining / rate” and if the rate is zero that isn’t possible.
I can catch it, but then what do I tell the user? If I put up something that makes sense like “Off” then I get errors about non-numeric value. But also “unavailable” suggests its broken, which is also not accurate.
I can’t use “0” because that would trigger the “its empty” automation and also just isn’t logical. I could pick a very big number like 365 or 999 but it would be far more user-friendly if the dashboard could convey “this can’t presently be computed as numeric, but the sensor is functioning properly”.
I want to keep the type numeric so it can be graphed (when its got a numerical value…I don’t care about graphing when its off)
# Sensor for est days remaining
- name: "Fireplace Propane Fuel Est Days Remaining"
unit_of_measurement: "days"
icon: "mdi:clock-outline"
state_class: "measurement"
state: >
{% set remain = states("sensor.fireplace_propane_fuel_remaining") | float(0) %}
{% set rate = states("sensor.fireplace_propane_fuel_consumption_daily") | float(0) %}
{% if rate <= 0 %}
Off/Invalid
{% else %}
{{ (remain / rate) | int(0) }}
{% endif %}