1KEY Developers
Guides

Devices

A hub's devices are the locks, thermostats, switches and sensors joined to it. Their state lives on the hub: the API asks the hub live, so these calls need the hub online.

Devices and channels

Each device has channels: the things it reads or sets. A lock has a lock channel and usually battery; a thermostat has temperature, mode and heating_setpoint; a two-gang switch has a switch channel on endpoint 1 and on endpoint 2.

curl
curl https://api.1keyplatform.dev/v1/hubs/1key-xfy2-nmf4-5xwp/devices/7 \
  -H "Authorization: Bearer $ONEKEY_API_KEY"
json
{
  "id": 7,
  "name": "Front door",
  "manufacturer": "Yale",
  "model": "YRD256",
  "channels": [
    { "key": "battery", "endpoint": 0, "kind": "battery", "unit": "%", "readable": true, "writable": false, "capabilities": {}, "available": true,
      "value": 82, "observed_at": "2026-10-03T13:58:00.000000Z", "desired": null, "desired_at": null, "status": "synchronized" },
    { "key": "lock", "endpoint": 0, "kind": "lock", "unit": null, "readable": true, "writable": true, "capabilities": {}, "available": true,
      "value": true, "observed_at": "2026-10-03T14:00:00.000000Z", "desired": null, "desired_at": null, "status": "synchronized" }
  ]
}

GET /hubs/{hub_id}/devices lists every device with its channels, without values. Get one device for its values. Both need hubs:read. Each device also carries room, set by you (below).

A channel's value is only ever what the device last reported. desired is what the last command asked for, and status compares them:

status Meaning
unknown Nothing asked, nothing reported yet
synchronized The device reports what was asked, or nothing was asked
pending A command is under way
diverged The device has since reported something else
failed The command was refused or abandoned

Channel keys

Key Value Writable
lock true locked, false unlocked yes
barrier true open, false closed (garage doors, gates) yes
switch true on, false off yes
level 0–99 % (dimmers) yes
position 0 closed – 99 open % (shades) yes
color {"red": 0–255, "green": …, "warm_white": …} yes
mode off, heat, cool, auto, eco, … yes
heating_setpoint, cooling_setpoint °C; capabilities has min and max yes
fan_mode auto_low, low, high, … yes
local_protection true while the device's own buttons are locked out yes
operating_state, fan_state idle, heating, cooling, … no
temperature, humidity, luminance, co2, … a number, in unit no
contact, motion, leak, smoke, co, heat, tamper true while triggered no
battery % no
energy, power, voltage, current, water, gas meter readings, in unit no
alarm {"type", "event", "active", "user"} no
scene {"scene": 1, "attribute": "pressed"} no

A device has only the channels it reported supporting. Check writable before sending a command.

Names and rooms

A device's name is what the hub reports unless you set one; room is yours alone. 1key keeps both in the cloud, so they survive a hub restart:

curl
curl -X PATCH https://api.1keyplatform.dev/v1/hubs/1key-xfy2-nmf4-5xwp/devices/7 \
  -H "Authorization: Bearer $ONEKEY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "Main entrance", "room": "Entrance"}'

Send either or both; null clears one. Needs hubs:write.

Adding a device

Open the hub's network, then put the device in pairing mode (usually three presses of its button, or as its manual says):

curl
curl -X POST https://api.1keyplatform.dev/v1/hubs/1key-xfy2-nmf4-5xwp/pairing \
  -H "Authorization: Bearer $ONEKEY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"setup_code": "12345"}'
json
{ "status": "open", "expires_in": 120 }

The hub listens for one device for two minutes. When it joins, a device.added event arrives with its device_id. setup_code is optional: the 5-digit PIN, DSK or QR text printed on the device or its box. Locks need it to join securely enough to be driven. DELETE /hubs/{hub_id}/pairing closes the window early. Needs hubs:write.

Removing a device

A device still on the hub's network leaves it with a hand on the device: open the removal window, then press the device's button.

curl
curl -X POST https://api.1keyplatform.dev/v1/hubs/1key-xfy2-nmf4-5xwp/removal \
  -H "Authorization: Bearer $ONEKEY_API_KEY"

A device.forgotten event confirms it. DELETE /hubs/{hub_id}/removal closes the window.

A device the hub can no longer reach (its channels show available: false) can't press a button. Forget it instead:

curl
curl -X DELETE https://api.1keyplatform.dev/v1/hubs/1key-xfy2-nmf4-5xwp/devices/8 \
  -H "Authorization: Bearer $ONEKEY_API_KEY"

The hub refuses to forget a device still on its network (400): remove that one with the removal window. Both need hubs:write.

Trying it in the portal

Each hub's Devices tab in the portal is built on these endpoints. Its console shows every request, response and event, can copy any request as curl, and can act with one of your API keys' scopes to see permission errors.

When the hub can't answer

Status type Meaning
503 hub_offline The hub is not connected. Sent nothing
503 hub_unavailable The hub is connected but can't do it now: its radio is down, or it doesn't know the time yet
504 hub_timeout The hub did not answer within 10 seconds

To track state over time, follow events rather than polling devices.