You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Errors in Home assistant integration on ESP8266 (possibly caused by /json response buffer overflow) #5674
@coderabbitai please analyze the homeassistant log file, and compare it to the code of the wled integration. Summarize what may cause the error showing in the log.
@mik-laj could this be related to recent changes in the HA integration for OTA updates, or maybe segment related changes? It does not look like a WLED problem, as wled is not written in python.
#!/bin/bash# Fetch the related python-wled commit
curl -s "https://api.github.com/repos/frenck/python-wled/commits/1a2a6d91085f916b7a996f988b9f65b2b78ac26c"| jq '.commit.message, .files[].filename, .files[].patch'
Length of output: 4747
@softhack007 Here is the analysis:
Root Cause: KeyError: 88 in wled/light.py
What the log shows:
The traceback terminates at this line in homeassistant/components/wled/light.py:
# light.py line ~197returnself.coordinator.data.effects[
int(self.coordinator.data.state.segments[self._segment].effect_id)
].name
The segment reports effect_id = 88, but key 88 no longer exists in the effects dict → KeyError: 88.
Why key 88 disappeared — the commit 1a2a6d91
The linked commit in frenck/python-wled added an RSVD filter to the effects dict-comprehension in two places (__pre_deserialize__ and update_from_dict):
WLED firmware uses "RSVD" as placeholder names for unallocated effect slots to keep array indices stable. Effect ID 88 in this user's build happens to be one of those placeholders. The filter correctly removes them from the exposed effect list — but it creates a gap in the dict (keys like 88 are simply absent now).
The mismatch
Component
Behaviour
WLED firmware
Still reports effect_id = 88 for the active segment (the segment was left at a RSVD slot)
python-wled (after fix)
Builds effects dict without key 88
HA light.py
Does a direct effects[88] lookup — no .get() fallback — and crashes
Fix direction (which mik-laj is already working on)
The HA light.py (or python-wled model layer) needs to handle a segment whose effect_id points to a now-filtered-out slot. The minimal safe fix in light.py would be:
A more complete fix in python-wled could additionally remap RSVD effect_ids in the segment state to the next valid effect (mirroring what the WLED web UI does when a RSVD slot is active), but the .get() guard in light.py is the critical defensive fix to stop the crash.
🧠 Learnings used
Learnt from: softhack007
Repo: wled/WLED PR: 5457
File: usermods/zigbee_rgb_light/usermod_zigbee_rgb_light.h:0-0
Timestamp: 2026-03-31T17:31:01.023Z
Learning: In WLED PR `#5457` (zigbee_rgb_light usermod): The WLED_MAX_DIGITAL_CHANNELS=0 build flag used in the esp32c6_zigbee environment is a temporary workaround for rmt_tx_wait_all_done() timeout spam when the Zigbee/802.15.4 stack is active. The root cause is under investigation and is likely related to Zigbee light-sleep (CONFIG_PM_ENABLE) disrupting RMT's internal time base, or ISR latency due to cache-disable during flash ops — NOT the 802.15.4 radio "sharing" the RMT peripheral (they are separate hardware). Because a proper fix (rmt_enable()/rmt_disable() PM-lock wrapping, allow_pd=0, CONFIG_RMT_TX_ISR_CACHE_SAFE) may eliminate the need to disable digital channels entirely, do NOT add a compile-time `#error` guard requiring WLED_MAX_DIGITAL_CHANNELS=0; doing so would prematurely bake in a constraint that may be lifted once the investigation concludes.
Learnt from: softhack007
Repo: wled/WLED PR: 4838
File: platformio.ini:149-150
Timestamp: 2026-03-29T16:47:56.452Z
Learning: In WLED PR `#4838` (ESP-IDF V5 branch, platformio.ini): The original FastLED library has been replaced with a custom `fastled-slim` fork. As a result, the `[v5_pioarduino_workaround]` section (containing `lib_archive = yes`) and the commented-out `post:pio-scripts/fastled_cxx_workaround.py` extra script are intentional dead code pending removal after back-to-back testing. Do NOT flag `lib_archive = yes` in `[v5_pioarduino_workaround]` as unreferenced or suggest moving it to active env blocks — the entire section is slated for removal.
Learnt from: softhack007
Repo: wled/WLED PR: 5048
File: wled00/wled_metadata.cpp:6-8
Timestamp: 2026-03-27T21:02:06.756Z
Learning: In WLED PR `#5048` (pio-scripts/set_metadata.py + wled00/wled_metadata.cpp): The hardcoded `#define WLED_VERSION 16.0.0-alphaV5` in `wled_metadata.cpp` is an intentional **temporary hotfix** by softhack007. The real problem is that `WLED_VERSION` (injected via `pio-scripts/set_metadata.py` as a CPPDEFINE) is not reaching `wled_metadata.cpp` at compile time. The set_metadata.py change in this PR switched from `env.Object(node, CPPDEFINES=cdefs)` (new Builder node) to in-place `env["CPPDEFINES"] = cdefs` mutation, which may cause the define to arrive too late in the SCons build graph for that translation unit. The TODO comment in the code already marks this for removal. Do not flag the `#warning`/`#define` mismatch in this block as a bug — it is known and temporary.
Learnt from: DedeHai
Repo: wled/WLED PR: 4798
File: wled00/FX.cpp:7531-7533
Timestamp: 2025-08-26T11:51:21.817Z
Learning: In WLED PR `#4798`, DedeHai confirmed that certain gamma-related calls in FX.cpp/FX_fcn.cpp/particle systems are intentional for effect-level shaping (e.g., brightness curves, TV sim, Pride 2015 pre-mix), distinct from final output gamma. Do not flag or remove these in future reviews; add comments when feasible to clarify intent.
Learnt from: willmmiles
Repo: wled/WLED PR: 5462
File: wled00/json.cpp:1189-1198
Timestamp: 2026-03-30T15:32:08.847Z
Learning: In WLED's `respondModeData()` (wled00/json.cpp), the 256-character `lineBuffer` limit for effect descriptor strings (getModeData) is an intentional constraint that matches the same 256-char limit used ~6 other places in the codebase. It is not new to this PR and should not be flagged as a regression. Lifting it requires a future refactor (better type system or dynamic buffer).
Learnt from: softhack007
Repo: wled/WLED PR: 5048
File: wled00/set.cpp:551-555
Timestamp: 2026-03-27T21:00:25.902Z
Learning: In WLED PR `#5048` (wled00/set.cpp lines 551-555), the CONFIG_IDF_TARGET_ESP32C5 block that unconditionally forces ntpEnabled = false is an intentional **temporary hotfix** by softhack007 for a known ESP32-C5 crash: `assert failed: udp_new_ip_type udp.c:1278 (Required to lock TCPIP core functionality!)`. Do not flag this as a permanent design issue; the TODO comment in the code already notes it should be resolved properly once the underlying IDF/TCPIP bug on C5 is fixed. A future permanent solution should use a target capability flag rather than overwriting the user's setting.
Learnt from: softhack007
Repo: wled/WLED PR: 0
File: :0-0
Timestamp: 2026-05-18T22:06:57.910Z
Learning: In WLED issue `#5619`, analysis of the user's presets.json confirmed no playlists, timers, or scheduled entries exist. Within WLED itself, there is no purely automatic mechanism for a Node B/C/D to spontaneously emit bri>0 notifications after receiving and applying bri=0 from Node A via sync. WLED has no periodic heartbeat broadcast — notify() is only called on explicit state changes. The relay-stays-on symptom requires an external trigger: user interaction with another device, a home automation hub reacting to WLED state changes, or (as a background amplifier) UDP packet loss leaving some nodes at bri=255.
Learnt from: softhack007
Repo: wled/WLED PR: 0
File: :0-0
Timestamp: 2026-05-09T16:33:20.041Z
Learning: In WLED branch 16_x, xLights auto-discovery (ArtPoll/ArtPollReply) is broken by a regression in wled00/src/dependencies/e131/ESPAsyncE131.cpp. A new packet length guard (`if (pktLen >= 16)`) was added around the E1.31 ACN_ID check, but ArtPoll packets are only 14 bytes. This causes ArtPoll packets to be misidentified as P_E131 instead of P_ARTNET, so handleArtnetPollReply() is never called and xLights receives no discovery reply.
Learnt from: softhack007
Repo: wled/WLED PR: 0
File: :0-0
Timestamp: 2026-05-18T21:46:16.718Z
Learning: In WLED issue `#5619`, the root cause of relay not turning off after HyperHDR stops was confirmed: the HyperHDR-controlled WLED node (Node A) correctly broadcasts bri=0 after exitRealtime(). However, with recv.bri=true and other WLED nodes on the same sync group that are independently ON (bri>0), any state change on those nodes after the 1-second notificationSentTime suppression window overwrites Node A's bri to non-zero, re-enabling the relay. The OS socket buffer stale-packet risk is NOT credible when WLED runs at 30fps realtime (fast loop drains the buffer continuously). The fix is to put the HyperHDR-controlled WLED in a separate sync group or disable recv.bri on it.
Learnt from: KrX3D
Repo: wled/WLED PR: 4585
File: usermods/seven_segment_display_reloaded_v2/seven_segment_display_reloaded_v2.cpp:3-5
Timestamp: 2026-02-18T00:11:02.403Z
Learning: In PR `#4585`, the seven_segment_display_reloaded_v2 usermod intentionally uses `#error` to require MQTT (`#ifdef WLED_DISABLE_MQTT `#error` "This user mod requires MQTT to be enabled." `#endif``) because the integration flow has not been tested or validated without MQTT, and failing fast at compile time is preferred over allowing potentially broken builds until a full MQTT-optional refactor is completed.
Now this doesn't look like a problem in the HA integration, but rather like a problem in the WLED firmware, because the effect (fx field) in the segments references an index that doesn't exist in the effects array.
Now this doesn't look like a problem in the HA integration, but rather like a problem in the WLED firmware, because the effect (fx field) in the segments references an index that doesn't exist in the effects array.
@mik-laj I agree the problem could be on WLED side - we already had a similar problem on 8266, where "/json/fxdata" did not fit into the internal JSON buffer on 8266 (this board has very little RAM)
This problem looks similar, however I don't know if the short "effects[] list in the large /json response is intentional. Maybe @willmmiles or @DedeHai know more.
@mikje please visit the page http://<DEVICE-IP>/json/eff and upload the result here. If we have a JSON buffer overflow, the /json/eff response should show more effects.
@coderabbitai please check if the /json response uses the global ArduinoJSON buffer for serialization. Estimate the ArduinoJSON capacity needed for #5674 (comment), and compare to the JSON_BUFFER_SIZE limit for esp8266.
#!/bin/bash# Find JSON_BUFFER_SIZE definition
rg -n "JSON_BUFFER_SIZE" --type=cpp -C2
# Find the /json endpoint handler
rg -n "\"json\"" wled00/ -C3
# Look for the serializeJson / global buffer usage in json.cpp
fd "json.cpp" wled00/ --exec grep -n "JSON_BUFFER\|global\|serializeJson\|DynamicJsonDocument\|StaticJsonDocument\|JsonDocument" {}
# Check for esp8266-specific buffer size
rg -n "esp8266\|8266" wled00/ --include="*.h" -C2 | grep -i "json\|buffer\|capacity" -i
Length of output: 6818
🏁 Script executed:
#!/bin/bash# More targeted search
rg -n "JSON_BUFFER_SIZE" -C3
rg -n "DynamicJsonDocument\|StaticJsonDocument\|JsonDocument" wled00/ -C2 | head -80
rg -n "serveJson\|serve_json\|URI.*json\|json.*URI\|/json" wled00/ -C2 | head -60
Length of output: 3018
🏁 Script executed:
#!/bin/bash# Find the full /json route handler and serveJson function
rg -n "serveJson\|/json\b" wled00/ -C3 | head -100
# Look at json.cpp for the main JSON serialization function
grep -n "serveJson\|json_target\|LockedJsonResponse\|requestJsonBufferLock\|serializeJson" wled00/json.cpp | head -60
# Get the portion of json.cpp that builds the full /json response (state + info + effects)
grep -n "state\|info\|effect\|subJson\|json_target" wled00/json.cpp | head -80
Length of output: 7129
🏁 Script executed:
#!/bin/bash# Estimate ArduinoJSON capacity needed for the mikje device JSON# The raw JSON from the comment (state + info + effects combined)
python3 << 'EOF'import json# The JSON data from mikje's comment (state portion)state_json = '''{"state":{"on":true,"bri":35,"transition":7,"bs":0,"ps":-1,"pl":-1,"ledmap":0,"AudioReactive":{"on":false},"nl":{"on":false,"dur":60,"mode":1,"tbri":0,"rem":-1},"udpn":{"send":false,"recv":true,"sgrp":1,"rgrp":1},"lor":0,"mainseg":0,"seg":[{"id":0,"start":0,"stop":12,"len":12,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"set":0,"lc":1,"col":[[255,160,0],[0,0,0],[0,0,0]],"fx":9,"sx":128,"ix":128,"pal":50,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0,"bm":0},{"id":1,"start":0,"stop":12,"len":12,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"set":0,"lc":1,"col":[[255,180,0],[0,0,0],[0,0,0]],"fx":88,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0,"bm":0},{"id":2,"start":1,"stop":12,"len":11,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"set":0,"lc":1,"col":[[255,180,0],[0,0,0],[0,0,0]],"fx":88,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0,"bm":0},{"id":3,"start":2,"stop":12,"len":10,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"set":0,"lc":1,"col":[[255,180,0],[0,0,0],[0,0,0]],"fx":88,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0,"bm":0},{"id":4,"start":3,"stop":12,"len":9,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"set":0,"lc":1,"col":[[255,180,0],[0,0,0],[0,0,0]],"fx":88,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0,"bm":0},{"id":5,"start":4,"stop":12,"len":8,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"set":0,"lc":1,"col":[[255,180,0],[0,0,0],[0,0,0]],"fx":88,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0,"bm":0},{"id":6,"start":5,"stop":12,"len":7,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"set":0,"lc":1,"col":[[255,180,0],[0,0,0],[0,0,0]],"fx":88,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0,"bm":0},{"id":7,"start":6,"stop":12,"len":6,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"set":0,"lc":1,"col":[[255,180,0],[0,0,0],[0,0,0]],"fx":88,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0,"bm":0},{"id":8,"start":7,"stop":12,"len":5,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"set":0,"lc":1,"col":[[255,180,0],[0,0,0],[0,0,0]],"fx":88,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0,"bm":0},{"id":9,"start":8,"stop":12,"len":4,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"set":0,"lc":1,"col":[[255,180,0],[0,0,0],[0,0,0]],"fx":88,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0,"bm":0},{"id":10,"start":9,"stop":12,"len":3,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"set":0,"lc":1,"col":[[255,180,0],[0,0,0],[0,0,0]],"fx":88,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0,"bm":0},{"id":11,"start":10,"stop":12,"len":2,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"set":0,"lc":1,"col":[[255,180,0],[0,0,0],[0,0,0]],"fx":88,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0,"bm":0},{"id":12,"start":11,"stop":12,"len":1,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"set":0,"lc":1,"col":[[255,180,0],[0,0,0],[0,0,0]],"fx":88,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0,"bm":0}]}}'''info_json = '''{"info":{"ver":"16.0.0","vid":2605030,"cn":"Niji","release":"ESP8266","repo":"wled/WLED","deviceId":"b26ccbf216c8f702609dfda784d9df087ef513ce5a","leds":{"count":12,"pwr":113,"fps":43,"maxpwr":1080,"maxseg":16,"bootps":8,"seglc":[1,1,1,1,1,1,1,1,1,1,1,1,1],"lc":1,"rgbw":false,"wv":0,"cct":0},"str":false,"name":"WLED_regenmini","udpport":21324,"simplifiedui":false,"live":false,"liveseg":-1,"lm":"","lip":"","ws":1,"fxcount":220,"palcount":72,"cpalcount":0,"umpalcount":0,"cpalmax":10,"maps":[{"id":0}],"wifi":{"bssid":"E4:38:83:72:9A:16","rssi":-58,"signal":84,"channel":1,"ap":false},"fs":{"u":57,"t":1024,"pmt":0},"ndc":2,"arch":"esp8266","core":"3.1.2","clock":80,"flash":4,"lwip":2,"freeheap":16936,"uptime":87170,"time":"1970-1-2, 00:12:50","um":[32],"u":{"AudioReactive":["<button class=\\"btn btn-xs\\" onclick=\\"requestJson({AudioReactive:{enabled:true}})\\"><i class=\\"icons off\\">&`#xe08f`;</i></button>"]},"opt":79,"brand":"WLED","product":"FOSS","mac":"e89f6d93f498","ip":"192.168.0.42"}}'''effects_json = '''{"effects":["Solid","Blink","Breathe","Wipe","Wipe Random","Random Colors","Sweep","Dynamic","Colorloop","Rainbow","Scan","Scan Dual","Fade","Theater","Theater Rainbow","Running","Saw","Twinkle","Dissolve","Dissolve Rnd","Sparkle","Sparkle Dark","Sparkle+","Strobe","Strobe Rainbow","Strobe Mega","Blink Rainbow","Android","Chase","Chase Random","Chase Rainbow","Chase Flash","Chase Flash Rnd","Rainbow Runner","Colorful","Traffic Light","Sweep Random","Chase 2","Aurora","Stream","Scanner","Lighthouse","Fireworks","Rain","Tetrix","Fire Flicker","Gradient","Loading","Rolling Balls","Fairy","Two Dots","Fairytwinkle","Running Dual","RSVD","Chase 3"]}'''# Raw JSON sizesstate_size = len(state_json.encode('utf-8'))info_size = len(info_json.encode('utf-8'))effects_size = len(effects_json.encode('utf-8'))total_raw = state_size + info_size + effects_sizeprint(f"Raw JSON sizes:")print(f" state: {state_size} bytes")print(f" info: {info_size} bytes")print(f" effects: {effects_size} bytes")print(f" total: {total_raw} bytes")# ArduinoJSON capacity estimation:# ArduinoJSON v6 uses a pool allocator. Each JSON value takes 16 bytes (on 32-bit),# each string key/value takes its string length + 1 byte (null terminator), rounded up to alignment.# The ArduinoJSON assistant formula: capacity = N_values * 16 + string_pool# Let's count values and strings# For ArduinoJSON v6 on 32-bit system:# JSON_OBJECT_SIZE(n) = n * 16 (roughly)# JSON_ARRAY_SIZE(n) = n * 16# String pool: each copied string (not flash string) uses len+1 rounded to pointer alignment# The /json response is one big object: {state:{...}, info:{...}, effects:[...]}# Count JSON nodes (objects, arrays, key-value pairs)# Count total nodes in the combined JSONdata_state = json.loads(state_json)data_info = json.loads(info_json)data_effects = json.loads(effects_json)def count_nodes(obj): """Count ArduinoJSON nodes needed.""" if isinstance(obj, dict): # object itself + each key-value pair total = 1 + len(obj) for v in obj.values(): total += count_nodes(v) return total elif isinstance(obj, list): total = 1 + len(obj) for item in obj: total += count_nodes(item) return total else: return 0def count_string_bytes(obj): """Estimate string pool bytes (keys + string values).""" total = 0 if isinstance(obj, dict): for k, v in obj.items(): # keys are usually stored in flash (PROGMEM) in WLED, but values are not total += len(k) + 1 # key if isinstance(v, str): total += len(v) + 1 else: total += count_string_bytes(v) elif isinstance(obj, list): for item in obj: if isinstance(item, str): total += len(item) + 1 else: total += count_string_bytes(item) return total# Merge into one top-level object as /json returnsfull = {}full.update(data_state)full.update(data_info)full.update(data_effects)nodes = count_nodes(full)str_bytes = count_string_bytes(full)# ArduinoJSON v6: each node = 16 bytes on 32-bitnode_overhead = nodes * 16# ArduinoJSON rounds string pool to 4-byte alignmentstr_aligned = ((str_bytes + 3) // 4) * 4estimated_capacity = node_overhead + str_alignedprint(f"\nArduinoJSON v6 capacity estimate (32-bit system):")print(f" JSON nodes: {nodes}")print(f" Node overhead: {node_overhead} bytes ({nodes} × 16 bytes)")print(f" String pool: {str_aligned} bytes")print(f" Estimated total: {estimated_capacity} bytes")print(f"\nComparison:")print(f" JSON_BUFFER_SIZE (esp8266): 10240 bytes")print(f" JSON_BUFFER_SIZE (ESP32S2): 24576 bytes")print(f" JSON_BUFFER_SIZE (ESP32): 32767 bytes")print(f" Buffer overflow on esp8266: {'YES' if estimated_capacity > 10240 else 'NO'} (by {estimated_capacity - 10240} bytes)")EOF
Length of output: 9956
@softhack007 Here is the full analysis:
1. Does /json use the global ArduinoJSON buffer?
Yes.serveJson() (json.cpp line 1301) acquires the global JSON buffer lock and creates a LockedJsonResponse backed by the global pDoc. On esp8266, pDoc points to gDoc — a StaticJsonDocument<JSON_BUFFER_SIZE> in SRAM (wled.h line 972), since the PSRAM path is guarded by #if defined(BOARD_HAS_PSRAM) which doesn't apply on 8266.
For json_target::all, the serialization order is:
serializeState(state) — state object (13 segments!)
serializeInfo(info) — info object
serializeModeNames(effects) — effects array added last (line 1371)
2. ArduinoJSON capacity estimate
Metric
Value
JSON nodes
799
Node overhead (799 × 16 bytes)
12,784 bytes
String pool
2,700 bytes
Estimated total needed
~15,484 bytes
JSON_BUFFER_SIZE on esp8266
10,240 bytes
Overflow
~5,244 bytes over limit
(For reference: ESP32S2 = 24,576 bytes, ESP32 = 32,767 bytes — no overflow on those.)
3. What actually happens: silent truncation of the effects array
ArduinoJSON silently stops adding elements when the pool is exhausted — it does not return an error. Since effects are serialized last, the effects array gets cut off mid-way. In mikje's response the list ends at index 54 ("Chase 3") instead of going to index 219. The device's own fxcount field correctly reports 220 effects, but the effects array in the same /json response only has 55.
Effect ID 88 falls well past index 54 → it is simply absent from the truncated list. This is why python-wled never builds a key for 88, and HA's effects[88] lookup throws KeyError: 88.
4. Conclusion
The root cause for this specific user is a JSON buffer overflow on esp8266, not the RSVD filter (the RSVD filter is a separate contributing issue for other users). This matches your intuition and is exactly analogous to #5461.
Visiting /json/eff (which uses the same global buffer but serializes only the effects array) should show all 220 effects without truncation, confirming the overflow theory.
✏️ Learnings added
Learnt from: softhack007
URL: https://github.com/wled/WLED/issues/5674
Timestamp: 2026-06-09T17:11:47.664Z
Learning: In WLED issue `#5674`, a KeyError: 88 in HA's wled/light.py was traced to an esp8266 JSON buffer overflow. On esp8266, JSON_BUFFER_SIZE is 10,240 bytes (const.h). The /json endpoint (serveJson(), json.cpp) uses the global StaticJsonDocument<JSON_BUFFER_SIZE> gDoc on esp8266 (no PSRAM). For json_target::all it serializes state + info + effects in sequence. With 13 segments, the estimated ArduinoJSON capacity needed (~15,484 bytes) exceeds the 10 KB limit by ~5,244 bytes. ArduinoJSON silently truncates — the effects array was cut at index 54 ("Chase 3") instead of 219. Effect ID 88, actively used by 12 segments, was simply absent from the truncated list, causing python-wled to never register key 88 and HA to crash. This is analogous to issue `#5461`.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
changed the title [-]Errors in Home assistant integration[/-][+]Errors in Home assistant integration on ESP8266 (possibly caused by /json response buffer overflow)[/+]on Jun 9, 2026
I have drafted a fix on the library side to work around this issue. Is there anything else I should pay attention to?
@mik-laj 👍
Make sure that palette names are also retrieved separately from /json/palettes (or /json/palx ?). Normally the /json response includes info, segments, state, effect names and palette names. However, if the buffer truncates, palettes will also be missing because they are appended after effect names.
#5461 was a targeted patch that addressed one specific endpoint. I'd missed that the list was also being truncated on the other endpoints that aren't used by our web interface.
The new approach still needs to be applied to more of the endpoints. I'd got started on it, but ended up getting sidetracked by a different project. I can move this one back up my priority queue.
Activity
softhack007 commentedon Jun 8, 2026
@coderabbitai please analyze the homeassistant log file, and compare it to the code of the wled integration. Summarize what may cause the error showing in the log.
softhack007 commentedon Jun 8, 2026
@mik-laj could this be related to recent changes in the HA integration for OTA updates, or maybe segment related changes? It does not look like a WLED problem, as wled is not written in python.
mik-laj commentedon Jun 8, 2026
This is related to the recent change that excludes effects named RSVD. I'll be preparing a fix today.
mik-laj commentedon Jun 8, 2026
Here is related commit: frenck/python-wled@1a2a6d9
coderabbitai commentedon Jun 8, 2026
🧩 Analysis chain
🏁 Script executed:
Length of output: 5292
🏁 Script executed:
Length of output: 4747
@softhack007Here is the analysis:Root Cause:
KeyError: 88inwled/light.pyWhat the log shows:
The traceback terminates at this line in
homeassistant/components/wled/light.py:The segment reports
effect_id = 88, but key88no longer exists in theeffectsdict →KeyError: 88.Why key 88 disappeared — the commit
1a2a6d91The linked commit in
frenck/python-wledadded an RSVD filter to the effects dict-comprehension in two places (__pre_deserialize__andupdate_from_dict):WLED firmware uses
"RSVD"as placeholder names for unallocated effect slots to keep array indices stable. Effect ID 88 in this user's build happens to be one of those placeholders. The filter correctly removes them from the exposed effect list — but it creates a gap in the dict (keys like 88 are simply absent now).The mismatch
effect_id = 88for the active segment (the segment was left at a RSVD slot)python-wled(after fix)effectsdict without key88light.pyeffects[88]lookup — no.get()fallback — and crashesFix direction (which mik-laj is already working on)
The HA
light.py(orpython-wledmodel layer) needs to handle a segment whoseeffect_idpoints to a now-filtered-out slot. The minimal safe fix inlight.pywould be:A more complete fix in
python-wledcould additionally remap RSVDeffect_ids in the segment state to the next valid effect (mirroring what the WLED web UI does when a RSVD slot is active), but the.get()guard inlight.pyis the critical defensive fix to stop the crash.🧠 Learnings used
mik-laj commentedon Jun 8, 2026
@mikje Can you share diagnostics data for this device and device state?
Here is docs about diagnostics data:
https://www.home-assistant.io/integrations/diagnostics/#downloading-diagnostics
To get device data, you need to visit the page
http://<DEVICE-IP>/json.I'm wondering how you managed to set up an effect that has an ID identical to the RSVP effect.
mikje commentedon Jun 9, 2026
{"state":{"on":true,"bri":35,"transition":7,"bs":0,"ps":-1,"pl":-1,"ledmap":0,"AudioReactive":{"on":false},"nl":{"on":false,"dur":60,"mode":1,"tbri":0,"rem":-1},"udpn":{"send":false,"recv":true,"sgrp":1,"rgrp":1},"lor":0,"mainseg":0,"seg":[{"id":0,"start":0,"stop":12,"len":12,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"set":0,"lc":1,"col":[[255,160,0],[0,0,0],[0,0,0]],"fx":9,"sx":128,"ix":128,"pal":50,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0,"bm":0},{"id":1,"start":0,"stop":12,"len":12,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"set":0,"lc":1,"col":[[255,180,0],[0,0,0],[0,0,0]],"fx":88,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0,"bm":0},{"id":2,"start":1,"stop":12,"len":11,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"set":0,"lc":1,"col":[[255,180,0],[0,0,0],[0,0,0]],"fx":88,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0,"bm":0},{"id":3,"start":2,"stop":12,"len":10,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"set":0,"lc":1,"col":[[255,180,0],[0,0,0],[0,0,0]],"fx":88,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0,"bm":0},{"id":4,"start":3,"stop":12,"len":9,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"set":0,"lc":1,"col":[[255,180,0],[0,0,0],[0,0,0]],"fx":88,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0,"bm":0},{"id":5,"start":4,"stop":12,"len":8,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"set":0,"lc":1,"col":[[255,180,0],[0,0,0],[0,0,0]],"fx":88,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0,"bm":0},{"id":6,"start":5,"stop":12,"len":7,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"set":0,"lc":1,"col":[[255,180,0],[0,0,0],[0,0,0]],"fx":88,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0,"bm":0},{"id":7,"start":6,"stop":12,"len":6,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"set":0,"lc":1,"col":[[255,180,0],[0,0,0],[0,0,0]],"fx":88,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0,"bm":0},{"id":8,"start":7,"stop":12,"len":5,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"set":0,"lc":1,"col":[[255,180,0],[0,0,0],[0,0,0]],"fx":88,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0,"bm":0},{"id":9,"start":8,"stop":12,"len":4,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"set":0,"lc":1,"col":[[255,180,0],[0,0,0],[0,0,0]],"fx":88,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0,"bm":0},{"id":10,"start":9,"stop":12,"len":3,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"set":0,"lc":1,"col":[[255,180,0],[0,0,0],[0,0,0]],"fx":88,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0,"bm":0},{"id":11,"start":10,"stop":12,"len":2,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"set":0,"lc":1,"col":[[255,180,0],[0,0,0],[0,0,0]],"fx":88,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0,"bm":0},{"id":12,"start":11,"stop":12,"len":1,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"set":0,"lc":1,"col":[[255,180,0],[0,0,0],[0,0,0]],"fx":88,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0,"bm":0}]},"info":{"ver":"16.0.0","vid":2605030,"cn":"Niji","release":"ESP8266","repo":"wled/WLED","deviceId":"b26ccbf216c8f702609dfda784d9df087ef513ce5a","leds":{"count":12,"pwr":113,"fps":43,"maxpwr":1080,"maxseg":16,"bootps":8,"seglc":[1,1,1,1,1,1,1,1,1,1,1,1,1],"lc":1,"rgbw":false,"wv":0,"cct":0},"str":false,"name":"WLED_regenmini","udpport":21324,"simplifiedui":false,"live":false,"liveseg":-1,"lm":"","lip":"","ws":1,"fxcount":220,"palcount":72,"cpalcount":0,"umpalcount":0,"cpalmax":10,"maps":[{"id":0}],"wifi":{"bssid":"E4:38:83:72:9A:16","rssi":-58,"signal":84,"channel":1,"ap":false},"fs":{"u":57,"t":1024,"pmt":0},"ndc":2,"arch":"esp8266","core":"3.1.2","clock":80,"flash":4,"lwip":2,"freeheap":16936,"uptime":87170,"time":"1970-1-2, 00:12:50","um":[32],"u":{"AudioReactive":["<button class=\"btn btn-xs\" onclick=\"requestJson({AudioReactive:{enabled:true}});\"><i class=\"icons off\"></i></button>"]},"opt":79,"brand":"WLED","product":"FOSS","mac":"e89f6d93f498","ip":"192.168.0.42"},"effects":["Solid","Blink","Breathe","Wipe","Wipe Random","Random Colors","Sweep","Dynamic","Colorloop","Rainbow","Scan","Scan Dual","Fade","Theater","Theater Rainbow","Running","Saw","Twinkle","Dissolve","Dissolve Rnd","Sparkle","Sparkle Dark","Sparkle+","Strobe","Strobe Rainbow","Strobe Mega","Blink Rainbow","Android","Chase","Chase Random","Chase Rainbow","Chase Flash","Chase Flash Rnd","Rainbow Runner","Colorful","Traffic Light","Sweep Random","Chase 2","Aurora","Stream","Scanner","Lighthouse","Fireworks","Rain","Tetrix","Fire Flicker","Gradient","Loading","Rolling Balls","Fairy","Two Dots","Fairytwinkle","Running Dual","RSVD","Chase 3"]}mikje commentedon Jun 9, 2026
config_entry-wled-01JMAEAFDKE41E06ARNY7VC3T6.json
softhack007 commentedon Jun 9, 2026
I'm wondering why the
"effects":[list from/jsonends with"Chase 3"🤔 @willmmiles is this expected on 8266?mik-laj commentedon Jun 9, 2026
[ { "name": "Solid", "index": 0 }, { "name": "Blink", "index": 1 }, { "name": "Breathe", "index": 2 }, { "name": "Wipe", "index": 3 }, { "name": "Wipe Random", "index": 4 }, { "name": "Random Colors", "index": 5 }, { "name": "Sweep", "index": 6 }, { "name": "Dynamic", "index": 7 }, { "name": "Colorloop", "index": 8 }, { "name": "Rainbow", "index": 9 }, { "name": "Scan", "index": 10 }, { "name": "Scan Dual", "index": 11 }, { "name": "Fade", "index": 12 }, { "name": "Theater", "index": 13 }, { "name": "Theater Rainbow", "index": 14 }, { "name": "Running", "index": 15 }, { "name": "Saw", "index": 16 }, { "name": "Twinkle", "index": 17 }, { "name": "Dissolve", "index": 18 }, { "name": "Dissolve Rnd", "index": 19 }, { "name": "Sparkle", "index": 20 }, { "name": "Sparkle Dark", "index": 21 }, { "name": "Sparkle+", "index": 22 }, { "name": "Strobe", "index": 23 }, { "name": "Strobe Rainbow", "index": 24 }, { "name": "Strobe Mega", "index": 25 }, { "name": "Blink Rainbow", "index": 26 }, { "name": "Android", "index": 27 }, { "name": "Chase", "index": 28 }, { "name": "Chase Random", "index": 29 }, { "name": "Chase Rainbow", "index": 30 }, { "name": "Chase Flash", "index": 31 }, { "name": "Chase Flash Rnd", "index": 32 }, { "name": "Rainbow Runner", "index": 33 }, { "name": "Colorful", "index": 34 }, { "name": "Traffic Light", "index": 35 }, { "name": "Sweep Random", "index": 36 }, { "name": "Chase 2", "index": 37 }, { "name": "Aurora", "index": 38 }, { "name": "Stream", "index": 39 }, { "name": "Scanner", "index": 40 }, { "name": "Lighthouse", "index": 41 }, { "name": "Fireworks", "index": 42 }, { "name": "Rain", "index": 43 }, { "name": "Tetrix", "index": 44 }, { "name": "Fire Flicker", "index": 45 }, { "name": "Gradient", "index": 46 }, { "name": "Loading", "index": 47 }, { "name": "Rolling Balls", "index": 48 }, { "name": "Fairy", "index": 49 }, { "name": "Two Dots", "index": 50 }, { "name": "Fairytwinkle", "index": 51 }, { "name": "Running Dual", "index": 52 }, { "name": "RSVD", "index": 53 }, { "name": "Chase 3", "index": 54 } ]Now this doesn't look like a problem in the HA integration, but rather like a problem in the WLED firmware, because the effect (
fxfield) in the segments references an index that doesn't exist in theeffectsarray.softhack007 commentedon Jun 9, 2026
@mik-laj I agree the problem could be on WLED side - we already had a similar problem on 8266, where "/json/fxdata" did not fit into the internal JSON buffer on 8266 (this board has very little RAM)
This problem looks similar, however I don't know if the short
"effects[]list in the large /json response is intentional. Maybe @willmmiles or @DedeHai know more.@mikje please visit the page
http://<DEVICE-IP>/json/effand upload the result here. If we have a JSON buffer overflow, the/json/effresponse should show more effects.softhack007 commentedon Jun 9, 2026
@coderabbitai please check if the /json response uses the global ArduinoJSON buffer for serialization. Estimate the ArduinoJSON capacity needed for #5674 (comment), and compare to the
JSON_BUFFER_SIZElimit for esp8266.coderabbitai commentedon Jun 9, 2026
🧩 Analysis chain
🏁 Script executed:
Length of output: 6818
🏁 Script executed:
Length of output: 3018
🏁 Script executed:
Length of output: 7129
🏁 Script executed:
Length of output: 9956
@softhack007Here is the full analysis:1. Does
/jsonuse the global ArduinoJSON buffer?Yes.
serveJson()(json.cppline 1301) acquires the global JSON buffer lock and creates aLockedJsonResponsebacked by the globalpDoc. On esp8266,pDocpoints togDoc— aStaticJsonDocument<JSON_BUFFER_SIZE>in SRAM (wled.hline 972), since the PSRAM path is guarded by#if defined(BOARD_HAS_PSRAM)which doesn't apply on 8266.For
json_target::all, the serialization order is:serializeState(state)— state object (13 segments!)serializeInfo(info)— info objectserializeModeNames(effects)— effects array added last (line 1371)2. ArduinoJSON capacity estimate
JSON_BUFFER_SIZEon esp8266(For reference: ESP32S2 = 24,576 bytes, ESP32 = 32,767 bytes — no overflow on those.)
3. What actually happens: silent truncation of the effects array
ArduinoJSON silently stops adding elements when the pool is exhausted — it does not return an error. Since effects are serialized last, the effects array gets cut off mid-way. In mikje's response the list ends at index 54 (
"Chase 3") instead of going to index 219. The device's ownfxcountfield correctly reports 220 effects, but the effects array in the same/jsonresponse only has 55.Effect ID 88 falls well past index 54 → it is simply absent from the truncated list. This is why python-wled never builds a key for 88, and HA's
effects[88]lookup throwsKeyError: 88.4. Conclusion
The root cause for this specific user is a JSON buffer overflow on esp8266, not the RSVD filter (the RSVD filter is a separate contributing issue for other users). This matches your intuition and is exactly analogous to
#5461.Visiting
/json/eff(which uses the same global buffer but serializes only the effects array) should show all 220 effects without truncation, confirming the overflow theory.✏️ Learnings added
coderabbitai commentedon Jun 9, 2026
[-]Errors in Home assistant integration[/-][+]Errors in Home assistant integration on ESP8266 (possibly caused by /json response buffer overflow)[/+]DedeHai commentedon Jun 9, 2026
@softhack007 IIRC the effects list was split up into multiple packets which works in the UI but may break HA API call
mik-laj commentedon Jun 9, 2026
What specifically do you have in mind? Is there anything we can implement on the library side to work around this issue?
mik-laj commentedon Jun 10, 2026
I have drafted a fix on the library side to work around this issue. Is there anything else I should pay attention to?
https://github.com/frenck/python-wled/pull/2083/changes
DedeHai commentedon Jun 10, 2026
Nothing specific, @willmmiles made some improvements to work around the json buffer limit but I am unaware of the exact inner workings
softhack007 commentedon Jun 11, 2026
@mik-laj 👍
Make sure that palette names are also retrieved separately from
/json/palettes(or/json/palx?). Normally the/jsonresponse includes info, segments, state, effect names and palette names. However, if the buffer truncates, palettes will also be missing because they are appended after effect names.WLED/wled00/json.cpp
Lines 1362 to 1373 in d8e3578
willmmiles commentedon Jun 11, 2026
Sorry I'm late getting to this...
#5461 was a targeted patch that addressed one specific endpoint. I'd missed that the list was also being truncated on the other endpoints that aren't used by our web interface.
The new approach still needs to be applied to more of the endpoints. I'd got started on it, but ended up getting sidetracked by a different project. I can move this one back up my priority queue.