Introduce constant for missing values

I have around 250 automations, about 50 template sensors, and 10 MQTT sensors. It often happens that sensor values are incorrect, e.g. because invalid or uninterpretable values were sent via MQTT or Zigbee. However, it seems to me that there is no representation for this in HA. There are “None”, “unavailable” and “unknown”, but these seem to be strings. In SQL, numpy and also in pandas, a value can be “missing”. And you can continue to calculate with missings without an error. numpy.nan * 3 is numpy.nan again, pandas.NA*3 is pandas.NA again. It would therefore be important if there were a consistent constant for missing values in HA and in the jinja templates, such as pandas.NA.

All states are strings.
Explain what the issue is. You say it’s calculations in jinja? So why not check for unknown/unavaliable first?

Hello Martin,

There is default in jinja, where you can set a fallback to be any thing you want it to be.

And what is the correct value to fill in if a value is missing? Who of you is working with databases and knows the concept of a constant representing a missing value?

The constant of missing value is a string “unknown”.
Your feature request will not change this in any way, there will be way to many breaking changes for everyone else.

You can always calculate with missing values.
So it should be possible to do 3 + unknown + 5 without getting an error.

And that is what Sir above posted.
Use the default

When you filter your result thru a default it will intercept the unknown and unavailable and insert the value you pick, 0 for instance.

In any case you are arguing jinja code here, so you might want to take up the argument with them.