Group Switches in .items file

Hello, so I have been building my openHAB setup and its great. However something is seeming to alude me at the moment. I’ve looked at the samples for greating a group switch. Works fine, create it within the items file and the example shows you putting it on the sitemap. My problem is this. Here is my site map top section.

Frame label=“Rooms”{
Group item=LivRoom label=“Living Room” icon=“sofa”
Group item=MasterBed label=“Master Bedroom” icon=“bedroom”
}

In the Living Room I have 2 bulbs. I’d like to create a switch that will allow me to turn off both of the bulbs within the living room but within the .items file just like how I have the other items setup. Is this not possible and if not does this mean I have to create new Frames for each room in the sitemap? Is this the recommended practice? Just wondering.

So here is the next problem that I would run into, if I place the items in my sitemap, the site map doesn’t allow me to dimmers. I have a dimmer for each light and was looking to possibly create a group dimmer as well. What is my best course of action here?

Than what is this considered?

This is in my items file
Group LivRoom_AllLights
Group:Switch:OR(On,OFF) LivRoom_AllLights_Sw "All Lights [{%d}] {LivRoom_AllLights

This is in my sitemap
Switch item=LivRoom_AllLights mappings=[OFF=“All Off”, ON=“All On”]

This works but when I do this I then can’t have all my items in the same frame. I get that I’d maybe have to make a Rule but why does this work and why can’t I do it within the items file?

That is what I was saying is that I know in the site map I can do it that way. However than I can’t have dimmers on the same page at that point. I want one page or Frame that when I click on Living Room top group at the top I want a switch to turn them all off and on and if possible a dimmer and then below have each individual Co tool. I have the individual control working I just want the group control as well.

Which leads me to believe that the only way I guess to accomplish this is a rule that handles all my living room lights. It’s just a different setup which I get I just was trynna understand why the behavior is the way it is.

If I’m putting it on the site map I can but I lose dimmer control thus it seems I’m forced to use a rule to control them all to set them within the items file so that I can keep the group switch individual switches and dimmer control of my living room

Hello Markus,

So this is what I’ve tried doing and I’m not getting expected behavior hopefully this is the last thing. In Sitemap I have the following now, the MasterBed currently is only one light so I haven’t updated yet or need to:

Frame label=“Rooms”{
Text label=“Living Room” icon=“sofa” {
Switch item=LivRoom_AllLights label=“Switch All” mappings=[OFF=“All Off”, ON=“All On”]
Slider item=LivRoom_AllLights_Dim label=“Dimmer All”
Switch item=Light_LivRoom_Steps_Sw
Slider item=Light_LivRoom_Steps_Dim
Switch item=Light_LivRoom_Candles_Sw
Slider item=Light_LivRoom_Candles_Dim
}
Group item=MasterBed label=“Master Bedroom” icon=“bedroom”
}

All On and All Off switches work now. I have this in my items file. I created a false dimmer per your suggestion above.

/* active groups */
Group LivRoom_AllLights
Group:Switch:OR(ON, OFF) LivRoom_AllLights_Sw (LivRoom_AllLights)

/* Lights */
Dimmer LivRoom_AllLights_Dim
Switch Light_LivRoom_Steps_Sw “Steps On/Off” (LivRoom, Lights, LivRoom_AllLights) {hue=“1”}
Dimmer Light_LivRoom_Steps_Dim “Steps Dimmer” (LivRoom, Lights, LivRoom_AllLights) {hue=“1;brightness;40”}
Switch Light_LivRoom_Candles_Sw “Candles On/Off” (LivRoom, Lights, LivRoom_AllLights) {hue=“2”}
Dimmer Light_LivRoom_Candles_Dim “Candles Dimmer” (LivRoom, Lights, LivRoom_AllLights) {hue=“2;brightness;40”}

Now this is the rule I created.
/**

  • This rule is to control all lights in living room on a dimmer
    */
    rule “Living Room Dimmer”
    when
    Item LivRoom_AllLights_Dim received command
    then
    var Number percent = 0
    if(LivRoom_AllLights_Dim.state instanceof DecimalType) percent = LivRoom_AllLights_Dim.state as DecimalType

     if(receivedCommand==INCREASE) percent = percent + 25
     if(receivedCommand==DECREASE) percent = percent - 25
    
     if(percent<0)   percent = 0
     if(percent>100) percent = 100
     
     sendCommand(Light_LivRoom_Steps_Dim, percent)
     sendCommand(Light_LivRoom_Candles_Dim, percent)
    

