Loop through all members in a group with OH2

I am trying to loop through all members of a group in OH2, this used to work in OH1

var hsb  = HSBType::fromRGB(240, 100, 100)
Group_DMX.members.forEach[s | s.sendCommand(hsb)]

what is the correct syntax in the smart home designer?

also how do I check the HSB status?

Group_Light.members.filter( s | s.state != "0,0,0").forEach [ item | 
			item.sendCommand(hsbValue)
		]
1 Like

More debugging, it seems like the rule does not run for some reason:

22:16:26.814 [INFO ] [smarthome.event.ItemCommandEvent ] - Item ā€˜Scene_LivingRoom2ā€™ received command 3
22:16:26.910 [INFO ] [marthome.event.ItemStateChangedEvent] - Scene_LivingRoom2 changed from 4 to 3

Because no infor is written to the karaf console:

@rich I also tried to cast the hsbValue to string to a new variable called hsb without succsess:

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


rule "Change Scene 2 in Living Room"
when
	Item Scene_LivingRoom2 received command
then
	Group_Light.members.forEach [s | logInfo("Debug", s.name + " equals " + s.state.toString)]
	val hsb = hsbValue.toString
	//logInfo("Debug", "hsbValue equals change group " + hsbValue.toString)
	
	//Group_Light.members.forEach [s | logInfo("Debug", s.name + " equals " + s.state.toString)]
	//Group_Light.members.forEach[s | s.sendCommand(OFF)]
	/*
	if (receivedCommand==1) {
			Group_Tv.members.forEach [ item | 
				sendCommand(item,hsbValue)
			]
	}

	if (receivedCommand==2) {
		Group_Dinner.members.forEach [ item | 
			item.sendCommand(hsbValue)
		]
	}
*/
	//Switch on just bar
	if (receivedCommand==3) {
		/* 
		Group_DMX_LivingRoom.members.filter( s | s.state.toString != "0,0,0").forEach [ item | 
			item.sendCommand(HSBType::fromRGB(0, 0, 0))
		]
		
		*/
		Group_DMX_LivingRoom.members.forEach [ item | 
			//item.sendCommand(hsb)
			logInfo("Info", "Turning off " + item.name) 
		]	
		
		Group_DMX_Bar.members.forEach [ item | 
			//item.sendCommand(hsb)
			logInfo("Info", "Turning on " + item.name)
		]	
	}

	//Switch OFF
	if (receivedCommand==4) {
		Group_DMX_LivingRoom.members.filter( s | s.state != "0,0,0").forEach [ item | 
			//item.sendCommand(HSBType::fromRGB(0, 0, 0))
		]
	}
	
	
end

Make the first line of the rule be a logInfo to verify whether the rule is triggering or not.

The syntax for looping through a Groupā€™s members is the same.

Iā€™ve no experience with HSB types so canā€™t comment on the best way to do that part. The toString stuff should be OK, but I would add some additional logging statements to verify that the states are what you think they are in the filters and such.

I think its just my RPI 2 that is too slow, after 20 min or so the debug message came, maybe my sd card is to slow.

23:26:37.265 [WARN ] [ore.internal.events.OSGiEventManager] - Dispatching event to subscriber 'org.eclipse.smarthome.model.rule.runtime.internal.engine.RuleEngineImpl@91244a' takes more than 5000ms.

I also got this error:

23:43:03.077 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'Change the color in Living Room': Script interpreter couldn't be obtain

But it seems like this would be the right rule:

Group_DMX.members.filter[s| s.state.toString != "0.0,0.0,0.0"].forEach[s | s.sendCommand(hsbValue)]

Though I do not like to compare stingsā€¦

Its the weirdest ouput of this loginfo script

Group_DMX.members.filter[s| s.state.toString != "0.0,0.0,0.0"].forEach[s | 
			logInfo("Info", "State of the thing:"+s.name)
			s.sendCommand(hsbValue)
		]
		Group_DMX.members.filter[s| s.state.toString == "0.0,0.0,0.0"].forEach[s | 
			logInfo("Info", "its off:" +s.name)
		]
		//Group_DMX.members.forEach[s | s.sendCommand(hsbValue)]
        //Group_DMX.members.forEach[s | s.sendCommand("100,100,100")]    
end

