Rgb light

In the item wiki:
Color Color information (RGB) OnOff, IncreaseDecrease, Percent, HSB
Dimmer Item carrying a percentage value for dimmers OnOff, IncreaseDecrease, Percent
Switch Typically used for lights (on/off) OnOff

I have been searching around in the wiki, but I can not figure out what is valid data type for each of the item.

What I am trying to figure out is: sendCommand(itemName,???)

I have an RGB light that i would like to to send rgb values to, the values are defined in number items:

Number redValue
Number greenValue
Number blueValue

So which item should i Use for RGB and how does the command look like? And where in the wiki can I figure out this?

Switch itemTest "Test" {dmx="CHANNEL[1,2,3:1000]"}

sendCommand(itemTest,redValue.toString +"," +greenValue.toString +"," +blueValue.toString)

what light is it (make/model) and what protocol does it use?

A simple light like this connected to my dmx driver. I can adjust each color when i have defined it as Dimmer testDimmer {dmx="CHANNEL[1:1000]"} but now i want to adjust it from rules.

A Switch should only receive “ON” and “OFF” commands.

You’re looking for Color

In items:

Color itemTest "test" {dmx="CHANNEL[1,2,3:1000]"}

And the command you would send would be a single color or HSBtype BUT, if you want to adjust the values of R G and B separately, you should define a channel for each one.

In items:

Dimmer redTest "test" {dmx="CHANNEL[1:1000]"}
Dimmer greenTest "test" {dmx="CHANNEL[2:1000]"}
Dimmer blueTest "test" {dmx="CHANNEL[3:1000]"}

Therefore in rules:

sendCommand(redTest,redValue)
sendCommand(greenTest,greenValue)
sendCommand(blueTest,blueValue)

Thanks, I think I will use the color type:)

So how can I get my number value type into

I bascically have this setup:

and then I want to set color with the lower scene and the dimmer will then take those values and multiply them with the percentage. The top scene just select which lights to control

If you used Colorpicker in your sitemap you’d be able to change colour and brightness in one widget. e.g.

In Items:

Color itemTest "test" {dmx="CHANNEL[1,2,3:1000]"}

In Sitemap:

Colorpicker	item=itemTest

If you’re set on using a scene selection and a dimmer slider for brightness then (and I’m only guessing here since I don’t have a DMX bulb to test) you’ll need to configure a rule to make up the HSBtype yourself.

rule OnSceneChange
when
	Item scenesTest received command
then
	val white = new HSBType(new DecimalType(000),new PercentType(000),new PercentType(100))
	val offwhite = new HSBType(new DecimalType(060),new PercentType(020),new PercentType(100))
	switch receivedCommand {
		
		case "White":		
		{
			itemTest.sendCommand(white)	
		}
		case "WharmWhite":		
		{
			itemTest.sendCommand(offwhite)	
		}
}
end

rule OnDimmerChange
when
	Item dimmerTest received command
then
	var oldHSB = itemTest.state as HSBType
	var oldHue = oldHSB.hue
	var oldSat = oldHSB.saturation
	var HSBType newColor= new HSBType(oldHue,oldSat,receivedCommand as PercentType)

	sendCommand(itemTest,newColor)
end

You’ll need to make sure that the dimmer is set in the rule as well.

Thanks,
The reason why to use scenes instead of color picker is that it also needs to be integrated to amazon echo.

The color picker works, however i have trouble understanding:

val white = new HSBType(new DecimalType(000),new PercentType(000),new PercentType(100))

why DecimalType and percentype?

and also can you do this?

