I’ve been doing a bit more work on this and have the following code in my rule:
triggeringRoomGroup = [group for group in ir.getItem("gRoom").members if group.type == "Group" and ir.getItem(event.itemName) in group.members][0]
lightItem = map( printItem, [lightItem for lightItem in ir.getItem(str("gLighting")).members if lightItem.type != "Group"])
with the function printItem being:
def printItem(item):
dev_lighting_preset_selection.log.info("blah blah blah ({})". format(item))
This results in the following in the log:
2019-08-13 20:48:48.758 [INFO ] [mple Channel event rule (decorators)] - gLightingPresetSetting received update
2019-08-13 20:48:48.759 [INFO ] [mple Channel event rule (decorators)] - blah blah blah (KitchenRGBWLight1_Dimmer (Type=DimmerItem, State=0, Label=Dimmer, Category=DimmableLight, Groups=[gKitchen, gLighting]))
2019-08-13 20:48:48.760 [INFO ] [mple Channel event rule (decorators)] - blah blah blah (DimmerKitchenCeilingRing_Dimmer (Type=DimmerItem, State=0, Label=Dimmer Switch 1, Category=DimmableLight, Groups=[gKitchen, gLighting]))
2019-08-13 20:48:48.760 [INFO ] [mple Channel event rule (decorators)] - blah blah blah (BulbDimmableWhiteTemp4_Brightness (Type=DimmerItem, State=0, Label=Brightness, Category=DimmableLight, Groups=[gTopLanding, gLighting]))
2019-08-13 20:48:48.760 [INFO ] [mple Channel event rule (decorators)] - blah blah blah (BulbDimmableWhiteTemp2_Brightness (Type=DimmerItem, State=100, Label=Brightness, Category=DimmableLight, Groups=[gLauriesRoom, gLighting])
)
2019-08-13 20:48:48.761 [INFO ] [mple Channel event rule (decorators)] - blah blah blah (SwitchSocket5_Switch (Type=SwitchItem, State=OFF, Label=Switch, Category=Switch, Groups=[gJulessRoom, gLighting]))
2019-08-13 20:48:48.761 [INFO ] [mple Channel event rule (decorators)] - blah blah blah (DimmerKitchenCupboards_Dimmer (Type=DimmerItem, State=0, Label=Dimmer Switch 1, Category=DimmableLight, Groups=[gKitchen, gLighting]))
2019-08-13 20:48:48.761 [INFO ] [mple Channel event rule (decorators)] - blah blah blah (SwitchSocket4_Switch (Type=SwitchItem, State=OFF, Label=Switch, Category=Switch, Groups=[gFrontroom, gLighting]))
2019-08-13 20:48:48.762 [INFO ] [mple Channel event rule (decorators)] - blah blah blah (LightCeilingBlueroomDimmer_Dimmer (Type=DimmerItem, State=100, Label=Dimmer, Category=DimmableLight, Groups=[gBlueRoom, gLighting]))
2019-08-13 20:48:48.762 [INFO ] [mple Channel event rule (decorators)] - blah blah blah (DimmerBathroomCeilingLights_Dimmer (Type=DimmerItem, State=0, Label=Dimmer, Category=DimmableLight, Groups=[gBathroom, gLighting]))
2019-08-13 20:48:48.762 [INFO ] [mple Channel event rule (decorators)] - blah blah blah (SwitchSocket3_Switch (Type=SwitchItem, State=OFF, Label=Switch, Category=Switch, Groups=[gKitchen, gLighting]))
2019-08-13 20:48:48.763 [INFO ] [mple Channel event rule (decorators)] - blah blah blah (DimmerMiddleLandingCeiling_Dimmer (Type=DimmerItem, State=0, Label=Dimmer 1, Category=DimmableLight, Groups=[gMiddleLanding, gLighting]))
2019-08-13 20:48:48.763 [INFO ] [mple Channel event rule (decorators)] - blah blah blah (SwitchSocket6_Switch (Type=SwitchItem, State=OFF, Label=Switch, Category=Switch, Groups=[gBlueRoom, gLighting]))
2019-08-13 20:48:48.764 [INFO ] [mple Channel event rule (decorators)] - blah blah blah (LaurieDoorLight_Brightness (Type=DimmerItem, State=100, Label=Brightness, Category=DimmableLight, Groups=[gLauriesRoom, gLighting]))
One of the attributes of lightItem is the groups it’s in. Awesome! I then tried to incorporate a check on the lightItem.Groups list:
lightItem = map( printItem, [lightItem for lightItem in ir.getItem(str("gLighting")).members if lightItem.type != "Group" and triggeringRoomGroup.name in lightItem.Groups])
But that results in the following error in the log:
2019-08-13 20:51:59.445 [ERROR] [mple Channel event rule (decorators)] - Traceback (most recent call last):
File "/etc/openhab2/automation/lib/python/core/log.py", line 43, in wrapper
return fn(*args, **kwargs)
File "<script>", line 13, in dev_lighting_preset_selection
AttributeError: 'org.eclipse.smarthome.core.library.items.DimmerIte' object has no attribute 'Groups'
2019-08-13 20:51:59.445 [ERROR] [omation.core.internal.RuleEngineImpl] - Failed to execute rule '59b4c1ab-373b-4863-a5fa-bbda6b491ace': Fail to execute action: 1
There’s no attribute called Groups? But I just saw it in the log earlier. Any ideas what I’m missing?