23:50:11.862 [INFO ] [.eclipse.smarthome.model.script.Info] - Set RGB value Living Room
23:50:13.870 [INFO ] [.eclipse.smarthome.model.script.Info] - its off:LMB2
23:50:13.981 [INFO ] [.eclipse.smarthome.model.script.Info] - its off:LMB3
23:50:14.136 [INFO ] [.eclipse.smarthome.model.script.Info] - its off:LMB4
23:50:14.295 [INFO ] [.eclipse.smarthome.model.script.Info] - its off:LMB5
23:50:14.512 [INFO ] [.eclipse.smarthome.model.script.Info] - its off:LMB6
23:50:14.640 [INFO ] [.eclipse.smarthome.model.script.Info] - its off:LMB7
23:50:14.766 [INFO ] [.eclipse.smarthome.model.script.Info] - its off:LMB8
23:50:14.878 [INFO ] [.eclipse.smarthome.model.script.Info] - its off:LMB9

of my items that are commented out, LB6 does not show up the commented out doesā€¦

Color LB6 "LB6"(Group_DMX,Group_DMX_LivingRoom,Group_DMX_Bar) {dmx="CHANNEL[82,83,84:1000]"}



Color LMB1 "LMB1"(Group_DMX,Group_DMX_MasterBedroom) {dmx="CHANNEL[110,111,112:1000]"}

/*Color LMB2 "LMB2"(Group_DMX,Group_DMX_MasterBedroom) {dmx="CHANNEL[110,111,112:1000]"}
Color LMB3 "LMB3"(Group_DMX,Group_DMX_MasterBedroom) {dmx="CHANNEL[110,111,112:1000]"}
Color LMB4 "LMB4"(Group_DMX,Group_DMX_MasterBedroom) {dmx="CHANNEL[110,111,112:1000]"}
Color LMB5 "LMB5"(Group_DMX,Group_DMX_MasterBedroom) {dmx="CHANNEL[110,111,112:1000]"}
Color LMB6 "LMB6"(Group_DMX,Group_DMX_MasterBedroom) {dmx="CHANNEL[110,111,112:1000]"}
Color LMB7 "LMB7"(Group_DMX,Group_DMX_MasterBedroom) {dmx="CHANNEL[110,111,112:1000]"}
Color LMB8 "LMB8"(Group_DMX,Group_DMX_MasterBedroom) {dmx="CHANNEL[110,111,112:1000]"}
Color LMB9 "LMB9"(Group_DMX,Group_DMX_MasterBedroom) {dmx="CHANNEL[110,111,112:1000]"}
*/

When you delete Items in OH2 text files, they donā€™t get deleted from the runtime config. Catches everyone out.

So is this safe todo? smarthome:items clear in karaf console, or will I loose all my items or will it just clear the cache, and reload them from the text file? DO i need to restart openhab? sudo systemtcl opanhab2 restart?

Not an OH2 user, I donā€™t know.
Might help -

Thanks, I am a bit afraid that this will delete some of items/setupā€¦

So here is my setupā€¦

I have 36 rgb lights in my living room, I have 8 scenes(ALL OFF, ALL ON,FIREPLACE,DINNER,READING,TV,BAR,PARTY)

Then I have 4 Modes(Warm WHITE, WHITE,LOUNGE,NIGHT), Then I have a dimmer to set brightness, and a color wheel to change colors.

So my main rule is when color item get a change it goes through all my leds, check if they are not off item.state.toString!=ā€œ0.0,0.0,0.0ā€)

If they are not off then it take the global value hsbValue*dimmerValue then send that value to the item

My Mode simply set lampColor.sendCommand(hsbValueWharmWhite) and so on.

The scenes send which item to be off and on, here my idea was to use group for each scene in the item definations, and send item.sendCommand(hsbValueOff) to all items in DMX_Group which are not member of the scene group(DMX_BAR) and also set dimmer value, then lampColor.postUpdate(hsbValue) to excute the changes

But now since I can not get groups to work, I need to write 36 if senteces , an 200+ sendcommands :frowning:

Iā€™ve found that when modifying Group meberships, in particular removing Items from a Group, a restart of OH will clear out the removed Items from the Group.

This has caught me several times but a reboot works every time.

thanks, I did this in the meantime

import org.eclipse.smarthome.core.library.types.HSBType

var HSBType hsbValue
var int redValue
var int greenValue
var int blueValue
var String RGBvalues

rule "Activate Scene 1"
when
	Item Scene_LivingRoom1 received command 
