Access Hub active/inactive status in SmartApps?


(Andrea Kealy) #1

Hello,

I’ve been having some internet connectivity issues which are affecting my SmartThings Hub, i.e. the status changes relatively frequently between active and inactive. I have two questions:

  1. Is there a way to catch these active/inactive event triggers using SmartApps, in a similar way to how capability.motionSensor can be used to catch motion active/inactive events or capability.contactSensor can be used to catch open/closed events.

  2. Are events that are triggered while the hub is offline/inactive buffered on the hub and sent when the hub comes back online or are the lost?

Any help would be great! Thanks!


(Geko) #2

No, all smart apps run in the cloud, so if the hub is off-line, they cannot receive any events from the hub. SmartThings has built-in ping facility (you can configure it in the IDE). If ST detects the hub is off-line for certain period of time (e.g. 5 minutes), they will send push notification to your phone.

Are events that are triggered while the hub is offline/inactive buffered on the hub and sent when the hub comes back online or are the lost?

No, there’s nothing queued on the hub.


(Andrea Kealy) #3

Thank you for your reply geko! I have the app set up on my phone and can see hub activity/inactivity pings. Is there any way to access this information in the SmartApps?


(Nikita Selednikov) #4

Hello!

I’ve found a way to do it, just in case somebody will get on this thread.

Information is actual on November 2016.

I use the following code to subscribe to Hub going online/offline in the SmartApp:

def installed() {
    log.debug "Installed"
	subscribeToEvents()
}

def updated() {
    log.debug "Updated"
	unsubscribe()
	subscribeToEvents()
}

def subscribeToEvents() {
    //get first hub object in your location.
    def hub = location.hubs[0] 
    //subscribe function "eventHandler" to Hub "status" events
    subscribe(hub, status, eventHandler)
}

def eventHandler(evt) {
    log.debug "$evt.name $evt.value"
}

Afterwards you will receive events, when Hub is connected/disconnected


(Keith Norman) #5

slight correction:

subscribe(hub, "hubStatus", eventHandler)

That is working for me.