OH5 DSL Rule - "getGreen() from the type HSBType is deprecated"

Hi team

I’m moving a groupMember rule from OH4 to OH5

While it still works, I am seeing these messages

2025-11-06 13:37:51.048 \[INFO \] \[el.core.internal.ModelRepositoryImpl\] - Loading model ‘Colour_OH5.rules’
2025-11-06 13:37:51.773 \[INFO \] \[el.core.internal.ModelRepositoryImpl\] - Validation issues found in configuration model ‘Colour_OH5.rules’, usin                     g it anyway:
The method getRed() from the type HSBType is deprecated
The method getRed() from the type HSBType is deprecated
The method getGreen() from the type HSBType is deprecated
The method getGreen() from the type HSBType is deprecated
The method getBlue() from the type HSBType is deprecated
The method getBlue() from the type HSBType is deprecated

The rule itself is fairly simple, in so much as it is meant to see a colour picker change in a member of the ColourPicker group

Extract the new RGB components from that and push them into three items, with names derived from the ColourPicker

		rule "colour"
		when
			Member of ColourPickers received command
		then
	
		 
		logInfo("Colour","Colour  = "+triggeringItem.name.toString+" Changed to "+triggeringItem.state.toString)
		if (triggeringItem.state.toString == "ON") {sendCommand(triggeringItem.name.toString,"0,0,100")}
		if (triggeringItem.state.toString == "OFF") {sendCommand(triggeringItem.name.toString,"0,0,0")}
		else
		{
				var HSBType hsbValue = triggeringItem.state as HSBType

		var int redValue = hsbValue.red.intValue
		var int greenValue = hsbValue.green.intValue
		var int blueValue = hsbValue.blue.intValue

		
		var RED = triggeringItem.name+"_RED"
		var GREEN = triggeringItem.name+"_GREEN"
		var BLUE = triggeringItem.name+"_BLUE"
	
		
		
		logInfo("Colour",triggeringItem.name.toString+" HSB Value = "+hsbValue+"\nRGB Values \n"+RED+" = "+redValue+"% \n"+GREEN+" = "+greenValue+"%\n"+BLUE+" = "+blueValue)	
		
		
		sendCommand(RED,redValue.toString)
		sendCommand(GREEN,greenValue.toString)
		sendCommand(BLUE,blueValue.toString)
		}

		end

Example Items

	Group	ColourPickers		"All Colour Pickers"


// Edit the following to suit the Dimmer channels in use - Any colour item should be put into the (ColourPickers) group
	
	Color	TestItem01Colour				"Test Colour 1 Colour Picker"		<colorpicker>		(ColourPickers, gLoungeLight)	["light"]
	Dimmer	TestItem01Colour_RED  			"Test Colour 1 Red"					<slider>		
	Dimmer	TestItem01Colour_GREEN  		"Test Colour 1 Green"				<slider>		
	Dimmer	TestItem01Colour_BLUE  			"Test Colour 1 Blue"				<slider>		
	Dimmer	TestItem01Colour_WHITE 			"Test Colour 1 White"				<slider>			(gLoungeLight)					["Light"]	


	Color	TestItem02Colour			"Test Colour 2 Colour picker"		<colorpicker>	(ColourPickers)	["light"]
	Dimmer	TestItem02Colour_RED  		"Test Colour 2 Red"					<slider>				
	Dimmer	TestItem02Colour_GREEN		"Test Colour 2 Green"				<slider>				
	Dimmer	TestItem02Colour_BLUE 		"Test Colour 2 Blue"				<slider>				
	Dimmer	TestItem02Colour_WHITE		"Test Colour 2 White"				<slider>			["Light"]

My Question is never “Fix this for me”

but “where can I go to find out how to fix it myself?”

I’ve gone looking for OH5 DSL HSL rules example, but can’t find any guidance.

Can someone point me in the correct direction please?

(FYI, I’ve tried creating this rule in the MainUI and I just can’t wrap my head around it, this DSL approach just seems to work… until something changes :slight_smile: )

I don’t use Color Items so I probably couldn’t fix this for you anyway. But I do remember seeing some PRs go by which created a Color utils class. I think all these transformations were moved to that utility.

The first place to look when the docs fail to provide answers is the JavaDocs. The JavaDoc for HSBType is here.

That points to org.openhab.core.util.ColorUtil.

I don’t know if ColorUtil is included by default in the rule preset or if you have to import it. But that’s the replacement for those deprecated functions on HSBType.

1 Like

Thanks Rich

I’ll have a good read and see what I can learn

Hi @MDAR

var rgb = hsbToRgb(hsbValue)

var redValue   = rgb.get(0)
var greenValue = rgb.get(1)
var blueValue  = rgb.get(2)

should do the trick for you.

Just from the top of my head now, so might need a little tweaking :wink:

1 Like

Thanks @rlkoshak & @Hans_Lree

You never fail to deliver.

It took me a little time to iron out the small details, but it’s working now

AND I have the illusive White component working from the colour picker now. :partying_face: (I’ve been looking for a solution for that for AGES)


For anyone finding this later, here are the working components

The Items files

the “All Colour Pickers” group is only there so the rule works with all the members

You can change whatever you like in the “TestItem01Colour” part, as long as the component colours have the same start, and end with “_RED”, “_GREEN”, “_BLUE” and “_WHITE”

	Group	ColourPickers		"All Colour Pickers"


