Sensor template not working properly (typo?)

Hi,

This is my sensor template:

- platform: template
  sensors:
    tronco_water:
      friendly_name: 'Water'
      value_template: >
         {% if (states.sensor.tronco_moisture | int < 18) %} Needs water
         {% else %} (states.sensor.tronco_moisture | int) Good
         {% endif %}

Value for sensor.tronco_moisture is above 18, but I still see “Needs water” on the card.
Any ideas?

Thanks!

Try states.sensor.tronco_moisture.state

1 Like

Thanks. Works like a charm!

Not working for me. Whatever I do it shows “needs water” which was actually my first state because I made it to say that in template if <60 (because atm it is on 52%). But when I changed the code to normal <20 it is still the same…

  - platform: template
    sensors:
      ficus_benjamina_moisture:
        friendly_name: 'Moisture'
        value_template: >
           {% if (states.sensor.ficus_benjamina_moisture.state | int < 20) %} Needs water
           {% else %} (states.sensor.ficus_benjamina_moisture.state | int) All ok
           {% endif %}
      ficus_benjamina_conductivity:
        friendly_name: 'Conductivity'
        value_template: >
           {% if (states.sensor.ficus_benjamina_conductivity.state | int < 350) %} Needs poop
           {% else %} (states.sensor.ficus_benjamina_conductivity.state | int) All ok
           {% endif %}

And I also need help in adding one more if - I tried in all forms and not successful. For example water - I would like to say if <20 “needs water”, if >60 “too much water” and if in between then “all ok”…