Getting all OFFLINE devices

Thanks, but OFF is not offline or did I missunderstand something?

The thing goes to offline and not the item.
The item has only states like ON/OFF/UNDEF, but not offline.

And I can’t create a group of things as far as I know.

You don’t want a Group of things, but a Group of items:

Group:Switch:OR(ON, OFF)	gMonitoring	"monitoring items"

and yeah, I think I shortcutted something, it could be, the item above changes to “UNDEF” not to “OFF”… so it should read:

...
When
	Member of gMonitoring changed to UNDEF
...

changed it above.

I understand so if an thing goes offline the items below are getting all UNDEF?
And if this is really the case I get sometimes false warnings because the items can get UNDEF because of any other event/case.

Because of this it would be great to define a group of things and I can check the state for the group :wink:

did you check with the docs?

it is depending on the device difficult to get a constant ping - that’s why sometimes you have to work with proxy items and get them some more expire-time. It reduces the false negative - but of course heightens the risk of getting to know offline-items at a later time…

if you use the gMonitoring “item”-group, you can of course check the group - no need to check it with things (which from the OH-concept don’t make sense to put in a group)

on a side note: OH3 bringt a whole new way of seeing things, items and stuff with the concept of a “model” openHAB 3.0 my getting started notes: Model and Pages

Tanks you are talking about network bindings, but I am talking about every binding.
For example a Z-Wave binding. The thing can go offline if it is loosing the connection to the Z-Wave stick or the HUE-Binding and so on.

But you are right that I can check this with item if I use a network binding.
So for example to check if a PC is online I can do this.

Thanks!

Thanks for the info. Will have a look at it.

Why have you got to create another thing and item to check if the thing status is correct. I have many rules but have no figured out a way to do it all with one rule.

Its late so I will write a rule to do it tomorrow and post it here for you to see.

Do you still want it to show in sitemap or just a notification?

Edit

Use

1 Like

ah! now we’re talking! but having a Z-Wave device losing connection is nothing more than not having a ping on a network device?
In my example - and if zwave behaves differently as network does - I would cascade:

  • gMonitoring
    ** gZwave
    ** gNetwork

meaning, gZwave as a Group has all Z-Wave devices and gNetwork all network ones (you can also make more branches as needed) - the state of gZwave / gNetwork is the determining the state of gMonitoring. That way you get at least two “OFFLINE”-Groups: the one, the item is in and gMonitoring also.

Oh this looks promising. Will have a look.
Thanks!

Thanks will check if the Z-Wave item gets state “UNDEF” if the Z-Wave node thing is offline.

1 Like

you can achieve the same thing on the Thing configuration itself. You can specify:

  • how often to ping
  • how long to wait for a reply
  • how many times a ping will time out before making it as offline

So you can check every 15 seconds, wait one second for a reply, and have the ping timeout 4 times in a row before it’s marked offline. There is no need to use a proxy item and rule.

The online/offline status of a Thing is whether the binding is working or not. To see if a device is online/offline you need to look at the Item linked to the status channel. It’s perfectly normal for The Thing to be ONLINE and the device be offline. The binding is working.

Unless you set an Item to UNDEF yourself in a rule, Items will only go to UNDEF if a binding determines it cannot connect to the device or something else like that has gone wrong. So you can rely on the UNDEF state to indicate a device has gone offline. Assuming the binding supports that.

1 Like

Thanks but for example the Hue Binding thing goes Offline if the connection is lost to the Hue Bridge.
The color item does still have the same old states.

So this is why I am want to get the thing status for example.

I relooked at my approach to this and I decided I don’t need a notification for every thing because Spotify things go offline all the time when you are not using them. So I going to trigger a rule for every thing I want to monitor.

I guess the hue binding doesn’t use the standard approach. You will have to create a rule to trigger on the Thing going offline. There is no way to group things (they are not items after all) so you need to trigger the rule with each Thing you care about. There will be a receivedEvent variable I think you can use to figure out which thing went offline.

