Trigger value template with two temperature sensors

For the creation of an automation I want to create a trigger (When) that will become active/true when the temperature of the sensor outside is higher than the temperature of the sensor inside. The following code doesn’t seems to work:

{{states.sensor.netatmo_weather_station_outdoor_temperature > states.sensor.netatmo_weather_station_indoor_temperature}}

What is wrong with this Value template code?

You’re not comparing the state of the entity, you’re comparing the state objects. Take a look at the templating documentation for more info on the states object and states() method. Also make sure you are comparing numbers not strings.

1 Like

Thanks for pointing me in the right direction. Got it working now:

{{states('sensor.netatmo_weather_station_outdoor_temperature') > states('sensor.netatmo_weather_station_indoor_temperature')}}

That’s still not right: you’re comparing strings rather than numbers (see Petro’s last sentence). Sensor states are always strings and need converting before you can do comparisons or arithmetic.

When it’s 15°C inside and 8°C outside, your template will return true because “8” is greater than “15”.

You want:

{{ states('sensor.netatmo_weather_station_outdoor_temperature')|float(0) >
   states('sensor.netatmo_weather_station_indoor_temperature')|float(0) }}

The 0 in float(0) is the default value returned if the sensor state can’t be converted to a number — if it is unavailable, for example.

1 Like

@Troon thank you for this additional explanation. I will adjust my automation!