Change value of sensor

Hi all,

How do I change the value of a sensor (sensor.smokesensor001_smoke)? I use value_template but all I get is ‘unknown’, or blanks. I have tried every combination known to me (noob). Can you push me in the right direction?

This is the code:

- platform: template
  sensors:
    smokesensor001_alarmcustom001:
      friendly_name: Alarmstatus001
      value_template: >-
        {% if sensor.smokesensor001_smoke == 254 %}
          IT WORKS
        {% endif %}

Thanks

Try

if states.sensor.smokesensor001_smoke.state == 254

Thanks!
This did the trick:

{% if states.sensor.smokesensor001_smoke.state == '254' %}

Can somebody explain why this works?

{% if states.xxx.xxx.state == 'xxx' %}

Thanks

Hello @jellelle,

I believe it works because states.xxx.xxx.state’s output is actually a string not an integer. So if you just want to use 254 as written above instead of '254', then you should use the int filter by this

{% if states.sensor.smokesensor001_smoke.state | int == 254 %}

This is also quite important if you want to compare values using logic like >= or <=

Hope this helps.

regards