Displaying Device Power Status

You can display the power status of your end users' devices in your app.

You can display the power status of your end users' devices in your app, including whether the device is wired or battery-powered. Further, for battery-powered devices, you can also display information about the battery status, such as the battery charge level and the battery status.

To display this information, use either of the following Seam mechanisms:

Get Device Power Status Using Device Properties

Seam polls connected devices and accounts every ten minutes and updates the following device properties accordingly:

Use a Get Device request to retrieve the current power status of a device. First, determine whether the device is wired. If the device is battery-powered (that is, not wired), get the battery level and status. Then, display the retrieved device power status in your app.

You can also use the prebuilt device details Seam Component, which includes a device power status display.

Request:

device = seam.devices.get("36cf1a96-196d-41b0-9804-88154387f1f9")
if device.properties.has_direct_power == True:
  pprint("Power Source: Wired")
else:
  pprint("Power Source: Battery-powered")
  pprint("Battery Level: " + str(device.properties.battery.level))
  pprint("Battery Status: " + device.properties.battery.status)

Response:

'Power Source: Battery-powered'
'Battery Level: 0.9999532347993827'
'Battery Status: full'

Seam generates the following battery-related events:

  • device.low_battery

  • device.battery_status_changed

You can retrieve these events using a List Events request or through webhooks and then display the corresponding status in your app.

When issuing a List Events request to retrieve device.low_battery or device.battery_status_changed events for a specific device, include the following parameters:

The following example uses the List Events request to retrieve all device.battery_status_changed events for a specific device since January 1, 2024:

Request:

device_battery_status_changed_events = seam.events.list(
    device_id = "36cf1a96-196d-41b0-9804-88154387f1f9",
    event_type = "device.battery_status_changed",
    since = "2024-01-01T00:00:00Z"
)
pprint(device_battery_status_changed_events)

Response:

[{'connected_account_id': 'c1413928-f527-4e12-abf9-d5e18d92dd33',
  'created_at': '2024-01-01T02:25:10.158Z',
  'device_id': '36cf1a96-196d-41b0-9804-88154387f1f9',
  'event_id': 'de4314a2-903d-53e9-bb5e-ded5d19ad074',
  'event_type': 'device.battery_status_changed',
  'occurred_at': '2024-01-01T02:25:10.158Z',
  'workspace_id': '398d80b7-3f96-47c2-b85a-6f8ba21d07be'}]

You can set up webhook endpoints to receive device.battery_status_changed and device.low_battery events. Then, you can use the receipt of these events to display the corresponding device status in your app. For more information about configuring webhooks, see Webhooks.

Last updated

Logo

© Seam Labs, Inc. All rights reserved.