In addition to this Im using an availability sensor:
{{ is_number(states('sensor.shellyplusht_kasse_temperature')) and is_number(states('sensor.shellyplusht_kasse_humidity')) }}
But I found out availability is wrong in my case, as this raises errors when total humidity sensor is not present. (e.g. at start when z2m takes longer then ha to startup),
so I want to move this template from config.yaml to my helpers and I want to have default values for the case one of the sensors is not reachable.
So I changed the formula to the following in my helpers:
Now the result is the same (tested in Developer Tools → Template) and if I change any of the sensors’ name to nonsense it seems like the correct default (set after float()) is used.
But im not 100% knowing what Im doing here, so can anyone please confirm that both formulas are the exact same, or did I do something wrond?
it returns 6.07
If I leave your formula as it is and change the convertion to int into convertion to float it returns 6.15 again.
So there shouldnt be the need for my second float, as you assumed.
But in this case im pretty sure float is the better datatype and it should look like this:
@tom_l
Your availability sensor obviously looks much more usefull than mine.
But if I understood its function correct then there is no absolut humidity sensor if the availability template returns false.
So if i move the sensor to helpers and give default values for missing sensor data I get (incorrect) data.
If I use availability there will be no absolut humidity sensor at all if availability is False.
And what happens after restarting, when z2m does not provide any sensor data?
I then get my float default values as there is no “last known good state”?
Hmm I think ill then prefer a wrong sensor value, due to float defaults.
In many (really many) mushroom condition cards I check if the value is >40 or <60.
Im too lazy changing all of them, as unknown > 40 surely raises an error.