Helped me solve something similar too! Here is another example of something similar. I had a lot of trouble getting the syntax right and also had to restart HA rather than just reloading the template entities. I use this as my projector can’t be controlled with IR commands when it is stopping or starting. The same command is used to stop and start so it is very state dependant.
- sensor:
- name: "Projector State"
state: >
{% if (states('sensor.projector_checker_current_consumption') | int < 1) %} off
{% elif (states('sensor.projector_checker_current_consumption') | int > 260) %} on
{% else %} transition
{% endif %}