Hi all,
I have been reading a lot and this is my first post so bare with me
I am running OH2 stable release now for a while and getting into the more complex site of things. So here is my situation and problem:
I purchased two Fibaro door/window sensor 2. All is working fine. All itâs channels work and are displayed correctly on the sitemap. I now wanted to create a rule that sends me a Pushover message if the battery of this sensor is running low and needs replacement. Problem is, it keeps sending me the wrong Item name. Here is the (relevant) setup (sorry, half in Dutch)
// contact.items file
// Battery alarm
Switch deurVoor_batAlarm "Voordeur [MAP(battery.map):%s]" <battery> (gHal, gBatteryAlarm, gHerstel)
Switch deurAchter_batAlarm "Achterdeur [MAP(battery.map):%s]" <battery> (gWookamer, gBatteryAlarm, gHerstel)
// group.items file
Group gBatteryAlarm "Batterij vervangen" <battery>
// battery.rules
// Send pushover msg when battery receives low level
val logName = "pushover"
rule "Battery low level"
when
Item deurVoor_batAlarm received command ON or
Item deurAchter_batAlarm received command ON
then
logInfo(logName, "Alarm received, checking devices...")
Thread::sleep(100)
val alarmItem = gBatteryAlarm.members.filter[s|s.lastUpdate("mapdb") !== NULL].sortBy[lastUpdate("mapdb")].last as SwitchItem
logInfo(logName, "Device " + alarmItem + " received alarm. Creating pushover message...")
val StringBuilder msg = new StringBuilder
msg.append("De batterij van ")
msg.append(alarmItem.name)
msg.append(" moet vervangen worden!")
pushover("","", msg.toString, 1)
logInfo(logName, "Pushover message sent")
end
// mapdb.persist
// Persists all items that need their value restored on startup
Strategies {
default = everyUpdate
}
Items {
// persist all items on every change and restore them from the db at startup
gHerstel* : strategy = everyChange, restoreOnStartup
}
The rules is hacked together from this topic.
In the logs I can see:
2018-02-18 11:42:48.073 [INFO ] [org.eclipse.smarthome.model.script.pushover ] - Alarm received, checking devices...
2018-02-18 11:42:48.203 [INFO ] [org.eclipse.smarthome.model.script.pushover ] - Device deurAchter_batAlarm (Type=SwitchItem, State=NULL, Label=Achterdeur, Category=battery, Groups=[gWookamer, gBatteryAlarm, gHerstel]) received alarm. Creating pushover message...
2018-02-18 11:42:48.863 [INFO ] [org.eclipse.smarthome.model.script.pushover ] - Pushover message sent
However, I manually tricked deurVoor_batAlarm and not deurAchter_batAlarm. So after sorting, it returns the wrong item. Any ideas where I go wrong? Any help appreciated!