[ST Edge] How to check online/offline status of device in a routine?

What if I need to create a routine that acts when device goes online/offline ?
What if I need to create a routine that acts when one of its precondition is the actual status of online device and not the last status before going offline ?

I thought I could use this capacity to create these routines.

There was a period when the Health Check capability displayed the online/offline status, but that stopped working quite some time ago now. I think it is still used in certain types of device integration to allow the status to be set via an attribute but other integrations like Edge simply don’t need it.

Device Health is now exposed via an API endpoint rather than via an attribute, and non-legacy SmartApps can subscribe to it, but I don’t think the Rules API, and so the Routines, can do anything with it yet. I’d be a bit surprised if Routines ever supported it.

What I have written above is a best guess. Getting reliable and consistent information about how to work with device health has never been easy.

1 Like

What is this endpoint for a zigbee device ?

Check Your Device’s Health | SmartThings Developers

I took out the power source of the device and made a request…

{
    "deviceId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "state": "ONLINE",
    "lastUpdatedDate": "2022-01-11T01:04:21.234Z"
}

After ± 30 minutes, I retested and it returned…

{
    "deviceId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "state": "OFFLINE",
    "lastUpdatedDate": "2022-01-11T01:34:24.609Z"
}

So yeah, thanks @orangebucket !

Do you know any way to check this status from the driver itself ?

Thanks for jumping in, @orangebucket. :smiley:
@w35l3y, health status can be accessed using a SmartApp as well.

You could create subscriptions to it and create automation based on that event. These are the functions you could use from the SmartThings Core SDK which the SmartApp SDK is based on.

In Edge drivers, the health status is handled automatically for Zigbee and Z-Wave. In LAN drivers, you could implement your own method and use the functions of device:online(), device:offline()

Can Health Status be set from a SmartApp? I would like to write a SmartApp replacement for Device Health - it seems to no longer function on zwave/zigbee DTH devices. I have many hardwired devices that are way over their checkInterval time, don’t get ping() called and never get marked OFFLINE.

No, it cannot be set through a SmartApp, but you can try using Edge drivers for your Zigbee and Z-Wave devices, they handle the device health automatically.
In the DTH, you had to enroll for the health check depending on the protocol but you don’t need to do that now.
There are some drivers already available here which you can have access to by enrolling your Hub in this channel (see more info about that at the bottom of this post.

All my devices are DTH currently and the ones that I’m inquiring about all enrolled in Health Check - but it appears to no longer be working. Polling is inconsistent too. I’m guessing they are related to the same problem.

For Edge, its not a “production ready” option for me at this point. Without the ability to see at least the following data from the Groovy IDE

  • Route (zwave and zigbee both)
  • Device Data (security level and other driver set data)
  • Current States
    Edge is not something I can switch to yet. I’ve played with it on our development hub but it can’t be used on our “production” (aka, the family uses it) hub yet.

Thanks for replying!

I see, well, for devices that are controlled Edge drivers, you can see several of their properties through the ST API, for example:

Field / Information Endpoint
networkId /devices
driverId /devices
executingLocally /devices
networkSecurityLevel /devices
parentDeviceId / hubId /devices
capability status/values /devices/deviceId/status
capability status/values /devices/deviceId/status
device health /devices/deviceId/health

If you want, I can report the issue with the device health using a DTH, to do so, please the following information over a direct message:

  • Device name and ID
  • if it’s a custom DTH, include its code. We can get more descriptions of the device from there (fingerprints)

PM sent. thank you so much for taking up my question/concern!

Is there a callback for when these occur? My driver has a hub device with many children. If the hub goes offline, the children are automatically marked offline. When the hub comes back online, I would like to be able to tell the child devices to try and update their status as well.

When the hub is rebooted or there was a power outage, the driver is restarted and the init lifecycle is executed for each device (the order parent-children is not guaranteed). The init of the device object just means that the record of the SmartThings device has been created on the Lua side.
So, you could add a validation there as a quick check-up of their current status and send those commands

To be clear, I was referring to a non-ST hub. ST talks to a different Hub (Hue/Bond/SwitchBot) and adds child devices from those hubs/bridges. If that bridge device goes offline, it marks all of the child devices offline as well. But when that bridge comes back, there isn’t a callback to have the child devices check as well.

Mmm, I see…I’m not aware of the method you defined to know the status of external Hub (offline/online) so ST knows if it’s out or not.
In this LAN sample, there’s a ping function scheduled to check if the device is still responsive.

If you can configure a method like this in your Hub so it responds to the pings you define in ST and sends the status of the connected devices, I believe you won’t need a callback when they get offline.
Is that something possible on your side?
I’m not sure the effect of device:refresh() in LAN devices, I will check that with the team.

I can ping and see if everything is online. If a device comes online, is there a callback within the same device? So if a device comes :online() I can have it do additional work like fetch its state from the LAN connected device. Basically, I would like to see online and offline become lifecycle callbacks that are triggered by calling device:online() and device:offline(). If this is not currently possible, I would like to make a feature request of the engineering team.

Thanks @nayelyz