While I’ve programmed in a number of different languages, from low level like Assembler, to higher level like Python or Java, I’m having serious difficulty understanding how to use variables in YAML files on ESPHome. Right now I’m primarily dealing with numbers and text and I can’t find clear examples of how to compare one number to another, to use them in calculations and store the result, or how to change the value of a variable. (The same for texts.) I can use the web interface with a template to change the value of a text or number, but then I am not clear just how to use the resulting value in the YAML file.
It looks to me like most work with texts is done with lambda functions. Is that just for convenience, or is that often the only way to work with comparing values, or setting them, or using them together?
I have tried to work with global variables, but I’m not clear if I can declare a global variable, then use it in a template or sensor. I’m also not at all clear how I can add two numbers, concatenate text strings, change the value of a global variable, or even print the value of a text string in a log message. (I did find one example for logging the value of a text, but when I tried it, I got gibberish that looked like it could either be a pointer instead of the text, or maybe that it interpreted the text itself as a pointer to some random place in memory.)
Is there a good summary somewhere of how to handle variables in YAML? Or is it best to just do it in lambda functions?