Cheat sheet
| states('sensor.x') | the state as a string; "unknown" if there is no such entity |
|---|---|
| | float(0) / | int(0) | to a number; 0 is the fallback if it is not a number (without it you get an error) |
| is_state('light.x', 'on') | compare the state |
| state_attr('light.x', 'brightness') | an attribute |
| states.light | selectattr('state','eq','on') | filter a domain’s entities |
| iif(cond, 'a', 'b') | a short if |
| now().hour, today_at('22:00') | time |
In YAML always quote a template: value_template: "{{ … }}". Check a whole file: YAML checker.