Sensor undefined error

I’m attempting to use the following as a condition in an automation:

      - condition: template
        value_template: '{{ sensor.smartweather_wind_speed_2 > sensor.midge_magnet_windspeed_threshold }}'

When evaluating the template in Developer Tools I get:

UndefinedError: 'sensor' is undefined

I can see both sensors OK in the front end.

I’m lost as to what I need to change.

Any ideas?

You need to get the state of the sensors, and you need to convert them to numbers (they are stored as strings) before making a numeric comparison like greater than. Also your second ‘sensor’ can be an input number. No need to convert it to a sensor if that is what you were doing.

value_template: "{{ states('sensor.smartweather_wind_speed_2')|float > states('input_number.midge_magnet_windspeed_threshold')|float }}"
3 Likes

Fantastic, tom_i. Works a treat. I appreciate your time.

1 Like