Your variable t is a string so cannot compared in the way that you are comparing it. Additionally it is not needed there, it can be used directly in the service call.
{% set t = now.hour()|int %}{{ "on" if (t >= 12 or t < 18) else "off" }}
Now the question is - did you mean or, or did you mean and?
OR means the light will be turned on is the hour is after 11am OR before 6pm otherwise it will be off.
AND means the light will be turned on if the hour is after 11am AND the hour is before 6pm.
In this case, your automation will trigger at 12pm and turn the light on, and when it triggers again at 6pm it will turn the light off.
No because 00 is not a valid integer. Just use 0 in the two tuples (12,0) and (18,0).
However, why do you believe there’s a need for the template?
The automation’s Time Trigger can only occur at 12:00 and 18:00 (when the light will be turned on). How will the template ever report off if the Time Trigger never triggers at any other times than 12 and 18?
action:
- service: "switch.turn_{% set t = now.hour()|int %}{{ "on" if (t >= 12 or t < 18) else "off" }}"
----
bad indentation of a sequence entry at line 393, column 61:
... {% set t = now.hour()|int %}{{ "on" if (t >= 12 or t < 18) else ...