Your code example works but I don’t understand the “the entity doesn’t exist” part. The entity does already exist because I have created with with {{ states('sensor.temp_livingroom_raw') }}
intially. After that I tried to change the template to the one in my first post.
Anyway, what I actually do want is this:
{% set newValue = states('sensor.temp_livingroom_raw') %}
{% set oldValue = this.state if this is not none and this.state is defined else newValue %}
{% if newValue in ('unavailable', 'unknown') %}
{{ oldValue }}
{% elif oldValue in ('unavailable', 'unknown') %}
{{ newValue }}
{% elif ((newValue | float) - (oldValue | float)) | abs >= 0.4 %}
{{ oldValue }}
{% else %}
{{ newValue }}
{% endif %}
It uses the new value of the sensor unless the new value differs from the previous value (which is this.state
) by more than 0.3. In this case it sticks with the previous value. However, this also leads to the same 'NoneType' object has no attribute 'lower'
error (which given the template code is highly confusing since no lower
is used anywhere).
Rationale behind this: I have a few temperature sensors which have a bug which lets their temperature jump by 0.4 degrees for about 30s and then it goes back to normal. I know about the built-in outlier
filter but that doesn’t do what I want which is simply ignoring these 0.4 degree jumps.