end

Which as you can see is basically copied version of the demo.rules with the sendCommand updated for my hue bulbs and the item updated to my virtual dimmer. However when I click the down arrow it completely dims the lights where there off and then if I press the up arrow I believe I’m maybe getting 25% and it will not go any higher. I can click down and it will go out again but I can’t not get it to go higher after the initial click. Am I missing something within any of the files? I appreciate the help and I have learned a lot.

So this is what I have figured out when it comes to the Hue Lux bulbs and I think possibly we need to add to the Wiki or something for ease of use or someone when they look around will find the information. The reason I was not getting any where going higher was due to the demo file saying percent and thinking 25 was going to give me 25% increments. THIS IS NOT THE CASE when setting brightness on a Hue Lux bulb. Again this might be something with these bulbs specifically but for 100% the value is 255. Here is my adjusted rule for anyone else wanting to accomplish this. I might start a blog and video serious on the stuff I find in here to help people.

/** This rule is to control all lights in living room on a dimmer */
rule “Living Room Dimmer”
when
Item Light_LivRoom_AllLights_Dim received command
then
var Number bVal = 0
if(Light_LivRoom_AllLights_Dim.state instanceof DecimalType) bVal = Light_LivRoom_AllLights_Dim.state as DecimalType

	if(receivedCommand==INCREASE) bVal = bVal + 25
	if(receivedCommand==DECREASE) bVal = bVal - 25

	if(bVal<0)   bVal = 0
	if(bVal>255) bVal = 255
	
	sendCommand(Light_LivRoom_Steps_Dim, bVal)
	sendCommand(Light_LivRoom_Candles_Dim, bVal)
	postUpdate(Light_LivRoom_Steps_Dim, bVal)
	postUpdate(Light_LivRoom_Candles_Dim, bVal)

end

Why does your rule use sendCommand and postUpdate for the same items?

Well I did it on accident at first trying to get the rule to work. At first I tried sending the sendCommand and it worked but was only getting the bulb to brighten a little bit. Tried postUpdate thinking I had to use this. Realized it didn’t work at all however when I was using the mobile app I noticed postUpdate was updating the other dimmers IMMEDIATELY and I didn’t have to wait for hue binding to update the status which I liked so I ended up keeping both of them in there. One thing though I noticed is when you first load the group my All On switch and Dimmer don’t automatically show if the lights are on or off. Hope this helps

Marcus,

I did not try the PercentType instead of Decimal type but I will when I get home but I’m willing to bet this is the issue. Thanks for pointing that out. Also yes, the best fix would be for a wonderful color hue bulb :slight_smile: I just don’t have the money right now LOL. Otherwise I’d have bought the 3 bulb color kit. I plan on adding a few color ones soon as my funds allow. Again thanks for pointing that out, the demo file being setup that way threw me off since it said percent but that was just the variable name but knowing the distinction between the 2 and that there is the 2 types will help in the future :slight_smile:

Hello,

i tried with Fibaro Dimmer 2, it shows Error like this:
[ERROR] [eController$ZWaveReceiveThread] - Protocol error (CAN), resending

my rule for dimmer:

rule "Bedroom Dimmer"
when
		Item bedroom_dimmer received command
then
		var Number bVal = 0
		if(bedroom_dimmer.state instanceof PercentType) bVal = bedroom_dimmer.state as PercentType 
			
		if(receivedCommand==INCREASE) bVal = bVal + 5	
		if(receivedCommand==DECREASE) bVal = bVal - 5
			
		if(bVal<0)  bVal = 0
		if(bVal>100) bVal = 100
		
		sendCommand(bedroom_dimmer, bVal)
		
		if(bVal>0) postUpdate(bedroom_light, ON)
		if(bVal==0) postUpdate(bedroom_light, OFF)
		
			
			
end

Do you have any ideas for this problem? for Turn on/off i had no problem with this.

Thanks