How to target multiple entities based on their state

I vary the colour temperature of my bulbs over the course of the day from the value of a template entity that I use.

At the moment I use node red to target all bulbs that are on. I want to replicate this behaviour in HA automations.

How can I apply an action to all lights that are on?

Similarly when a light turns on I want that to trigger an automation that updates it’s colour temperature. How do I trigger when any light turns on and then use that triggering ID in the action?

Looks as if {{'light.none, ' ~ (states.light | selectattr('state','eq','on') | map(attribute='entity_id') | list | join(', ')) }} may do the trick

All you need is

target:
  entity_id: >
    {{ states.light | selectattr('state','eq','on') | map(attribute='entity_id') | list }} 

If no lights are on, and therefore evaluates to '"", is it true that it will target all lights?

it will evaluate to [], but you should put a condition in place to do nothing if all the lights are off prior to running that service. You don’t want to run the service with a fake light, that’s just unnecessary.