Skip to content

The JSON API

Everything that controls WLED — the web page, the apps, Home Assistant, your own scripts — eventually speaks one language: the JSON API. It is a set of web addresses on the device itself that exchange JSON objects. Learn it and you can drive the lights from anything that can fetch a URL, including a five-line shell script. This chapter's shapes are not copied from a wiki: they are read from the firmware's own serialising code, so the keys below are the keys the device really sends.

The four objects

GET http://<device>/json returns one document with four members:

  • state — the light as it is now, and the only part you may write back;
  • info — the device: version, counts, Wi-Fi, free memory. Read-only;
  • effects — the names of the effects, in slot order (chapter 9);
  • palettes — the palette names, likewise.

Each is also served alone, at /json/state, /json/info, /json/eff and /json/pal. To change something, POST the part of state you care about to /json/state — or to /json, which accepts state and answers with the new whole document. Partial updates are the normal case: send one key, the rest is untouched.

The state object

The heart of it, with the keys you will actually use (the full list, including sync and realtime members, is in the lab notes):

{ "on": true, "bri": 128, "transition": 7,
  "ps": -1, "pl": -1, "mainseg": 0,
  "nl": { "on": false, "dur": 60, "mode": 1, "tbri": 0 },
  "seg": [ { "...": "chapter 8's segment object" } ] }
  • on and bri — power and master brightness, 0–255. (bri is stored even while off, so the light comes back at the level you left.)
  • transition — the crossfade time for this change, in units of 100 ms (7 = 0.7 s). The single most-misread number in the API.
  • ps / pl — apply a preset or playlist by number; WLED reports −1 when state no longer matches any saved preset.
  • nl — the nightlight of chapter 10.
  • seg — the segments, chapter 8. Address one by id, or use "id": -1-style broadcast forms documented in the API reference — including "seg": [] tricks like stopping at segment boundaries, which the reference spells out.

A worked example — porch strip to a warm, dim solid, one request:

curl -X POST http://wled-porch.local/json/state \
  -H 'Content-Type: application/json' \
  -d '{"on":true,"bri":90,"transition":20,
       "seg":[{"id":0,"fx":0,"col":[[255,160,40]]}]}'

The info object

/json/info is the device's identity card. The fields the lab verified in the serialiser include ver (the version string), vid (its numeric form), name, mac and ip; a leds object with count, fps, and pwr — the estimated current draw right now, in milliamps, with maxpwr the ABL budget it is being held to (chapter 4); and three counters that settle bar bets: fxcount 220, palcount 72 on a stock build (plus cpalcount, custom palettes loaded). freeheap and uptime are there too, for the day the device feels unwell and you want facts before feelings.

The older doors

Two relatives worth knowing. The HTTP API — http://<device>/win&A=128 and friends — changes settings with a single GET and answers in XML; the project recommends JSON for anything new but keeps this one working, and macro presets (chapter 10) can speak either. And beyond HTTP entirely, the device accepts realtime streams and sync messages over UDP (chapter 12), which never appear in this chapter's objects at all — they write the same state from the side door.