Rule for "all" Things?

Hello Community,

I am trying to add a sitemap that displays the status of my things (Online, Offline…).
All of them are Z-Wave nodes.

Therefore i could setup a rule for each things like:

when
	Thing "zwave:device:86910632:node21" changed
then
	var status =  ThingAction.getThingStatusInfo("zwave:device:86910632:node21").getStatus()
	if(status.toString() == 'OFFLINE')
	{
		logInfo(strDeviceOffline, "Device offline: zwave:device:86910632:node21")
	}

…and so on. Can I somehow make this in a more elegant way? My idea would be somthing like (pseudoCode):

when
    Thing AnyThing has changed
then
    var status = ThingAction.getThingStatusInfo("<the thing that has changed>").getStatus

I’m running openHAB 2.1 on a Raspi3 with Razberry

Ok, since i didn’t find any possibility to list all things automatically, i found another way to get it working.

I created a hashmap that contains all devices and the items that should change their states:

val HashMap<String, Object> 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
										)

and within my rule (which is triggered by a cron timer i’m iterating through this map:

	//enumerate all things and check status
	ThingsMap.forEach[key, value|

		//get status of thing		
		var status = ThingAction.getThingStatusInfo(key.toString)

		//check if status is online
		if(status.toString == 'ONLINE')
		{
			//only if the previous state reports offline switch on
			if((value as GenericItem).previousState(true) == OFF)
			{
				(value as GenericItem).sendCommand(ON)
			}
		}
		else //status is anything else than online
		{
			//only if the previous state reports online switch on
			if((value as GenericItem).previousState(true) == ON)
			{
				(value as GenericItem).sendCommand(OFF)
			}
		}
	]

This seems to be working without any issues. Adding a new thing i want to monitor just requires to extend the Hashmap with the ThingID and the corresponding item.

Still it would be really good to be able to list all things within a rule.

3 Likes

I’m also intrested in this.
Did you (or somebody else) manage to have it filled in automaticly?

No - no progress at that point. I’ve switched to individual rules for my devices and i’m happy so far.
However it could definitely be improved…best would be if every thing (since it has a state) would by default make its state available via an item.

@Sascha_Billian, I’m really interested in this! Can you explain how I can get this working?

  • Where you put the hash_map? Is it a transform map?
  • I assume you need an item-file (to define Plug_Garden_TerraseRight_Ping etc). Do you decleare them as switch or as string?
  • Do you have to use a cron timer? Can’t you trigger the rule when the status of a thing is changed?

Thx

I’ve put the hashmap above the rules. The items for the state of the devices are declared as a switch and the rule was running by a Cron timed trigger. However I faced the rule engine stopping every now and then due to this rule (without any helpful logs) so I switched back to have individual rules for all my things. They are triggered by the thing’s event