then

	var hsbOff = HSBType::fromRGB(0, 0, 0)
	//Switch on TV
	if (receivedCommand==1) {	
		LL1.sendCommand(hsbValue)
		LL2.sendCommand(hsbValue)
		LL3.sendCommand(hsbValue)
		LL4.sendCommand(hsbValue)
		LL5.sendCommand(hsbOff)
		LL6.sendCommand(hsbOff)
		LL7.sendCommand(hsbOff)
		LL8.sendCommand(hsbOff)
		LL9.sendCommand(hsbOff)
		LL10.sendCommand(hsbOff)
		LL11.sendCommand(hsbOff)
		LL12.sendCommand(hsbOff)
		LL13.sendCommand(hsbOff)
		LL14.sendCommand(hsbOff)
		LL15.sendCommand(hsbOff)
		LL16.sendCommand(hsbOff)
		LL17.sendCommand(hsbOff)
		LL18.sendCommand(hsbOff)
		LL19.sendCommand(hsbOff)
		LL20.sendCommand(hsbOff)
		LL21.sendCommand(hsbOff)
		LL22.sendCommand(hsbOff)
		LL23.sendCommand(hsbOff)
		LL24.sendCommand(hsbOff)
		LL25.sendCommand(hsbOff)
		LL26.sendCommand(hsbOff)
		LL27.sendCommand(hsbOff)
		LL28.sendCommand(hsbOff)
		LL29.sendCommand(hsbOff)
		LL30.sendCommand(hsbOff)
		
		LB1.sendCommand(hsbOff)
		LB2.sendCommand(hsbOff)
		LB3.sendCommand(hsbOff)
		LB4.sendCommand(hsbOff)
		LB5.sendCommand(hsbOff)
		LB6.sendCommand(hsbOff)
		sendCommand(Light_Hallway, OFF)
		sendCommand(Light_Kitchen,OFF)
		
	}
	
	//Switch on Dinner
	if (receivedCommand==2) {	
		var hsbOff = HSBType::fromRGB(0, 0, 0)
		LL1.sendCommand(hsbOff)
		LL2.sendCommand(hsbOff)
		LL3.sendCommand(hsbOff)
		LL4.sendCommand(hsbOff)
		LL5.sendCommand(hsbOff)
		LL6.sendCommand(hsbOff)
		LL7.sendCommand(hsbOff)
		LL8.sendCommand(hsbValue)
		LL9.sendCommand(hsbValue)
		LL10.sendCommand(hsbValue)
		LL11.sendCommand(hsbValue)
		LL12.sendCommand(hsbValue)
		LL13.sendCommand(hsbValue)
		LL14.sendCommand(hsbOff)
		LL15.sendCommand(hsbOff)
		LL16.sendCommand(hsbOff)
		LL17.sendCommand(hsbOff)
		LL18.sendCommand(hsbOff)
		LL19.sendCommand(hsbOff)
		LL20.sendCommand(hsbOff)
		LL21.sendCommand(hsbOff)
		LL22.sendCommand(hsbOff)
		LL23.sendCommand(hsbOff)
		LL24.sendCommand(hsbOff)
		LL25.sendCommand(hsbOff)
		LL26.sendCommand(hsbOff)
		LL27.sendCommand(hsbOff)
		LL28.sendCommand(hsbOff)
		LL29.sendCommand(hsbOff)
		LL30.sendCommand(hsbOff)
		
		LB1.sendCommand(hsbOff)
		LB2.sendCommand(hsbOff)
		LB3.sendCommand(hsbOff)
		LB4.sendCommand(hsbOff)
		LB5.sendCommand(hsbOff)
		LB6.sendCommand(hsbOff)
		sendCommand(Light_Hallway, OFF)
		sendCommand(Light_Kitchen,ON)
		
	}
	
	//Switch on Reading
	if (receivedCommand==1) {	
		sendCommand(Light_Hallway, OFF)
		sendCommand(Light_Kitchen,OFF)
		
		LL1.sendCommand(hsbOff)
		LL2.sendCommand(hsbOff)
		LL3.sendCommand(hsbOff)
		LL4.sendCommand(hsbOff)
		LL5.sendCommand(hsbOff)
		LL6.sendCommand(hsbOff)
		LL7.sendCommand(hsbOff)
		LL8.sendCommand(hsbOff)
		LL9.sendCommand(hsbOff)
		LL10.sendCommand(hsbOff)
		LL11.sendCommand(hsbOff)
		LL12.sendCommand(hsbOff)
		LL13.sendCommand(hsbOff)
		LL14.sendCommand(hsbOff)
		LL15.sendCommand(hsbOff)
		LL16.sendCommand(hsbOff)
		LL17.sendCommand(hsbValue)
		LL18.sendCommand(hsbOff)
		LL19.sendCommand(hsbValue)
		LL20.sendCommand(hsbOff)
		LL21.sendCommand(hsbOff)
		LL22.sendCommand(hsbValue)
		LL23.sendCommand(hsbOff)
		LL24.sendCommand(hsbValue)
		LL25.sendCommand(hsbOff)
		LL26.sendCommand(hsbOff)
		LL27.sendCommand(hsbValue)
		LL28.sendCommand(hsbOff)
		LL29.sendCommand(hsbValue)
		LL30.sendCommand(hsbOff)
		
		LB1.sendCommand(hsbOff)
		LB2.sendCommand(hsbOff)
		LB3.sendCommand(hsbOff)
		LB4.sendCommand(hsbOff)
		LB5.sendCommand(hsbOff)
		LB6.sendCommand(hsbOff)
		sendCommand(Light_Hallway, OFF)
		sendCommand(Light_Kitchen,ON)
	}
	
	
	
	//Switch off
	if (receivedCommand==4) {	
		sendCommand(Light_Hallway, OFF)
		sendCommand(Light_Kitchen,OFF)
		sendCommand(Light_Bathroom,OFF)
	sendCommand(Light_Balcony,OFF)
		sendCommand(Light_MasterBedroom,OFF)
		
		LL1.sendCommand(hsbOff)
		LL2.sendCommand(hsbOff)
		LL3.sendCommand(hsbOff)
		LL4.sendCommand(hsbOff)
		LL5.sendCommand(hsbOff)
		LL6.sendCommand(hsbOff)
		LL7.sendCommand(hsbOff)
		LL8.sendCommand(hsbOff)
		LL9.sendCommand(hsbOff)
		LL10.sendCommand(hsbOff)
		LL11.sendCommand(hsbOff)
		LL12.sendCommand(hsbOff)
		LL13.sendCommand(hsbOff)
		LL14.sendCommand(hsbOff)
		LL15.sendCommand(hsbOff)
		LL16.sendCommand(hsbOff)
		LL17.sendCommand(hsbOff)
		LL18.sendCommand(hsbOff)
		LL19.sendCommand(hsbOff)
		LL20.sendCommand(hsbOff)
		LL21.sendCommand(hsbOff)
		LL22.sendCommand(hsbOff)
		LL23.sendCommand(hsbOff)
		LL24.sendCommand(hsbOff)
		LL25.sendCommand(hsbOff)
		LL26.sendCommand(hsbOff)
		LL27.sendCommand(hsbOff)
		LL28.sendCommand(hsbOff)
		LL29.sendCommand(hsbOff)
		LL30.sendCommand(hsbOff)
		
		LB1.sendCommand(hsbOff)
		LB2.sendCommand(hsbOff)
		LB3.sendCommand(hsbOff)
		LB4.sendCommand(hsbOff)
		LB5.sendCommand(hsbOff)
		LB6.sendCommand(hsbOff)
		
	}

	
		