// Edit the following to suit the Dimmer channels in use - Any colour item should be put into the (ColourPickers) group
	
	Color	TestItem01Colour				"Test Colour 1 Colour Picker"		<colorpicker>		(ColourPickers)	["light"]
	Dimmer	TestItem01Colour_RED  			"Test Colour 1 Red"					<slider>		
	Dimmer	TestItem01Colour_GREEN  		"Test Colour 1 Green"				<slider>		
	Dimmer	TestItem01Colour_BLUE  			"Test Colour 1 Blue"				<slider>		
	Dimmer	TestItem01Colour_WHITE 			"Test Colour 1 White"				<slider>		


	Color	TestItem02Colour			"Test Colour 2 Colour picker"		<colorpicker>	(ColourPickers)	["light"]
	Dimmer	TestItem02Colour_RED  		"Test Colour 2 Red"					<slider>				
	Dimmer	TestItem02Colour_GREEN		"Test Colour 2 Green"				<slider>				
	Dimmer	TestItem02Colour_BLUE 		"Test Colour 2 Blue"				<slider>				
	Dimmer	TestItem02Colour_WHITE		"Test Colour 2 White"				<slider>				

And this is the new OH5 DSL rule that does the HSL to RGBW magic

// Stuart Hanlon - MDAR Ltd - Velbus.eu NOV 2025
// Rule for converting Colourpicker from HSL to RGBW
		rule "colour"
		when
			Member of ColourPickers received command
		then
	
		 		// Create a loop to restart the rule with correct values for ON and OFF
		logInfo("Colour","Colour  = "+triggeringItem.name.toString+" Changed to "+triggeringItem.state)

		if (triggeringItem.state.toString == "ON")	{sendCommand(triggeringItem.name.toString,"0,0,100")}
		if (triggeringItem.state.toString == "OFF")	{sendCommand(triggeringItem.name.toString,"0,0,0")}
		else 
{
		// Split RGBW values from HSL and send to components
		
		
	// OH5 solution, special thanks to @Hans_Lree and @rikoshak

var HSBType hsbValue = triggeringItem.state as HSBType
var rgbw = hsbToRgbw(hsbValue)

var Number redValue   = rgbw.get(0)
var Number greenValue = rgbw.get(1)
var Number blueValue  = rgbw.get(2)
var Number whiteValue  = rgbw.get(3)

// 		logInfo("Colour",triggeringItem.name.toString+"\nRGBW HEX Values ;\n RED = "+redValue+"\n GREEN = "+greenValue+"\n BLUE = "+blueValue+"\nWHITE = "+whiteValue)	


// Convert HEX value to %, only required if destination item doesn't support 0 to 255

if (redValue >0)		{redValue	=	(redValue/255) *100}

if (greenValue >0)		{greenValue	= 	(greenValue/255) *100}

if (blueValue >0)		{blueValue	=	(blueValue/255) *100}

if (whiteValue>0)		{whiteValue	=	(whiteValue/255) *100}



		var RED = triggeringItem.name+"_RED"
		var GREEN = triggeringItem.name+"_GREEN"
		var BLUE = triggeringItem.name+"_BLUE"
		var WHITE = triggeringItem.name+"_WHITE"
	
		
		
				logInfo("Colour",triggeringItem.name.toString+"\n    HSL Value = "+hsbValue+"\n    RGBW Values ;\n      "+RED+" = "+redValue+"% \n      "+GREEN+" = "+greenValue+"%\n      "+BLUE+" = "+blueValue+"%\n      "+WHITE+" = "+whiteValue+"%")		
		
		
		sendCommand(RED,redValue.toString)
		sendCommand(GREEN,greenValue.toString)
		sendCommand(BLUE,blueValue.toString)
		sendCommand(WHITE,whiteValue.toString)
}


		end

Example logging

2025-11-07 12:12:31.146 [INFO ] [org.openhab.core.model.script.Colour] - TestItem01Colour
    HSL Value = 31,100,100
    RGBW Values ;
      TestItem01Colour_RED = 100.00000000%
      TestItem01Colour_GREEN = 51.76470600%
      TestItem01Colour_BLUE = 0%
      TestItem01Colour_WHITE = 0%
2025-11-07 12:12:41.805 [INFO ] [org.openhab.core.model.script.Colour] - Colour  = TestItem01Colour Changed to 260,100,100
2025-11-07 12:12:41.819 [INFO ] [org.openhab.core.model.script.Colour] - TestItem01Colour
    HSL Value = 260,100,100
    RGBW Values ;
      TestItem01Colour_RED = 33.33333300%
      TestItem01Colour_GREEN = 0%
      TestItem01Colour_BLUE = 100.00000000%
      TestItem01Colour_WHITE = 0%
2025-11-07 12:12:44.333 [INFO ] [org.openhab.core.model.script.Colour] - Colour  = TestItem01Colour Changed to 260,72,100
2025-11-07 12:12:44.346 [INFO ] [org.openhab.core.model.script.Colour] - TestItem01Colour
    HSL Value = 260,72,100
    RGBW Values ;
      TestItem01Colour_RED = 23.92156900%
      TestItem01Colour_GREEN = 0%
      TestItem01Colour_BLUE = 72.15686300%
      TestItem01Colour_WHITE = 27.84313700%

Good to hear you got things working :slight_smile:

Just as a suggestion for a more compact syntax, you could just pull the above two lines together as one

var rgbw = hsbToRgbw(triggeringItem.state as HSBType)

1 Like

:smiley:
As long as I remove the reference to the hsbValue from the logging line

1 Like