[Edge] - How to check the LAN device online/offline status?

For LAN type device, we can set whether the device is online or offline.

How do we check what is the online/offline status?

device:online() or device:offline()
Device — SmartThings Edge Device Drivers documentation

Hi, @hongtat!
You need to define how you would like to check if the device is considered not “reachable” or “unresponsive”. For example, in the LAN sample using an ESP8266, there’s a method to ping the device that is scheduled to be called to verify the device is still reachable and there’s also a Refresh method scheduled to get the current device status. If the last one fails, the device is set as “offline”.

@nayelyz I think the question was how to check the current state of that “online” flag being stored by the platform. So if we call device:online(), I assume some flag is changed in the device. Is there a way to get at that flag?

Ah, is like your question here, right?

  1. device:online() isn’t a command that is sent to the device. It is a state that the device instance “emits”.
  2. There is not a callback for online/offline and we suggest that wherever you set that value you can run other necessary commands/functions.
    For example:
    You could check the device’s online status and generate an internal event or save it in persistent storage as the “last_health_status” (device:set_field(), device:get_field()). That is similar to the variable state we used in Groovy.

Pretty much the same question. My original was looking for a callback. @hongtat was looking for a simple check. In either case, this makes sense.

What do you think of doing this? Add the healthCheck capability and emit an update to healthStatus. It would then be available in the state cache. Would implementing this capability provide any additional benefits within the platform?

That can be helpful for internal control, however, this capability is no longer used to define the current health status of the device. For example, if we don’t use device:offline() but change the value of healthStatus, the device will continue as “online” in the app (no cloud disconnected icon).
Also, if you create subscriptions to the device’s health with a SmartApp, the change to healthStatus won’t trigger an event.
That can be checked in the health endpoint of the API: https://api.smartthings.com/v1/devices/deviceID/health
But, we cannot make requests to the API from a Driver…

1 Like

Thanks. Sound like a more difficult alternative to set_field. My personal solution to my callback request mentioned above, was to call device:online and then inject a refresh command which would grab the latest state.

I can certainly use the set_field, get_field to check the online/offline status, but it may not truly reflect the actual state of the device, if it is set outside of my driver?

Can other app, routine, automations, etc, modify/trigger the online/offline status of the device?

No, the only one that can define the health status of LAN devices is the driver that controls the device. From other places, SmartApps, automation, etc. we can just react to the events of “online”/“offline” but we can’t modify it.
Also, other drivers that don’t handle the device can’t send this type of event.

2 Likes