@KevinHab thanks for your help.
I think i’ve found some errors in my rule (plz don’t be mad at me for still trying to get my approach working )
previous state was not working hence i stored the items as strings in my hashmap. Therefore
(value as GenericItem).previousState().state
doesn’t point to the same persistence entry like e.g.
Valve_Garden_Left_Ping.previousState().state
So i switched my Hashmap to
val HashMap<String, GenericItem>
Now i can access directly the items and in addition persistence seems to work.
Without the previousState stuff it worked for days now. So i’m testing it now with my modified HashMap hoping that it will last forever
My complete code is now:
import java.util.HashMap
val HashMap<String, GenericItem> ThingsMap = newHashMap (
"zwave:device:86910632:node21" -> Plug_Garden_TerraceRight_Ping, //Plug_Garden_TerraceRight
"zwave:device:86910632:node5" -> Illumination_Garden_Blind_Ping, //Illumination_Garden_Blind
"zwave:device:86910632:node11" -> Illumination_GroundFloor_LivingRoom_Ping, //illumination_GroundFloor_LivingRoom
"zwave:device:86910632:node10" -> Plug_Garden_TerraceLeft_Ping, //Plug_Garden_TerraceLeft
"zwave:device:86910632:node6" -> Pump_Basement_Circulation_Ping, //Pump_Basement_Circulation
"zwave:device:86910632:node19" -> SmokeDetector_2ndFloor_Entrance_Ping, //SmokeDetector_2ndFloor_Entrance
"zwave:device:86910632:node12" -> SmokeDetector_2ndFloor_KidsRoom_Ping, //SmokeDetector_2ndFloor_KidsRoom
"zwave:device:86910632:node18" -> SmokeDetector_2ndFloor_SleepingRoom_Ping, //SmokeDetector_2ndFloor_SleepingRoom
"zwave:device:86910632:node3" -> SmokeDetector_GroundFloor_Entrance_Ping, //SmokeDetector_GroundFloor_Entrance
"zwave:device:86910632:node2" -> SmokeDetector_GroundFloor_LivingRoom_Ping, //SmokeDetector_GroundFloor_LivingRoom
"zwave:device:86910632:node9" -> Valve_Garden_Left_Ping, //Valve_Garden_Left
"zwave:device:86910632:node4" -> Valve_Garden_Right_Ping, //Valve_Garden_Right
"zwave:device:86910632:node8" -> Door_GroundFloor_Terrace_Ping //Door_GroundFloor_Terrace
)
rule "DeviceState"
when
Time cron "0 0/30 * * * ?" //every 30 minutes
then
//enumerate all things and check status
ThingsMap.forEach[key, value|
//get status of thing
var status = ThingAction.getThingStatusInfo(key.toString)
//logInfo("DeviceState", value.toString + "Previous State: " + value.previousState().state + "Thing State:" + status.toString())
//check if status is online
if(status.toString == 'ONLINE')
{
logInfo("Devicestate", "Current state of " + key + ": ONLINE")
//only if the previous state reports offline switch on
if(value.previousState().state == OFF)
{
value.sendCommand(ON)
sendMail("---", "OpenHab Thing ONLINE", "The following device changed from OFFLINE to ONLINE:"+ "\n\r" + value.label.toString + "\n\r" + now.toString)
}
}
else //status is anything else than online
{
logInfo("Devicestate", "Current state of " + key + ": OFFLINE")
//only if the previous state reports online switch off
if(value.previousState().state == ON)
{
value.sendCommand(OFF)
sendMail("---", "OpenHab Thing OFFLINE", "The following device changed from ONLINE to OFFLINE:"+ "\n\r" + value.label.toString + "\n\r" + now.toString)
}
}
]
end
So if it is working - i’m really happy.
If not, I will try to get back to your approach.