I have created the rule below.
Regardless which of the 4 items in the “when section” triggers the rule I am always getting in LF_Garden.members.sortBy[lastUpdate].last the same Item.
What am I make here wrong?
import java.util.concurrent.locks.ReentrantLock
var java.util.concurrent.locks.ReentrantLock lock1 = new java.util.concurrent.locks.ReentrantLock()
rule OutsideLightsRule
when
Item GardenOuterLights changed or
Item GardenInnerLights changed or
Item GardenPowerSocket changed or
Item TerasseLights changed
then
Thread::sleep(100) // give persistence time to catch up
lock1.lock()
try {
logInfo("OutsideLightsRule", "triggered")
//get the member which triggered the rule
val outLight = LF_Garden.members.sortBy[lastUpdate].last as SwitchItem
logInfo("OutsideLightsRule", "outLight.label " + outLight.label)
// Alert
val StringBuilder msg = new StringBuilder
msg.append(outLight.label) // note a map and transform can convert from Item name to human friendly words
if (OFF == outLight.state) {
msg.append(" OFF") }
else {
msg.append(" ON")}
sendMail("lukic@gmx.ch", "Garden Light " + outLight.label , msg.toString)
} finally {lock1.unlock()}
end