If entity value is not numeric - set value to 0

Hi everyone,

i do have a gauge, which displays my (numeric) state of a solar panel in W(att).
When, at night time, the panel is beeing completely shut off, i get an “entity is not numeric” error at the gauges position.
How can i achive a numeric 0 when state is really “undefined” or not numeric?
I imagine i have to use a template, right?

Thanks a lot.

As for the meter in W and the solar panel is in the dark, will the meter display a numerical value of 0 W, or am I wrong?

Where does that gauge receive it’s number from? Meaning on which sensor is the gauge based?
And, to which integration does the sensor belong too?

The information you are providing is too little to be able to help you.


If your original sensor isn’t created by an intregration that you can control then you can cast the state of the original sensor to a float which will return a zero for any non-numeric values.

something like:

value_template: "{{ states('sensor.your_sensor') | float }}"

it should return the value of your original sensor unless it’s non-numeric then return a value of 0.0 .

if you don’t need a float then you can do the same using int.

Sorry for not delivering all necessary information.
The sensor is coming from the SMA integration and is giving me an numeric value during daytime by reading the corresponding key off of the inverter. it’s not based on a template or something.

During nighttime the solar inverter is completely shutting down, and I get a non numeric state instead of 0.

I hoped for a solution without setting up an additional template sensor, but will try.

If you don’t have any control of the upstream sensor data then the only option will be a template.

The best way to get this is fixed is by creating an Issue here: Issues · home-assistant/core · GitHub
Make the SMA codeowner aware of this problem.

Maybe this is already fixed on the latest pysma-library: I see that v0.3.5 is used at present in HA Core, on Pypi the latest version is v0.4.3.

This worked, thank you very much. :slight_smile:

1 Like

Hey, I have the same problem… but dont know what to do. Could You show me the exact steps ot the code i have to enter in config.ymal