I’ve recently discovered Template Switches and have added a lot of those to my Home Assistant. Had no problems with them so far since they all have just handled states that is either On or Off.
I want to add 4 buttons to my panel that sets my ceiling lights either Off, Low, Normal or Bright. Is it possible to make a template switch that shows to be on if brightness of a light is between 20-40% for example?
you sure can value_template: '{{ 20 < state_attr("light.light_name", "brightness") | int < 40}}'
Of course you’ll have to replace the entity and attribute names with yours…
I also tried this for my colored lights presets but didn’t seem to work.
{{ state_attr("light.living_room_ambiance", "xy_color") | int == "0.508,0.383" }}
My guessing it has something to do with the output not matching, but the problem is when I try to add the below to the template editor I get the error: Error rendering template: UndefinedError: ‘my_test_json’ is undefined
So I don’t have a way to check what the output is for that attribute.
Advice code is correct. The error message you got was because you didn’t delete all the code from the template example. Make sure you delete everything then paste your code again