Toggle Button / Script to Colour Loop Hue Lights

I’ve been trying to find a way to do the following in a script with no luck so was wondering if anyone could help:

Have a toggle button on the Lovelace UI that does the following:

  1. Checks if a group of hue light are off and if they are it does the following:
    -Turns all the lights on to a particular colour to start
    -colorloop’s all lights in the group

  2. Check if the lights are on but not in a colorloop and then does the above if they are not

  3. Checks if the lights are on and in a colorloop and turns them off

Can this all be achieve by running one script/pressing one toggle button in the UI?

Yes this can be achieved.

Could you share some examples or code to how I would go about to achieve this?