Template binary sensor on when it doesn't meet given condition

Hi there,

I have two temperature sensors.
I have a template binary sensor that goes on when one temperature is higher then the other temperature:

################################################
## Entities / Binary Sensors / Buiten warmer dan binnen
################################################
unique_id: 994533d9-fcde-411d-b786-cd0d8e87a36f
name: "Buiten warmer dan binnen"
state: >-
  {{ states('sensor.achtertuin_multisensor_temperature') > states('sensor.woonkamer_temperature') | default(False)}}

But sometimes the binary sensor flips on although it doesn’t meet its condition:

Can someone explain why? Is it because of typing?

Yes.

States are strings, so you need to cast:

{{ states('sensor.achtertuin_multisensor_temperature') | float(0) > states('sensor.woonkamer_temperature') | float(0) }}

Thank you @parautenbach

1 Like