case "White":		
		{

shouldnt it be 1 ,2 , 3, and so on when

Switch item=Scene_ColorSelector label="Color" mappings=[1=WharmWhite, 2=White, 3=Lounge,4=Night]

is the definition in the sitemap.

HSBType is of made of three parts:

Hue is measured between 0 and 360 degrees and hence decimal. Imagine a colour wheel, red is 0 degrees, green is 120 and blue is 240, back to red at 360/0 again.

Saturation is the amount of colour, and Brightness is measured in percent. 0% saturation and 100% brightness of any hue is white.

Yes, if your switch uses 1, 2, 3 etc you can use 1, 2 and 3 in your cases.

Almost there:

I am bit unsure how to do the for.each member in rules:

/*testcomment*/

import org.openhab.core.library.types.*

    var HSBType hsbValue
	var HSBType hsbValue2
    var String  redValue
    var String  greenValue
    var String  blueValue


rule "Set RGB value"
    when
            Item lampColor changed
    then
            hsbValue = lampColor.state as HSBType
			Group_Light.members.forEach( s |
			if s.state = ON{
				sendCommand( s, hsbValue))
			}

end


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////// Switch the different areas where LED-Lights should be switched on/off ////////////////7////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////


rule "changeLightGroup"
when
	Item groupSelector received command
then
	if (receivedCommand==1) {
			Group_Tv.members.forEach( s | sendCommand( s, hsbValue2))
	}

		if (receivedCommand==2) {
			Group_Dinner.members.forEach( s | sendCommand( s, hsbValue2))
	}
	
		if (receivedCommand==3) {
			Group_Reading.members.forEach( s | sendCommand( s, hsbValue2))
	}
	
		if (receivedCommand==4) {
			hsbValue2 = new HSBType(new DecimalType(060),new PercentType(000),new PercentType(000))
			Group_Light.members.forEach( s | sendCommand( s, hsbValue2))
	}
end

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////// Change the moodings of light, e.g. warm white, white, lounge and night ////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
rule "changeLightMood"
when
	Item moodSelector received command
then
	//warm white
	if (receivedCommand==1) {
		hsbValue2 = new HSBType(new DecimalType(060),new PercentType(100),new PercentType(100))
		lampColor.sendCommand(hsbValue2)		
	}
    //white
		if (receivedCommand==2) {
		hsbValue2 = new HSBType(new DecimalType(0),new PercentType(0),new PercentType(100))
		sendCommand(lampColor,hsbValue2)
	}
	//lounge
		if (receivedCommand==3) {
		hsbValue2 = new HSBType(new DecimalType(300),new PercentType(100),new PercentType(50))
		sendCommand(lampColor,hsbValue2)
	}
	//night
		if (receivedCommand==4) {
		hsbValue2 = new HSBType(new DecimalType(000),new PercentType(100),new PercentType(50))
		sendCommand(lampColor,hsbValue2)
	}
	
	Group_Light.members.forEach( s |
			if s.state = ON{
				sendCommand( s, hsbValue2))
			}
end

And here are my items defined:

Group Group_Kitchen 
Group Group_LivingRoom 
Group Group_Light
Group Group_Bar
Group Group_Tv
Group Group_Dinner

Color LL1 "LL1"(Group_Light,Group_Kitchen) {dmx="CHANNEL[25,26,27:1000]"}
Color LL2 "LL2"(Group_Light,Group_Kitchen) {dmx="CHANNEL[22,23,24:1000]"}
Color LL3 "LL3"(Group_Light,Group_Kitchen) {dmx="CHANNEL[19,20,21:1000]"}
Color LL4 "LL4"(Group_Light,Group_Tv,Group_Dinner) {dmx="CHANNEL[16,17,18:1000]"}
Color LL5 "LL5"(Group_Light,Group_Tv,Group_Dinner) {dmx="CHANNEL[13,14,15:1000]"}
Color LL6 "LL6"(Group_Light,Group_Kitchen) {dmx="CHANNEL[10,11,12:1000]"}
Color LL7 "LL7"(Group_Light,Group_Kitchen) {dmx="CHANNEL[7,8,9:1000]"}
Color LL8 "LL8"(Group_Light,Group_Dinner) {dmx="CHANNEL[4,5,6:1000]"}
Color LL9 "LL9"(Group_Light,Group_Dinner) {dmx="CHANNEL[1,2,3:1000]"}
Color LL10 "LL10"(Group_Light,Group_Dinner) {dmx="CHANNEL[52,53,54:1000]"}
Color LL11 "LL11"(Group_Light,Group_Kitchen) {dmx="CHANNEL[49,50,51:1000]"}
Color LL12 "LL12"(Group_Light,Group_Kitchen) {dmx="CHANNEL[46,47,48:1000]"}
Color LL13 "LL13"(Group_Light,Group_Kitchen,Group_Dinner) {dmx="CHANNEL[43,44,45:1000]"}
Color LL14 "LL14"(Group_Light,Group_Dinner) {dmx="CHANNEL[40,41,42:1000]"}
Color LL15 "LL15"(Group_Light,Group_Dinner) {dmx="CHANNEL[37,38,39:1000]"}
Color LL16 "LL16"(Group_Light,Group_Tv,Group_Reading) {dmx="CHANNEL[34,35,36:1000]"}
Color LL17 "LL17"(Group_Light,Group_Reading) {dmx="CHANNEL[31,32,33:1000]"}
Color LL18 "LL18"(Group_Light,Group_Reading) {dmx="CHANNEL[28,29,30:1000]"}
Color LL19 "LL19"(Group_Light,Group_Reading) {dmx="CHANNEL[79,80,81:1000]"}
Color LL20 "LL20"(Group_Light,Group_Reading) {dmx="CHANNEL[76,77,78:1000]"}
Color LL21 "LL21"(Group_Light,Group_Reading) {dmx="CHANNEL[73,74,75:1000]"}
Color LL22 "LL22"(Group_Light,Group_Reading) {dmx="CHANNEL[70,71,72:1000]"}
Color LL23 "LL23"(Group_Light,Group_Reading) {dmx="CHANNEL[67,68,69:1000]"}
Color LL24 "LL24"(Group_Light,Group_Reading) {dmx="CHANNEL[64,65,66:1000]"}
Color LL25 "LL25"(Group_Light,Group_Reading) {dmx="CHANNEL[61,62,63:1000]"}
Color LL26 "LL26"(Group_Light,Group_Reading) {dmx="CHANNEL[58,59,60:1000]"}
Color LL27 "LL27"(Group_Light,Group_Reading) {dmx="CHANNEL[55,56,57:1000]"}
Color LL28 "LL28"(Group_Light,Group_Reading) {dmx="CHANNEL[106,107,108:1000]"}
Color LL29 "LL29"(Group_Light,Group_Reading) {dmx="CHANNEL[103,104,105:1000]"}
Color LL30 "LL30"(Group_Light,Group_Reading) {dmx="CHANNEL[100,101,102:1000]"}
Color LB1 "LB1"(Group_Light,Group_Bar) {dmx="CHANNEL[97,98,99:1000]"}
Color LB2 "LB2"(Group_Light,Group_Bar) {dmx="CHANNEL[94,95,96:1000]"}
Color LB3 "LB3"(Group_Light,Group_Bar) {dmx="CHANNEL[91,92,93:1000]"}
Color LB4 "LB4"(Group_Light,Group_Bar) {dmx="CHANNEL[88,89,90:1000]"}
Color LB5 "LB5"(Group_Light,Group_Bar) {dmx="CHANNEL[85,86,87:1000]"}
Color LB6 "LB6"(Group_Light,Group_Bar) {dmx="CHANNEL[82,83,84:1000]"}



Color lampColor "theLampColor" /*holds the selected color scheme*/

Number groupSelector "Group" <sofa> // any idea which icon to use?
Number moodSelector "Mood" <sofa> // any idea which icon to use?

What is the refresh rate :1000 meaning? Should i increase this to 100000? Because when a rule get executed it get updated instant anyway right?

And are

 var HSBType hsbValue
  var HSBType hsbValue2

global variables that are kept as long as openhab is running or do I need to define it as items instead, and how to do this?

Can I call a rule from a rule?

That’s invalid syntax, try:

Val fixedHSB = hsbvalue2
Group_Light.members.filter( s | s.state != "0,0,0").forEach [ item | 
				sendCommand(item, hsbValue2)
			]

You’ll have to change that to what state the lights would be if they’re off, I’m only guessing that they would be “0,0,0”

This is an optional delay, I’d probably keep it how it is.

Global Variables are kept and shared between the rule file for as long as openhab is running. Items are only restored after a reboot if they are persisted and made with strategy restoreOnStartup.

Great, I am off to skiing now, will try it out on monday.

I tried it this morning with out much luck. So how can debug it? How can I print out the value of s,hsbValue2 and item, and how can you use them without declaring them? This seems to be some strange openhab syntax and not java syntax. Which tool do you use to write your rules, to make sure syntax is correct?

And what the difference between val and var hsbValue?

rule "changeLightGroup"
when
	Item groupSelector received command
then
	if (receivedCommand==1) {
			Group_Tv.members.filter( s | s.state != "0,0,0").forEach [ item | 
				sendCommand(item, hsbValue2)
			]
	}

	if (receivedCommand==2) {
		Group_Dinner.members.filter( s | s.state != "0,0,0").forEach [ item | 
			sendCommand(item, hsbValue2)
		]
	}

	if (receivedCommand==3) {
		Group_Reading..filter( s | s.state != "0,0,0").forEach [ item | 
			sendCommand(item, hsbValue2)
		]	
	}

	if (receivedCommand==4) {
		hsbValue2 = new HSBType(new DecimalType(000),new PercentType(000),new PercentType(000))
		Group_Light.members.filter( s | s.state != "0,0,0").forEach [ item | 
			sendCommand(item, hsbValue2)
		]
	}
end

I am afraid the error is here:

	//warm white
	if (receivedCommand==1) {
		hsbValue2 = new HSBType(new DecimalType(060),new PercentType(100),new PercentType(100))
		lampColor.sendCommand(hsbValue2)		
	}

Use the openhab designer to write your rules and ensure that the syntax is correct.

Try

logInfo("Debug", "hsbvalue2 equals " + hsbValue2.toString)
Group_Light.members.forEach [s | logInfo("Debug", s.name + " equals " + s.state.toString)]

and read from the openhab.log file to see what the states actually are.

var is a variable, val is fixed, you have to use fixed values in those methods.

So I installed the designer, however when I installed it I noticed that it does not work unless you have the default_configuration.cfg in the directory. I would like to add this to the wiki since it seems that several other also has this issue.

So my error is in the declaration of the global variable:

import org.openhab.core.library.types.*

val HSBType hsbValue

so how do I import the HSBtype, where in the wiki can I find the import packages that you need for different rules?

val HAS to be initialized, because it can’t change, if you assign it later you must use var.

If you hover over the line that has a red line indicating an error, it tells you how it can be fixed. If your import and variable declarations are at the top of the rules file, then they are valid.

1 Like

So now my dmx.rules file does not contain any error:

// testcomment

import org.openhab.core.library.types.*

    var HSBType hsbValue
	var HSBType hsbValue2
 
rule "Set RGB value"
    when
            Item lampColor changed
    then
            hsbValue = lampColor.state as HSBType
end



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////// Switch the different areas where LED-Lights should be switched on/off ////////////////7////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////


rule "changeLightGroup"
when
	Item groupSelector received command
then
	logInfo("Debug", "hsbvalue2 equals " + hsbValue2.toString)
	
	Group_Light.members.forEach [s | logInfo("Debug", s.name + " equals " + s.state.toString)]
	
	if (receivedCommand==1) {
			Group_Tv.members.filter( s | s.state != "0,0,0").forEach [ item | 
				sendCommand(item, hsbValue2.toString())
			]
	}

	if (receivedCommand==2) {
		Group_Dinner.members.filter( s | s.state != "0,0,0").forEach [ item | 
			sendCommand(item, hsbValue2.toString())
		]
	}

	if (receivedCommand==3) {
		Group_Reading.members.filter( s | s.state != "0,0,0").forEach [ item | 
			sendCommand(item, hsbValue2.toString())
		]	
	}

	if (receivedCommand==4) {
		hsbValue2 = new HSBType(new DecimalType(000),new PercentType(000),new PercentType(000))
		Group_Light.members.filter( s | s.state != "0,0,0").forEach [ item | 
			sendCommand(item, hsbValue2.toString())
		]
	}
end

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////// Change the moodings of light, e.g. warm white, white, lounge and night ////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
rule "changeLightMood"
when
	Item moodSelector received command
then
	//warm white
	if (receivedCommand==1) {
		hsbValue2 = new HSBType(new DecimalType(060),new PercentType(100),new PercentType(100))
		lampColor.sendCommand(hsbValue2)		
	}
    //white
	if (receivedCommand==2) {
		hsbValue2 = new HSBType(new DecimalType(0),new PercentType(0),new PercentType(100))
		sendCommand(lampColor,hsbValue2)
	}
	//lounge
		if (receivedCommand==3) {
		hsbValue2 = new HSBType(new DecimalType(300),new PercentType(100),new PercentType(50))
		sendCommand(lampColor,hsbValue2)
	}
	//night
		if (receivedCommand==4) {
		hsbValue2 = new HSBType(new DecimalType(000),new PercentType(100),new PercentType(50))
		sendCommand(lampColor,hsbValue2)
	}
end

However when i run openhab I get this error:

19:29:36.845 [ERROR] [o.o.c.s.ScriptExecutionThread :50 ] - Error during the execution of rule 'changeLightGroup': Could not invoke method: org.openhab.model.script.actions.BusEvent.sendCommand(java.lang.String,java.lang.String) on instance: null

So how can i get around this?

I highly recommend using item.sendCommand(hsbValue2) or the second best choice sendCommand(item.name, hsbValue2.toString).

thanks, changed it to item.
but still gets
:50 ] - Error during the execution of rule 'changeLightGroup': cannot invoke method public java.lang.String org.openhab.core.library.types.HSBType.toString() on null

what does that mean?

Are you certain that “changeLightMood” gets executed at least one before “changeLightGroup”? If not then hsbValue and hsbValue2 are never set (i.e. null).

ALmost works now!!

Changing colors does not send anything to the light:

if (receivedCommand==1) {
		Group_Tv.members.filter( s | s.state != "0,0,0").forEach [ item | 
			item.sendCommand(hsbValue2)
		]
}

but if I switch off then select color and then select scene then the color changes.

Any idea why this happens? “0,0,0” is not off or can you not compare strings that way?