Sensor,write last number insted of 0

Greetings,
i have this config
pokoj_kancelar:
value_template: “{{ state_attr(‘climate.sistema_2_kancelar’, ‘current_temperature’) | round(1) }}”
unit_of_measurement: ‘°C’

with this graph:
Screenshot_171

Because of some timeouts there are 0 values in the graph.
Can i make value template so it will ignore thoose 0 values?

Thank you

1 Like

Yes use ‘if’

1 Like

like if 0 then use last?

Okay i found if else statements, but how can i set last value into the if statement

I think the current state of the template sensor will be what you want.

1 Like

will try thx

Isn’t availability template a good way to do it? Template - Home Assistant

Of course you could try to eliminate the 0 entries by fixing the sensor?

not possible, out of my reach,custom component dont want to get in to it

The sensor is available, the problem is that its loosing wifi signal and server givving 0’s.
So its fine if i fix template value, it will work thx

Seems to be working,Thank you :slight_smile:
pokoj_kancelar:
value_template: >
{% if value == “0” %}
{{ states.sensor.pokoj_kancelar.state }}
{% else %}
{{state_attr(‘climate.sistema_2_kancelar’, ‘current_temperature’) | round(1)}}
{% endif %}
unit_of_measurement: ‘°C’

Okay, so guyz, my value_template not working:
Why?Same as picture above, going to 0

      pokoj_kancelar:
        value_template: >
          {% if value == 0 %}
            {{ states.sensor.pokoj_kancelar.state }} 
          {% else %} 
            {{state_attr('climate.sistema_2_kancelar', 'current_temperature') | round(1)}}
          {% endif %}
        unit_of_measurement: '°C' 

your logic is backwards.

{% set temp = state_attr('climate.sistema_2_kancelar', 'current_temperature') | round(1) %}
{% if temp %}
  {{ temp }}
{% else %}
  {{ states('sensor.pokoj_kancelar') }}
{% endif %}

In the future, please take the time to properly format code. Your code is unformatted and does not copy/paste well. This makes it harder for people to help you.

Got it sorry, actualy its working i forgot to remove quotes. The logics seems fine. Maybe i explained it wrong :>

No, your logic is wrong. Value is not defined so you’ll always go to the else statement.


Idk buts fine as you see. Maybe you are right and the problem will apear then i will check.
I understand that its not set,for now i will not mark as solved

Thank you for pointer! <3

It’s dumb luck. value is not in the namespace. It’s something you made up that doesn’t exist and you’re checking something that doesn’t exist to zero. You need to check what’s changing your template (The temperature) and action off that pulling the last information or new information. I’ve done this many many times. You’re welcome to ignore this advice but just know, it’s not correct.

1 Like

Yes you are right. will do that. <3

also, the if temp in the template is checking it against zero. So no need to add ==0.