I’m using this as an example to get a light in a room location. I don’t have any subgroups in my location, so I didn’t use descendents (testing that caused an error - possibly because there are no subgroups?). The location and location members are printed, but the filter fails with the log message below. What am I doing wrong?
var location = actions.Semantics.getLocation(items[event.itemName]);
console.log("location of " + event.itemName + " is: " + location);
console.log("location.members of " + event.itemName + " is: " + location.members);
var lights = location.members.filter(i => i.tags.includes("Lightbulb"));
2024-12-24 17:09:01.115 [INFO ] [tion.script.ui.AutomaticRoomLighting] - location of CabinBathLaundryMotionSensor is: gLaundryBath (Type=GroupItem, Members=4, State=NULL, Label=Laundry Bath, Category=, Tags=[Location], Groups=[gIndoor])
2024-12-24 17:09:01.116 [INFO ] [tion.script.ui.AutomaticRoomLighting] - location.members of CabinBathLaundryMotionSensor is: [CabinBathLaundrySinkLight (Type=SwitchItem, State=OFF, Label=Cabin Bath Laundry Sink Light, Category=light, Tags=[Lightbulb], Groups=[gLaundryBath]), CabinBathLaundryMotionSensor (Type=SwitchItem, State=OFF, Label=Cabin Bath Laundry Motion Sensor, Category=Motion, Tags=[Point], Groups=[gLaundryBath]), CabinBathLaundryMotionSensorBatteryLevel (Type=NumberItem, State=86 %, Label=Cabin Bath Laundry Motion Sensor Battery Level, Category=Battery, Tags=[Level, Measurement], Groups=[gLaundryBath, gBatteryLevel]), CabinLaundryBathDoorSensor (Type=ContactItem, State=OPEN, Label=Cabin Laundry Bath Door Sensor, Category=door, Tags=[Door], Groups=[gLaundryBath])]
2024-12-24 17:09:01.118 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'AutomaticRoomLighting' failed: org.graalvm.polyglot.PolyglotException: TypeError: invokeMember (filter) on java.util.Collections$UnmodifiableSet@eab1d1f failed due to: Unknown identifier: filter
FYI, when I tried with the descendents, it says it is ‘undefined’:
console.log("location.members.descendents of " + event.itemName + " is: " + location.members.descendents);
2024-12-24 17:05:07.759 [INFO ] [tion.script.ui.AutomaticRoomLighting] - location.members.descendents of CabinBathLaundryMotionSensor is: undefined