I cannot get the service template to work in the following script. Is it not scripted properly? Since I need a condition, should I create and call an Automation instead?
Change the service to switch.turn_on and just use a state condition before that service call that sun.sun is below_horizon (you can use conditions in scripts or the action of an automation)