So i try to show you the light as understand it. There is no guarantee that i am right.
1.) The switch thing
val sw = gMotionDetectors.members.sortBy[lastUpdate].last as SwitchItem
You are very close, but not precise enough. So letzt go trough the statement.
val
Defines a value that could not be changed (Constant). var is the other option. This defines a value that could be altered. I am not in the design pattern, but i assume the the val is choosen, because it is used inside a lambda
gMotionDectectors
This is a group off all motion detector switches. Typically if a motion detector tripped as swicth is triggered
members
This selects all members of this group. If i remeber right you get some kind of list with all the members
sortBy[lastUpdate]
This sorts you member list by the key “lastupdate”
last
And the last selects the last element is the list. so this ist the one which is last updated. Unfortunately OH ist currently not able to tell which item within a group has triggered rule. And with this statement you get the triggering item.
as SwitchItem
Defines the returned item as a switch.
As you see more or less the same, but a little bit more precise. Now the next parts
2.) The Map part
import java.util.Map
val Map<String, Timer> timers = newHashMap
Because OH does not know directly all thing of stuff, we have to import some “constructs”. Here we improt a type called Map. A Map is a collection of key/value pairs like (Thomas->52; Geord->23; Charles->22). Here the Name is the key and with the key you are able to acces the age. The secondline creates a variable named timers. timers stores Timer connected to a String
timers.get(sw.name)
This line of code retrieves a timer from the map timer by using the key sw.name. Remeber sw ist our switch item and with the .name we acces the name of the item. Maybe something like “MotionDetectorMainEntry”
timers.put(sw.name, createTimer…)
this is the opposite of getting the timer. put puts a new timer into the map with the key “sw.name”. the createTimer create the Timer in the fly
timers.put(sw.name, null)
the null puts the map entry into a defined state after the timer has expired. so you can check if the timer is not null, it should be running
Hope this helps a little bit.
Cheers
Thomas