Basic Template Question - Using a template as a condition

I’m just trying to learn templates. This is a very basic question.

I want to use a template as a condition in an automation. When the brightness of a light is a specific value (52 in my case), I want the condition to be true. So far, these are the templates I’ve tried:

"{{state_attr('light.bike_room_lights','brightness')}}"=52
"{{state_attr('light.bike_room_lights','brightness')}}"==52
"{{state_attr('light.bike_room_lights','brightness')}}=52"
"{{state_attr('light.bike_room_lights','brightness')}}==52"
"{{52=state_attr('light.bike_room_lights','brightness')}}"
"{{52==state_attr('light.bike_room_lights','brightness')}}"
{"{{state_attr('light.bike_room_lights','brightness')}}"==52}

Any help would be much appreciated. Also, if there’s an intro level video tutorial on templating I’d be interested in suggestions.

Anything outside the delimiters, in this case {{ }}, will be printed as is. All data processing needs to happen inside delimiters. So, generally:

{{ state_attr('light.bike_room_lights', 'brightness') == 52 }}

or

{{ is_state_attr('light.bike_room_lights', 'brightness', 52) }}

Just keep in mind that all states and some attributes will be strings, not one of the actual numeric data types. In those cases you need to use the int() or float() functions for a mathematical comparison or equation to work properly:

{{ states('input_number.example') | float(0) == 52 }}

1 Like

Thank you for the input.

I went to this tutorial and based on it, I came up with a functional template as follows:

{% if state_attr('light.bike_room_lights','brightness') == 52 %}
 True
 {% else %}
 False
 {% endif %}