Issues with creating and updating a binary sensor

Hi all - I think I am making a stupid mistake, but I can’t get my head around it. I have a Zigbee temperature sensor with entity name: sensor.temp005_temperature. It provides regular temperate updates in degrees Celcius with two decimals. I can see the historic temperature which confirms that HA is getting regular updates (once every 1-3 minutes). Temperature is always (slightly) different, which is what I am expecting. No issues here.

In my Configuration.yaml, I have added the following code to create two binary sensors. One to be ‘true / on’ if temperature is rising, and one to be true / on in case temperature is declining.

binary_sensor:
- platform: template
sensors:

[various other sensors]

  temperature_increase_temp005:
    friendly_name: "Temperature Increase Temp005"
    value_template: "{{ states('sensor.temp005_temperature') | float > states('sensor.temp005_temperature') | float(1) }}"

  temperature_decrease_temp005:
    friendly_name: "Temperature Decrease Temp005"
    value_template: "{{ states('sensor.temp005_temperature') | float < states('sensor.temp005_temperature') | float(1) }}"

After reloading the YAMLs, the sensors appear as an entity. However, both remain ‘off’ and are not updating. Any hints on what I am doing wrong?

Thanks a lot for your help!

You are comparing the same states, that won’t work…they will always be identical.
I think you should store the value in f.e. a helper, when the value changes and check that helper versus the actual sensor value, to see if it increased or decreased :thinking:

If you really want/need something to compare each state change to the last, you could do it with a trigger-based Template sensor, but I would go for the one of the built-in statistics integrations above.

1 Like

Thank you both for your quick and helpful responses. It seems that the ‘Trend’ integration is exactly what I need!
Thanks!

Eager to set up the Trend ‘helper’, another stupid question. I am running the latest home assistant version, yet I can’t get this helper/ integration to be installed.

I tried both options shown in the reference documentation:

  1. Click on the button ‘add integration to my HA’, and
  2. followed the manual steps to select Trend from the list of Helpers.

Both do not work:

  1. gives an error that it cannot find the helper and that I should use the latest version of HA (I am using 2023.12.4 for Core and 11.2 for Operating System)
  2. when manually installing, I cannot find the Trend helper in the list shown.

I can confirm doing it through the Integrations page and Helpers page both work in 2024.1 after clearing the browser cache.

You can also still configure them manually in YAML.

Thanks. It works!