I´m using a rest interface to read out some temperatures, but I have now got this warning
Sensor sensor.eta_utetemp has device class temperature, state class None and unit °C thus indicating it has a numeric value; however, it has the non-numeric value: −1,6 (<class ‘str’>)
Sensor sensor.eta_utetemp has device class temperature, state class None and unit °C thus indicating it has a numeric value; however, it has the non-numeric value: −0.4 (<class ‘str’>);
But now with . instead of ,
name: eta_utetemp
device_class: temperature
unit_of_measurement: "°C"
value_template: '{{ value_json["eta"]["value"]["@strValue"].replace(",",".") }}'
Is that an en-dash rather than a minus sign?! Who designed that sensor?!
value_template: '{{ value_json["eta"]["value"]["@strValue"].replace(",",".").replace("–","-") }}'
# copy this character from the error message------------------------------------------^
I assume from your ["@strValue"] that this is coming from XML, and that “strValue” suggests it’s a “human-readable” output. Is there another value attribute that would be better to read?
Yeah, so I can click posts and “edit” them. Which shows the raw un-forum-tainted text. Then I just cancel the edit. Making it code, like in my post above, leaves the characters unaltered. So your template with the character change in my post should work.
Agree, in 95% of my templates sensors there is an “availability” attribute to handle “bad” input data; so these sensors are either with some “good” data or “unavailable”.
But there are template sensors for which:
“availability” = true;
state = either processed “good” data or PREVIOUS data if input data are “bad”; this behavior is needed since I want to memorize last “good” data.
And because of unclear reasons these sensors are “unknown” on HA startup.
if states(some-source-sensor) in [‘unavailable’,’unknown’]
If states(this-sensor) != ‘unknown’
states(this-sensor)
else
?? some-default-value ??
else
states(some-source-sensor)
?
And defining that “default value” is not an easy task too. Ideally it must be the last “good” value.
Not clear((. Assume some source sensor is NOT unavailable or unknown - then it anyway may be not populated?
When you restart, HA does not restore pre-restart states. So the state objects in memory are empty. HA has been like this for years. There’s a few things that can restore states. Some template sensors can restore states, but I believe that’s trigger only template sensors. So you have to account for a restart. I’m not sure why you don’t just make it unavailable as that’s the most appropriate for the situation. When the other sensor that it feeds from comes back to life, your sensor will no longer be unavailable.
Probably there is a language barrier between us which prevents understanding.
Let me explain then.
As I said this is what I do for 95% of my sensors:
– source sensor is ok - then use it’s data;
– otherwise (device is offline, sensor became unavailable, data are invalid - like negative battery_level etc) availability=false.
But imagine a special case: if source data are bad, the PREVIOUS good data are used.
Agree that in general this could be a bad approach: you are using OLD data, which may be not valid now.
But in some cases the source device is not sending changed data very often (i.e. these data do not change very often), or these changes are not critical.
Imagine a vacuum robot, an air purifier which send data about their filters: in both cases filters are degrading slowly; in case of vacuum - it degrades only after cleaning.
In similar cases it is rather OK to use previous data when currently data are absent (assume that you switched off the vacuum - but still interested to see data about filters; and same about jet printer etc).
So, for these cases algorithm is like this:
– source sensor is ok - then use it’s data;
– otherwise - use previous data (i.e. the current sensor’s state);
– availability=true (always).
It works fine and allows to see the last “good” data if currently data are not available.
The only problem occurs on HA startup - these sensors become “unknown”.
This was not a problem; but since 2023.2 these events are reported in the Log; surely I may filter them in “logger”, but I want to make algorithms better.
You wrote - “ When you restart, HA does not restore pre-restart states. So the state objects in memory are empty. ”
So these “previous data” are supposed to be not available on startup, yes?
But after HA startup I still see data about filters in a vacuum robot from yesterday:
– yesterday the sensor got this data about filters;
– today HA was restarted;
– on HA startup the sensor became “unknown”;
– then the sensor got the yesterday’s data about sensor since the vacuum is OFF.
And here I do not understand a reason of this “unknown” state.