Need help with my first script (switch on HUE with specified color)

Hi,

Day 3 of my openHAB voyage :rofl:.
I have created switches for my HUE lights, but the builtin power switches come with a disadvantage (for me).
The switch turns on the lights with the same color as they were turned off.

I need them to be switched in a predefined color, so I guess I will be needing a script then???
Can someone point me in the right direction on where and how to build a script?
And perhaps does anyone have a sample code to manipulate the color and state of HUE lights?

Search for rules in the documentation.

Create a rule, that is triggered when your light will change from off to on and set the color you want.

Here’s some starting code to get you started.

Top of rules - global variables

var HSBType 		Blacklight  	= new HSBType(new DecimalType(63),new PercentType(3),new PercentType(0))		// Black 100%

var HSBType 		Redlight50  	= new HSBType(new DecimalType(7),new PercentType(100),new PercentType(50))		// Scarlet Red 50%
var HSBType 		Redlight  		= new HSBType(new DecimalType(7),new PercentType(100),new PercentType(100))		// Scarlet Red 100%

var HSBType 		Orangelight50  	= new HSBType(new DecimalType(39),new PercentType(87),new PercentType(100))		// Dark Tangerine 50%
var HSBType 		Orangelight  	= new HSBType(new DecimalType(39),new PercentType(87),new PercentType(100))		// Dark Tangerine 100%

var HSBType 		Whitelight50 	= new HSBType(new DecimalType(0),new PercentType(0),new PercentType(50))		// White 50%
var HSBType 		Whitelight  	= new HSBType(new DecimalType(0),new PercentType(0),new PercentType(100))		// White 100%

var HSBType 		Bluelight  		= new HSBType(new DecimalType(234),new PercentType(87),new PercentType(100))	// Blue 100%
var HSBType 		DarkOrangelight = new HSBType(new DecimalType(32),new PercentType(100),new PercentType(100))	// Dark Orange 100% (Halloween)
var HSBType 		Purplelight 	= new HSBType(new DecimalType(300),new PercentType(100),new PercentType(50))	// Purple 100%

Inside a rule:

					BookShelf_Color.sendCommand(Redlight)
						Thread::sleep(200)  
					BookShelf_Dimmer.sendCommand(new PercentType(100)) 
						Thread::sleep(200)
					BookShelf_Switch.sendCommand(ON)
						Thread::sleep(200)

Best, Jay

Thanks,

I have created the following rule:

configuration: {}
triggers:
  - id: "2"
    configuration:
      itemName: Eetkamer_Vermogen
      previousState: OFF
      state: ON
    type: core.ItemStateChangeTrigger
conditions: []
actions:
  - inputs: {}
    id: "1"
    configuration:
      itemName: Eetkamer_Kleur
      command: 1,100,100
    type: core.ItemCommandAction

This works, but I would like to understand @jwiseman solution as well.
I can’t seem to find anything that looks like your code?
Where should I put your code?

My example is creating a .rule file (used in OH v2.x) vs. using the OH 3.x GUI rule editor. My way is the old way but it still works with OH 3.x.

Best, Jay