A template that is almost right makes an automation silently do nothing, and you only find out when the lights stay off. Home Assistant has a built-in scratchpad that shows the result of a template right away.
Open Developer Tools in the sidebar and choose the Template tab. Type a template on the left, and the rendered result appears on the right while you type. Nothing you do here changes your system.
{{ states('sensor.living_room_temperature') | float(0) > 21 }}
Replace the entity with one of your own. The answer is True or False, so you see at once whether the condition in your automation would pass. The float(0) part matters: a sensor that is unavailable is text, not a number, and without a default the comparison throws an error. With a default of 0 the template keeps working.
{{ now().hour }}
{{ is_state('person.jordi', 'home') }}
{{ state_attr('climate.livingroom', 'current_temperature') }}
The first prints the current hour, useful for time conditions. The second checks if someone is home (use your own person entity). The third reads one attribute of an entity. The States tab right next to it lists every entity with its attributes, which is where I would look for the exact name to copy.
Once the template gives the right answer, paste it into your automation, script or template sensor. In a condition it goes under a template condition, in a notification message it sits between {{ }} in the text. Keep the working version in Developer Tools while you edit, and use the Automation trace (Settings, Automations, the three dots, Traces) to see what the template returned on the last real run.
The editor renders with the current state of your system, so a template that depends on a sensor looks fine now and might behave differently at night. Test the edge cases by temporarily using fixed values, for example {% set t = 25 %} at the top. Also, a template in YAML needs the right quotes around it; the tool shows only the template itself, without the YAML wrapper.
Further reading: Home Assistant: templating
Going deeper: Guide: Home Assistant backups in Docker, with a failure alert on your phone and a copy off the box