end










 
rule "Set RGB value Living Room"
when
        Item Color_LivingRoom changed
then
logInfo("Info", "Set RGB value Living Room")
hsbValue = Color_LivingRoom.state as HSBType
	
	//LL8.sendCommand(lampColor)
	
//if((moodSelector.state as DecimalType) != 1 || (moodSelector.state as DecimalType) != 2){
		//Group_Light.members.filter[s|s instanceof SwitchType].forEach[s | s.sendCommand(OFF)
	//}
		if (LL1.state.toString !="0.0,0.0,0.0") {
			LL1.sendCommand(hsbValue)
		}
		if (LL2.state.toString !="0.0,0.0,0.0") {
			LL2.sendCommand(hsbValue)
		}
		if (LL3.state.toString !="0.0,0.0,0.0") {
			LL3.sendCommand(hsbValue)
		}
		if (LL4.state.toString !="0.0,0.0,0.0") {
			LL4.sendCommand(hsbValue)
		}
		if (LL5.state.toString !="0.0,0.0,0.0") {
			LL5.sendCommand(hsbValue)
		}
		if (LL6.state.toString !="0.0,0.0,0.0") {
			LL6.sendCommand(hsbValue)
		}
		if (LL7.state.toString !="0.0,0.0,0.0") {
			LL7.sendCommand(hsbValue)
		}
		if (LL8.state.toString !="0.0,0.0,0.0") {
			LL8.sendCommand(hsbValue)
		}
		if (LL9.state.toString !="0.0,0.0,0.0") {
			LL9.sendCommand(hsbValue)
		}
		if (LL10.state.toString !="0.0,0.0,0.0") {
			LL10.sendCommand(hsbValue)
		}
		if (LL11.state.toString !="0.0,0.0,0.0") {
			LL11.sendCommand(hsbValue)
		}
		if (LL12.state.toString !="0.0,0.0,0.0") {
			LL12.sendCommand(hsbValue)
		}
		if (LL13.state.toString !="0.0,0.0,0.0") {
			LL13.sendCommand(hsbValue)
		}
		if (LL14.state.toString !="0.0,0.0,0.0") {
			LL14.sendCommand(hsbValue)
		}
		if (LL15.state.toString !="0.0,0.0,0.0") {
			LL15.sendCommand(hsbValue)
		}
		if (LL16.state.toString !="0.0,0.0,0.0") {
			LL16.sendCommand(hsbValue)
		}
		if (LL17.state.toString !="0.0,0.0,0.0") {
			LL17.sendCommand(hsbValue)
		}
		if (LL18.state.toString !="0.0,0.0,0.0") {
			LL18.sendCommand(hsbValue)
		}
		if (LL19.state.toString !="0.0,0.0,0.0") {
			LL19.sendCommand(hsbValue)
		}
		if (LL20.state.toString !="0.0,0.0,0.0") {
			LL20.sendCommand(hsbValue)
		}
		if (LL21.state.toString !="0.0,0.0,0.0") {
			LL21.sendCommand(hsbValue)
		}
		if (LL22.state.toString !="0.0,0.0,0.0") {
			LL22.sendCommand(hsbValue)
		}
		if (LL23.state.toString !="0.0,0.0,0.0") {
			LL23.sendCommand(hsbValue)
		}
		if (LL24.state.toString !="0.0,0.0,0.0") {
			LL24.sendCommand(hsbValue)
		}
		if (LL25.state.toString !="0.0,0.0,0.0") {
			LL25.sendCommand(hsbValue)
		}
		if (LL26.state.toString !="0.0,0.0,0.0") {
			LL26.sendCommand(hsbValue)
		}
		if (LL27.state.toString !="0.0,0.0,0.0") {
			LL27.sendCommand(hsbValue)
		}
		if (LL28.state.toString !="0.0,0.0,0.0") {
			LL28.sendCommand(hsbValue)
		}
		if (LL29.state.toString !="0.0,0.0,0.0") {
			LL29.sendCommand(hsbValue)
		}
		if (LL30.state.toString !="0.0,0.0,0.0") {
			LL30.sendCommand(hsbValue)
		}
		
		
		if (LB1.state.toString !="0.0,0.0,0.0") {
			LB1.sendCommand(hsbValue)
		}
		if (LB2.state.toString !="0.0,0.0,0.0") {
			LB2.sendCommand(hsbValue)
		}
		if (LB3.state.toString !="0.0,0.0,0.0") {
			LB3.sendCommand(hsbValue)
		}
		if (LB4.state.toString !="0.0,0.0,0.0") {
			LB4.sendCommand(hsbValue)
		}
		if (LB5.state.toString !="0.0,0.0,0.0") {
			LB5.sendCommand(hsbValue)
		}
		if (LB6.state.toString !="0.0,0.0,0.0") {
			LB6.sendCommand(hsbValue)
		}
		
		/* 
		Group_DMX.members.filter[s| s.state.toString != "0.0,0.0,0.0"].forEach[s | 
			logInfo("Info", "State of the thing:"+s.name)
			s.sendCommand(hsbValue)
		]
		
		*/
		Group_DMX_LivingRoom.members.filter[s| s.state.toString == "0.0,0.0,0.0"].forEach[s | 
			logInfo("Info", "its off:" +s.name)
		]
		//Group_DMX.members.forEach[s | s.sendCommand(hsbValue)]
    //Group_DMX.members.forEach[s | s.sendCommand("100,100,100")]    
