How do I subscribe to the event of a device going offline or coming online in a smartapp?

I know I can get the Hub status of a device by using device.status in groovy but how do I subscribe to that event?

1 Like

Hi there! You could use the SmartApp SDK (Simple SmartApp tutorial).
The example below shows a subscription to the health events of all the devices in a location. When a device status changes from online to offline or vice versa, you’ll receive an event to the handler with this information:

  eventId: 'xxxx-xxxx-xxxx',
  locationId: 'xxxx-xxxx-xxxx',
  deviceId: 'xxxx-xxxx-xxxx',
  hubId: 'xxxx-xxxx-xxxx',
  status: 'ONLINE',
  reason: 'NONE'

For more information about the configuration page and settings options, see this document

1 Like