Hi new to HA and yaml but not to scripting generally.
I want to use variables as much as possible to make my scripts easy to update if/when entities change.
So I have the following script which is that start of a longer process but at the moment all it does is compare two lamps brightness and then change the brighter one to be the same as the brightness of the dimmer one.
The commented line with explicit entity references works but when I try to use variables it does not.
The variables work correctly later in the script but not in the condition. I’ve found many examples of variables being used in condition templates but not with operators i.e. the “>”
There’s no need to use expressions for static strings.
Use your variables to reduce repetition in subsequent variables.
Take care with quotation marks. Because of the internal "-marks, the expression: {{ "{{ init_lamp01_brightness }}">"{{ init_lamp02_brightness }}" }}
from your post isn’t asking "Is the brightness of lamp01 greater than that of lamp02, it’s asking "Is the string{{ init_lamp01_brightness }} greater than the string{{ init_lamp02_brightness }}. This will always render false. Without them you would have gotten a syntax error because…
Nested templates are invalid, just use the variables
Hi Drew, many thanks for the comprehensive and clear reply - apart from anything else I obviously went a bit OTT with the punctuation!!
Yes, I was wondering if I could use a variable in subsequent variables but hadn’t attempted it so thanks I’ll be doing that from now on.
Of course - single and double quotes always trip me up!
Right ok comments are like that - I just put the commented line in my posted code for ease of reference but when I need it I’ll do it properly
Thanks again for your help - really appreciate it