end



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

rule "Change Scene 2 in Living Room"
when
	Item Scene_LivingRoom2 received command
then
	var hsbOff = HSBType::fromRGB(0, 0, 0)

	//Switch on fireplace Mode
	if (receivedCommand==1) {
		sendCommand(Light_Hallway, OFF)
		sendCommand(Light_Kitchen,OFF)
		
		LL1.sendCommand(hsbOff)
		LL2.sendCommand(hsbOff)
		LL3.sendCommand(hsbOff)
		LL4.sendCommand(hsbOff)
		LL5.sendCommand(hsbOff)
		LL6.sendCommand(hsbOff)
		LL7.sendCommand(hsbOff)
		LL8.sendCommand(hsbOff)
		LL9.sendCommand(hsbOff)
		LL10.sendCommand(hsbOff)
		LL11.sendCommand(hsbOff)
		LL12.sendCommand(hsbOff)
		LL13.sendCommand(hsbOff)
		LL14.sendCommand(hsbOff)
		LL15.sendCommand(hsbOff)
		LL16.sendCommand(hsbOff)
		LL17.sendCommand(hsbOff)
		LL18.sendCommand(hsbOff)
		LL19.sendCommand(hsbOff)
		LL20.sendCommand(hsbOff)
		LL21.sendCommand(hsbOff)
		LL22.sendCommand(hsbOff)
		LL23.sendCommand(hsbOff)
		LL24.sendCommand(hsbValue)
		LL25.sendCommand(hsbValue)
		LL26.sendCommand(hsbOff)
		LL27.sendCommand(hsbValue)
		LL28.sendCommand(hsbOff)
		LL29.sendCommand(hsbOff)
		LL30.sendCommand(hsbOff)
		
		LB1.sendCommand(hsbOff)
		LB2.sendCommand(hsbOff)
		LB3.sendCommand(hsbOff)
		LB4.sendCommand(hsbOff)
		LB5.sendCommand(hsbOff)
		LB6.sendCommand(hsbOff)
			
		
	}
	//Switch on bar Mode
	if (receivedCommand==2) {
		sendCommand(Light_Hallway, OFF)
		sendCommand(Light_Kitchen,OFF)
		LL1.sendCommand(hsbOff)
		LL2.sendCommand(hsbOff)
		LL3.sendCommand(hsbOff)
		LL4.sendCommand(hsbOff)
		LL5.sendCommand(hsbOff)
		LL6.sendCommand(hsbOff)
		LL7.sendCommand(hsbOff)
		LL8.sendCommand(hsbOff)
		LL9.sendCommand(hsbOff)
		LL10.sendCommand(hsbOff)
		LL11.sendCommand(hsbOff)
		LL12.sendCommand(hsbOff)
		LL13.sendCommand(hsbOff)
		LL14.sendCommand(hsbOff)
		LL15.sendCommand(hsbOff)
		LL16.sendCommand(hsbOff)
		LL17.sendCommand(hsbOff)
		LL18.sendCommand(hsbOff)
		LL19.sendCommand(hsbOff)
		LL20.sendCommand(hsbOff)
		LL21.sendCommand(hsbOff)
		LL22.sendCommand(hsbOff)
		LL23.sendCommand(hsbOff)
		LL24.sendCommand(hsbOff)
		LL25.sendCommand(hsbOff)
		LL26.sendCommand(hsbOff)
		LL27.sendCommand(hsbOff)
		LL28.sendCommand(hsbOff)
		LL29.sendCommand(hsbOff)
		LL30.sendCommand(hsbOff)
		
		LB1.sendCommand(hsbValue)
		LB2.sendCommand(hsbValue)
		LB3.sendCommand(hsbValue)
		LB4.sendCommand(hsbValue)
		LB5.sendCommand(hsbValue)
		LB6.sendCommand(hsbValue)
			
		
	}

	//Switch on party Mode
	if (receivedCommand==3) {
		LL1.sendCommand(hsbOff)
		LL2.sendCommand(hsbOff)
		LL3.sendCommand(hsbOff)
		LL4.sendCommand(hsbOff)
		LL5.sendCommand(hsbOff)
		LL6.sendCommand(hsbOff)
		LL7.sendCommand(hsbOff)
		LL8.sendCommand(hsbOff)
		LL9.sendCommand(hsbOff)
		LL10.sendCommand(hsbOff)
		LL11.sendCommand(hsbOff)
		LL12.sendCommand(hsbOff)
		LL13.sendCommand(hsbOff)
		LL14.sendCommand(hsbOff)
		LL15.sendCommand(hsbOff)
		LL16.sendCommand(hsbOff)
		LL17.sendCommand(hsbOff)
		LL18.sendCommand(hsbOff)
		LL19.sendCommand(hsbOff)
		LL20.sendCommand(hsbOff)
		LL21.sendCommand(hsbOff)
		LL22.sendCommand(hsbOff)
		LL23.sendCommand(hsbOff)
		LL24.sendCommand(hsbOff)
		LL25.sendCommand(hsbOff)
		LL26.sendCommand(hsbOff)
		LL27.sendCommand(hsbOff)
		LL28.sendCommand(hsbOff)
		LL29.sendCommand(hsbOff)
		LL30.sendCommand(hsbOff)
		
		LB1.sendCommand(hsbValue)
		LB2.sendCommand(hsbValue)
		LB3.sendCommand(hsbValue)
		LB4.sendCommand(hsbValue)
		LB5.sendCommand(hsbValue)
		LB6.sendCommand(hsbValue)
			
		
	}
	//Switch ON
	if (receivedCommand==4) {
		sendCommand(Light_Hallway, ON)
		sendCommand(Light_Kitchen,ON)
		
		LL1.sendCommand(hsbValue)
		LL2.sendCommand(hsbValue)
		LL3.sendCommand(hsbValue)
		LL4.sendCommand(hsbValue)
		LL5.sendCommand(hsbValue)
		LL6.sendCommand(hsbValue)
		LL7.sendCommand(hsbValue)
		LL8.sendCommand(hsbValue)
		LL9.sendCommand(hsbValue)
		LL10.sendCommand(hsbValue)
		LL11.sendCommand(hsbValue)
		LL12.sendCommand(hsbValue)
		LL13.sendCommand(hsbValue)
		LL14.sendCommand(hsbValue)
		LL15.sendCommand(hsbValue)
		LL16.sendCommand(hsbValue)
		LL17.sendCommand(hsbValue)
		LL18.sendCommand(hsbValue)
		LL19.sendCommand(hsbValue)
		LL20.sendCommand(hsbValue)
		LL21.sendCommand(hsbValue)
		LL22.sendCommand(hsbValue)
		LL23.sendCommand(hsbValue)
		LL24.sendCommand(hsbValue)
		LL25.sendCommand(hsbValue)
		LL26.sendCommand(hsbValue)
		LL27.sendCommand(hsbValue)
		LL28.sendCommand(hsbValue)
		LL29.sendCommand(hsbValue)
		LL30.sendCommand(hsbValue)
		
		LB1.sendCommand(hsbValue)
		LB2.sendCommand(hsbValue)
		LB3.sendCommand(hsbValue)
		LB4.sendCommand(hsbValue)
		LB5.sendCommand(hsbValue)
		LB6.sendCommand(hsbValue)
		
	}
	

