For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to page URLs.
Skip to content

Devices

List the dashboard's devices and change the selected device from a Custom Metric widget — dashboardDevices, useUbidotsSelectedDevice, setDashboardDevice

GET

  • All devices on the dashboard, to list them or build a picker: useUbidots().state.dashboardDevices returns Device[] | null. It arrives through the v2:dashboard:devices:self event.

  • The selected device(s):

    • useUbidotsSelectedDevice() returns Device | null.

    • useUbidotsSelectedDevices() returns Device[] | null.

  • The devices that own this widget's configured variables, handy for labels and names when you render: the devices: [{ id, label, name }] of the onInfo payload.

A Device has the shape { id, label, name, ... }.

EMIT (useUbidotsActions())

  • Change the selected device: setDashboardDevice(deviceId).

  • Select several at once: setDashboardMultipleDevices([deviceId, ...]).

How to implement: a device picker

import { useUbidots, useUbidotsActions } from '@ubidots/react-html-canvas';

function DevicePicker() {
  const { state } = useUbidots();
  const devices = state.dashboardDevices ?? []; // the full dashboard list
  const { setDashboardDevice } = useUbidotsActions();
  return (
    <select onChange={(e) => setDashboardDevice(e.target.value)}>
      {devices.map((d) => (
        <option key={d.id} value={d.id}>{d.label ?? d.name}</option>
      ))}
    </select>
  );
}

Last updated

Was this helpful?