To put it on your sitemap you’ll have to create an Item and set it’s state from the rules.

1 Like

I having some issues getting this to work :slight_smile:

I think you can only use a receivedEvent on a channel and not on a thing

Ok here is what I have.

import org.eclipse.smarthome.model.script.ScriptServiceUtil
val telegramAction = getActions("telegram","telegram:telegramBot:Telegram_Bot")

rule "Thing Detected off line list question"
when
    Thing 'wled:wled:Anabel_NL' changed from ONLINE to OFFLINE or
    Item PING_Device changed to OFF
then
    telegramAction.sendTelegramQuery("One of your things went OFFLINE in openHAB.\nItem " + triggeringItem + "\n\nDo you want a list of OFFLINE Things?", "Offline_List", "Yes", "No")
end


rule "Get status of thing and if OFFLINE send message to telegram"
when
    Item telegramReplyId received update Offline_List
then
    val StringBuilder   Message = new StringBuilder
    val things = ScriptServiceUtil.getInstance.thingRegistry.getAll()

   if (telegramMessage.state.toString == "Yes")
    {
    Message.append( " Your OFFLINE things are;   " + "\n" + "\n" )    
    things.forEach[ thing |
        val statusInfo = thing.getStatusInfo()
        if (statusInfo.getStatus().toString() != 'ONLINE') {
            Message.append( "Thing: " + thing.getLabel() + "\n" )
            Message.append( "state: " + statusInfo.getStatus() + "\n" )
            Message.append( "detail: " + statusInfo.getStatusDetail() + "\n" )
            Message.append( "description: " + statusInfo.getDescription() + "\n" + "\n" )
        }
    ]
       
    telegramAction.sendTelegramAnswer(telegramReplyId.state.toString, Message.toString) 
 
    } else {
    telegramAction.sendTelegramAnswer(telegramReplyId.state.toString, "Ok")
    }

end

The result in telegram please forgive typo

image
Item null is because it was triggered by thing if item triggers it shows up.

Select Yes it checks when you select yes so it is a live list not from when it went offline.

Sample of response message

Its still a work in progress

thanx!
…i should be more up to reading improved functionality on “old” bindings! :wink:

1 Like

I had the same problem, and I noticed that the rule “changed from ONLINE to OFFLINE” did not work reliably. So I created the following script, to be executed regularly. It gets the online/offline data directly from the bridge and sets +"_Online" to the values “ONLINE” or “OFFLINE”.

Replace <huepw> with your apikey for the Hue Bridge.

HueSetup includes all lamps with the number (according to Bridge), name, type and item prefix.

load(Java.type("java.lang.System").getenv("OPENHAB_CONF")+'/automation/jsr223/jslib/JSRule.js');
var ThingUID = Java.type("org.eclipse.smarthome.core.thing.ThingUID");

logDebug("HueWorker.js: being loaded");

var HueSetup = [
	[1, "k3", 220, "hueKeller3"]
    // insert here other lamp descriptions
	]

var getHueFromNo=function(id) {
	for (var i = 0; i < HueSetup.length; i++) {
		if(HueSetup[i][0]==id) return HueSetup[i];
	}
	return -1;
}

