Getting all OFFLINE devices

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"] {

@denominator thanks! I learned something new.

How do we get the list of ALL things, so that my script can loop through and check their online / offline status?