Hello everyone. I have a strange problem. I am sensing an 18b20 connected to a nodemcu that I had to make a correction of 1 degree so that it is like another one that I have. In the graph that measures the sensor without the template it works well. The graph showing the modified sensor shows values of 1 degree. I did this the same but with a sonoff th and it works fine. Someone sees something wrong. If you look at the two graphs you will see that the original shows the data well but the one that is modified shows it badly. Thank you so much
sensor:
- platform: template
sensors:
temperatura_sump:
unit_of_measurement: °C
friendly_name: temperatura_sump
value_template: "{{'%0.2F' | format(states('sensor.temperatura_sump_sin_template') | float(0) + 1) | round(1)}}"
Without template
With temolare
What if using just this:
value_template: "{{ (states('sensor.temperatura_sump_sin_template') | float(0) + 1) | round(1) }}
Still the same. It’s weird because it works fine before the template
Then the float(0)
could be the reason - i.e. sometimes the source sensor gives non-numerical values…
Check the source sensor’s graph on a small time period to see possible gaps.
if gaps are there - then in the template sensor you may do smth like this:
if states(source sensor) in ['unavailable','unknown']
states(this sensor) - i.e. use previous value
else
states(source sensor)
I have no cuts. I have drops to 1 degree every few minutes. Would that be fine?
value_template: >
{% if states('sensor.temperatura_sump_sin_template') != 1 -%}
{{ (states('sensor.temperatura_sump_sin_template') | float(0) + 1) | round(1) }}
{%- endif %}
Strange , it is not shown in the 1st picture.
What I see is that the 2nd graph (is it for template sensor?) have drops to “1”.
Are you sure that you got my point?
You’re right. The original is fine. The corrected sensor notices drops to 1 degree and cuts
This is how the sensor is with template
if states(source sensor) in ['unavailable','unknown']
states(this sensor) - i.e. use previous value
else
states(source sensor)
So this is what I don’t know where I should go?
Could be like this?
value_template: >
{% if states('sensor.temperatura_sump_sin_template') != 1 && states('sensor.temperatura_sump_sin_template') not in ['unavailable','unknown'] -%}
{{ (states('sensor.temperatura_sump_sin_template') | float(0) + 1) | round(1) }}
{%- else %}
{{ states('sensor.temperatura_sump') }}
{%- endif %}
I look at the original sensor in a short time and it works perfect. The problem is when I add 1.0 to the value it has- I’m confused
Show the original sensor from 20:10 to 20:30.
You are not just adding a “1” - you are trying to convert the state to “float” first:
float(0)
The default value is “0” - it is used when the state cannot be converted to float, i.e. for non-numerical.
That is what I suspected.
Try this:
value_template: >-
{% if states('sensor.temperatura_sump_sin_template') not in ['unavailable','unknown'] -%}
{{ (states('sensor.temperatura_sump_sin_template') | float(0) + 1) | round(1) }}
{%- else -%}
{{ states('sensor.temperatura_sump') }}
{%- endif %}
1 Like
It worked mate. Thank you very much for the help. I needed to try for a while but throughout the night I filter the cuts very well… thank you!!!
1 Like