var getHueReachable=function() {
	logTrace("HueWorker.js: Getting Hue data");
	var requestURL = 'http://philips-hue.local/api/<huepw>/lights';
	var HttpUtilNativ = Java.type("org.eclipse.smarthome.io.net.http.HttpUtil");
	var results = HttpUtilNativ.executeUrl("GET", requestURL, 5000);
	var inJson = JSON.parse(results);
	logTrace("HueWorker.js: JSON received from bridge: "+inJson);
	var outJson=""
	for (x in inJson) {
		var hue=getHueFromNo(x);
		if(hue[0]!=2) {
			var itState=getItem(hue[3]+"_Toggle").state;
			var onlineState=getItem(hue[3]+"_Online").state;
			var thState=things.get(new ThingUID("hue:0"+hue[2]+":1:"+hue[1])).status;
			var jsOnOff=inJson[x]['state']['on'].toString();
			var jsOnline=inJson[x]['state']['reachable'].toString();
			var thingMatch;
			if(jsOnOff=="true") jsOnOff="ON";
			else if(jsOnOff=="false") jsOnOff="OFF";
			else jsOnOff="UNDEFINED";
			if(jsOnline=="true") jsOnline="ONLINE";
			else if(jsOnline=="false") jsOnline="OFFLINE";
			else jsOnline="UNDEFINED";
			// We test if the online/offline status is the same for the thing and the JSON string
			if (thState==jsOnline) thingMatch="match    ";
			else {
				if(onlineState==jsOnline) thingMatch="mism(cor)"
				else {
					thingMatch="mismatch ";
					events.postUpdate(hue[3]+"_Online", jsOnline);
					logInfo("HueWorker.js: Thing status (ONLINE/OFFLINE) mismatch for item "+hue[3]+". jsOnline="+jsOnline+" with _Online="+getItem(hue[3]+"_Online").state+". Corrected.");
				}
			}
			if(onlineState!=jsOnline) events.postUpdate(hue[3]+"_Online", jsOnline);
			var itemMatch;
			// We test for different light state, e.g. if the item shows on and the JSON-string shows off
			if (itState==jsOnOff)
				itemMatch="match   ";
			else {
				if(jsOnline=="ONLINE") {
				itemMatch="mismatch";
				events.postUpdate(hue[3]+"_Toggle", jsOnOff);
				logInfo("HueWorker.js: Item state (ON/OFF) mismatch for item "+hue[3]+". jsOnOff="+jsOnOff+". Corrected.");
				}
				else itemMatch="mism(th)";
			}
			if(itState!=jsOnOff) events.postUpdate(hue[3]+"_Toggle", jsOnOff);
			logDebug("HueWorker.js: "+String(" "+x).slice(-2)+":"+String(hue[3]+"               ").slice(0,18)+
				", testing "+"hue:0"+hue[2]+":1:"+String(hue[1]+"   ").slice(0,5)+
				": ITEM-STATUS:"+String(itState+"  ").slice(0,4)+
				"; THING-STATUS: "+String(thState+" ").slice(0,7)+
				"; JSON: on="+String(jsOnOff+" ").slice(0,3)+
				", reachable="+String(jsOnline+" ").slice(0,7)+
				"; Thing: "+thingMatch+
				", Item: "+itemMatch+
				"==>"+onlineState);
			outJson+="| ";
			outJson+=x+"-"+inJson[x]['state']['on']+"-"+inJson[x]['state']['reachable']+"-"+hue[1];
		}
		outJson+=" ";
		}
	outJson+="|";
	// outJson shows all Json on/off and on-/offline in one line
	logTrace("HueWorker.js: "+outJson);
	return;
}

JSRule({
	name: "Hue Synchronization",
	description: "This rules is a simple example for getting started with JSR223 Javascript",
	triggers: [
		TimerTrigger("0/15 * * * * ?")//Enable/Disable Rule
	],
	execute: function( module, input){
		getHueReachable();
	}
});

logDebug("HueWorker.js: finished loading");
1 Like

Great, thanks will try this.

Good question!

Each Tasmota and Zigbee (via zigbee2mqtt) has “Reachability” status. With Tasmota it’s the LWT topic, and for zigbee2mqtt it’s the “availability” topic.

I have assigned an item for each thing into gAvailability group, so in my sitemap I can just add

Group item=gAvailability label="Availability Status"

and when I click that, I get all the status.

1 Like

You can still use the thing online offline status with MQTT you just have to set it up.
things file

    Thing topic Kettle "Kettle in Kitchen" @ "Kitchen" [ availabilityTopic ="tele/kettle/LWT", payloadAvailable ="Online", payloadNotAvailable ="Offline"] {