Change light group based on sun elevation

I’m trying to turn on different lights as part of an automation based on the sun elevation.

I’d like to avoid having to create two separate automations for this - partly because the automation may get more complex in the future and partly because I’d just like to figure out how to solve this.

My first idea was something like this

- id: "1610642684966"
  alias: Kitchen Motion Activated Lights
  description: ""
    path: homeassistant/motion_light.yaml
      no_motion_wait: '{{ ''300'' if state_attr("sun.sun", "elevation") < 3.5 else ''60'' }}'
      motion_entity: binary_sensor.kitchen_motion_sensor_occupancy
        entity_id: '{{ ''lights.kitchen_and_conservatory_lights'' if state_attr("sun.sun", "elevation") < 3.5 else ''lights.kitchen_lights'' }}'

The no_motion_wait template works perfectly, but the entity_id one does not.

Any suggestions on how else I might implement this condition?