Help create sensor template to ignore certain value

Hi guys,

I’ve tried creating sensor template to ignore certain value (1000 in this case) but failed.

Could you please help?

Sensor output is taken from modbus device.

Here’s my current config:

FB_IMG_1625815949137

Thank you kindly!

Please dont post pictures of text. Post the correctly formatted text. That way we can use copy/paste/edit to help you.

Sure, sorry, this was only thing I had on hand until now.

  sensor:
  - platform: template
    sensors:
      filtered_pm25cleanr:
          unit_of_measurement: μg/m3
          value_template: "{% if states('sensor.pm25cleanr') == 1000 %}      {% else %}        {{ states('sensor.pm25cleanr') }}        {% endif %}"
1 Like

This should do it.

  sensor:
  - platform: template
    sensors:
      filtered_pm25cleanr:
        unit_of_measurement: μg/m3
        value_template: >
          {% if states('sensor.pm25cleanr') == 1000 %}
            {{ states('sensor.filtered_pm25cleanr') }}
          {% else %}
            {{ states('sensor.pm25cleanr') }}
          {% endif %}

If the new value = 1000, keep that last value.

Thanks Tom, unfortunately this doesn’t do the job :frowning:

When 1000 appears, it does use this value.

Try:

{% if states('sensor.pm25cleanr')|int == 1000 %}

or:

{% if states('sensor.pm25cleanr') == '1000' %}

States are always strings, so you can either convert and compare to a number, or compare to a string that looks like the number.

1 Like

The |int did the job.

Thank you both!