Template rendered invalid service:

I noticed recently this error in my log:
Cat Fountain Comes On With Kitchen Lights: Error executing script. Unexpected error for call_service at pos 1: Template rendered invalid service:
Here is the automation:

- alias: Cat Fountain Comes On With Kitchen Lights   
  initial_state: true
  trigger:
    platform: state
    entity_id: switch.kitchen_light_switch
  action:
    service_template: >
      {%- if states('switch.kitchen_light_switch') == 'on' -%}
        switch.turn_on
      {%- endif -%}
    entity_id: switch.cat_fountain_switch 

After a little research I think this is happening because I don’t have an “else” statement but I don’t want the cat fountain to turn off with the kitchen light. How can I change this automation so I don’t get the error? BTW the automation works fine, just trying to clean up the error log.

Add to: 'on' to your trigger to only trigger the automation when the kitchen lights turn on, not when they turn off. Like this:

- alias: Cat Fountain Comes On With Kitchen Lights   
  initial_state: true
  trigger:
    platform: state
    entity_id: switch.kitchen_light_switch
    to: 'on'
  action:
    service: switch.turn_on
    entity_id: switch.cat_fountain_switch

Thanks. Didn’t even think about doing it the easy way.