[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

1 Like

I can only poke at code, but I really need to be able to tell if a device is off in my barn. Does anyone have a working set of code and how to implement to send a notification in the app if a device status goes offline?

You could try the following but it requires a constantly running PC or RPi.

Is an always on pc still the only way to achieve this? I have a faulty August Connect plugged into a smart plugā€¦ I have manually toggled the switch to clear connectivity issues, but itā€™d be great to achieve this by rules or routinesā€¦

1 Like