Please test the new Expire Binding

Each room has a Group for the lights (e.g. Kitchen_Lights, Hall_Lights, etc). That Group gets put into a parent Group (RoomLights) so we can access it later. Each room has a Timer Item with Expire binding config (e.g. Kitchen_Timer, Hall_Timer, etc) and all the Timers go into a Group (RoomTimers). Each Sensor goes into another Group (RoomOccupancySensors).

All Items are named using Assocaited Items DP.

rule "Sensor detected occupancy in a room"
when
    Member of RoomOccupancySensors received update
then
    // schedule/reschedule the timer
    sendCommand(triggeringItem.name.split("_").get(0) + "_Timer" , "ON") 
end

rule "A room is no longer occupied"
when
    Member of RoomTimers received command OFF
then
    // turn off the lights
    sendCommand(triggeringItem.name.split("_").get(0) + "_Lights", "OFF")
end

Theory of operation: When any sensor updates, use Assocaited Items to send a command to the associated Timer. You may need to do more checking here to make sure the update indicates presence. When a Timer Item expires another Rule runs which sends the OFF command to that room’s lights. You may need to loop through the Group and send a different command depending on the Item type. If you do you need to pull the Group out by name:

val lights = RoomLights.members.findFirst[ lts | lts.name == triggeringItem.name.split("_).get(0) + "_Lights" ]
lights.filter[ l | l instanceof SwitchItem ].forEach[ l | l.sendCommand(OFF) ]
lights.filter[ l | l instanceof NumberItem ].forEach[ l | l.sendCommand(0) ]
...

The magic happens by using the Associated Item DP naming scheme and Groups so you can use the name of triggeringItem of the Rule to access the Items you need to interact with.

1 Like