end



	


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////// Change the moodings of light, e.g. warm white, white, lounge and night ////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
rule "Change the color in Living Room"
when
	Item MoodSelector_LivingRoom received command
then
	
	//warm white
	if (receivedCommand==1) {
		hsbValue   = HSBType::fromRGB(255, 0, 0)
		Color_LivingRoom.sendCommand(hsbValue)		
	}
//white
	if (receivedCommand==2) {
		hsbValue   = HSBType::fromRGB(0, 255, 0)
		Color_LivingRoom.sendCommand(hsbValue)
	}
	//lounge
	if (receivedCommand==3) {
		hsbValue   = HSBType::fromRGB(0, 0, 255)
		Color_LivingRoom.sendCommand(hsbValue)	
	}
	//night
	if (receivedCommand==4) {
		hsbValue   = HSBType::fromRGB(255, 255, 255)
		Color_LivingRoom.sendCommand(hsbValue)
	}
	
end

@rlkoshak You saved my rule file for becoming tremendously large

Final question how can I loop through a group and do sth like this as smoothly as possible, turn on every light in a group if its not already ON, rest off

val hsbOn = HSBType::fromRGB(125, 125, 125)
    val hsbOff = HSBType::fromRGB(0, 0, 0)

Group_DMX_LivingRoom.members.forEach[item | 
            if item.memberOf(Group_DMX_Bar){
           
	        logInfo("Info", "ON of the thing:"+item.name)
                    if(item.state.toString=="0.0,0.0,0.0"){
	             item.sendCommand(hsbOn)
                   }
           else{
                  item.sendCommand(hsbOff)
          }
]
1 Like

What you have is perfectly fine. I would probably rewrite what you have above as:

val hsbOn  = HSBType::fromRGB(125, 125, 125)
val hsbOFF = HSBType:fromRGB(0, 0, 0)

val barLights = Group_DMX_LivingRoom.members.filter[l | l.memberOf(Group_DMX_Bar)]
barLights.members.filter[l|l.state.toString == "0.0,0.0,0.0"].forEach[l| l.sendCommand(hsbOn) ]
barLights.members.filter[l|l.state.toString != "0.0,0.0,0.0"].forEach[l| l.sendCommand(hsbOff)]

Note: Iā€™m assuming that there are more Items that are members of Group_DMX_Bar than are members of both Group_DMX_Bar and Group_DMX_LibingRoom. If that isnā€™t the case, skip the first line and just use Group_DMX_Bar.members.

Also, I try to avoid variable names that are even close to reserved words (e.g. ā€œitemā€) which is why I switched to use ā€œlā€ for ā€œlightā€.

If you need hsbOn and hsbOff elsewhere consider making it a global val.

The log statement is lost above but you should be able to add it back in where you want it to go.

Sorry for late reply, was away for the weekend,

So living room group Group_DMX_LivingRoom has 36 downlights in it, the scene bar Group_DMX_Bar, which is a part of my living room has 6 lights in it were maybe a bad example, better would maybe be the group Group_DMX_Kitchen and Group_DMX_Cooking, where the Group_DMX_Cooking contains all the lights in Group_DMX_Kitchen plus 5 lights, So if I would like to change scene from Group_DMX_Kitchen to Group_DMX_Cooking I would like to just turn on those extra 5 lights instead of turning off all lights and so on all lights in Group_DMX_Cooking. When going from Group_DMX_Cooking to Group_DMX_Kitchen i switch off 5 lights.

So by adding a new scene i simply need to add lights to that group, that was my idea.I do have 5 normal lights in the living room (not rgb, simply switch), but I thought to add those manually to the desired scenes, since they are not RGB, (or could I also check type of an item, i.e switch/rgbvalue?)

Does this work, or did I miss something, because it seems like your rule does not switch of non members of the bar group in living room groupā€¦

//So all non bar lights in livingroom
val nonBarLights = Group_DMX_LivingRoom.members.filter[l |! l.memberOf(Group_DMX_Bar)]
nonBarLights .members.filter[l|l.state.toString != "0.0,0.0,0.0"].forEach[l| l.sendCommand(hsbOff)]

//Bar lights
val barLights = Group_DMX_LivingRoom.members.filter[l | l.memberOf(Group_DMX_Bar)]
barLights.members.filter[l|l.state.toString == "0.0,0.0,0.0"].forEach[l| l.sendCommand(hsbOn) ]

That is because based on your original rule you seemed to only want to control those lights that are part of both Groups.

But what you have seems correct.

The first line should give you all members of the lights in Group_DMX_LivingRoom that are not members of Group_DMX_Bar.

The second line sends OFF to all of those lights that are not already off.

The third line returns all of the Group_DMX_LivingRoom that are alos members of Group_DMX_Bar.

The fourth line turns ON any light in that list that is not already ON.

If you want to send hsbOn to ANY light in Group_DMX_Bar that isnā€™t on you need to drop line 3 and just filter an loop on Group_DMX_Bar.

Like this then, but can i make a function of it so i can avoid copy paste?:

rule "Activate Scene 1"
when
	Item Scene_LivingRoom1 received command 
then

	var hsbOff = HSBType::fromRGB(0, 0, 0)
	//Switch on TV
	if (receivedCommand==1) {	

             rgbLightFunction("Group_DMX_TV")
       }
   end

Then my function that takes in a string, or can I pass group object somehow?

   rgbLightFunction(group as String){  
    //So all non  scene group lights in livingroom get switched off if they not already are off
    val nonSceneLights = Group_DMX_LivingRoom.members.filter[l |! l.memberOf(Group(group))]
    nonSceneLights.members.filter[l|l.state.toString != "0.0,0.0,0.0"].forEach[l| l.sendCommand(hsbOff)]

    //Bar lights
    Group(group).members.[l|l.state.toString == "0.0,0.0,0.0"].forEach[l| l.sendCommand(hsbOn) ]

}

Look for my simple lambda example p wish justosting. You just need to pass on your two groups as arguments to the lambda.

I looked at you lamda example, but I can not figure out how to pass on a group to you lambda function:

val Functions$Function2 rgbLights= [ Group s, HSBType hsbValue |
	
    val hsbOff = HSBType::fromRGB(0, 0, 0)
    //So all non  scene group lights in livingroom get switched off if they not already are off
    val nonSceneLights = Group_DMX_LivingRoom.members.filter[l |! l.memberOf(s)]
    nonSceneLights.members.filter[l|l.state.toString != hsbOff.toString].forEach[l| l.sendCommand(hsbOff as Command)]

    //Group lights
    s.members.[l|l.state.toString == hsbOff.toString].forEach[l| l.sendCommand(hsbValue as Command) ]

]
val Functions$Function2 rgbLights = [GroupItem s, HSBType hsbValue|

Thanks Rich, I tried googling valid variable types for 10 minutes, but It seems not to be any documentation out there. Where do you find this information?

Now the problem is that groupiem does not have the method memberOf ā€¦ I tried s as Group and several other things, like using Group(s) where I sent s in as String instead of groupitem

Is there javadoc somewhere where I can find all available methods?

val Functions$Function2 rgbLights= [ GroupItem s, HSBType hsbValue |
	
    val hsbOff = HSBType::fromRGB(0, 0, 0)
    //So all non  scene group lights in livingroom get switched off if they not already are off
    val nonSceneLights = Group_DMX_LivingRoom.members.filter[l |! l.memberOf(s)]
    nonSceneLights.members.filter[l|l.state.toString != hsbOff.toString].forEach[l| l.sendCommand(hsbOff as Command)]

    //Group lights
    s.members.[l|l.state.toString == hsbOff.toString].forEach[l| l.sendCommand(hsbValue as Command) ]

]