P2930 — WiFi/local coverage + Tuya protocol versions (LAN and Zigbee)
Written in our own words. No source code copied.
Sources studied (credits)
| Source | Author / ID | Link | Used for |
|---|---|---|---|
| tuya-local | make-all (Jason Rumney), MIT, commit 95300d05ac | https://github.com/make-all/tuya-local | product_id → DP schemas (data/wifi/tuya-local-product-schemas.json, generated by scripts/data/build-tuya-local-schemas.js) |
| tinytuya | jasonacox, MIT | https://github.com/jasonacox/tinytuya | 3.1–3.5 framing, the 3.22 "device22" alias, wizard devices.json/snapshot.json format, UPDATEDPS (18) |
| tuyapi | codetheweb, MIT | https://github.com/codetheweb/tuyapi | CONTROL vs CONTROL_NEW, DP_QUERY_NEW on 3.4/3.5 |
| localtuya | rospogrigio + xZetsubou fork, GPL-3.0, study only | https://github.com/rospogrigio/localtuya, https://github.com/xZetsubou/hass-localtuya | single-client limit, DP auto-config idea, sub-device cid |
| tuya-convert | ct-Open-Source, MIT | https://github.com/ct-Open-Source/tuya-convert | discovery ports 6666/6667 background (no code) |
| ha_tuya_ble | PlusPlus-ua | https://github.com/PlusPlus-ua/ha_tuya_ble | BLE protocol versions are separate from LAN |
zigbee-herdsman-converters src/lib/tuya.ts | Koenkk, MIT | https://github.com/Koenkk/zigbee-herdsman-converters | EF00 command ids, appVersion bit layout |
| Tuya developer docs | Tuya | https://developer.tuya.com | pv/bv labels, MCU serial protocol, EF00 commands |
| Homey topic 154077 "Tuya Local" | community | https://community.homey.app/t/154077 | earlier field reports (P2700) |
Johan's Homey apps, Athom's Tuya cloud app, Tasmota and OpenBeken templates: already covered by earlier study notes (docs/automation/localtuya-study.md); nothing new taken this pass.
What is added
TuyaProtocolVersions.js: 3.1/3.2/3.3/3.4/3.5 documented;3.22= 3.3 + device22;1.x/2.x= cloud/firmware labels (pv/bv), not LAN, so the documented chain is probed; unknown3.x(e.g. 3.6) = lead, probes documented versions only. Chain = declared → neighbours → probe order. Frame detection: 0x6699 → 3.5, 0x55AA + ASCII tag → 3.x. Wired intobuildProtocolFallbackChain.TuyaCommandPlan.js: CONTROL(7) vs CONTROL_NEW(13), DP_QUERY(10)/DP_QUERY_NEW(16)/device22, bounded UPDATEDPS(18) payload, cid wrapping for gateway sub-devices.TinyTuyaImport.js: tinytuya wizard import, gateway children inherit the gateway key/ip.LocalConnectionGate.js: one LAN session per device id (wired intoTuyaLocalClient.connect/destroy).TuyaLocalClient: live queue capped at 64, "socket hang up"/ECONNABORTED/ETIMEDOUT now retried (max 2).WiFiDPRegistry: tuya-local schemas (1 908 exact product ids, 1 463 schemas, 21 capabilities), lazy read, only the rows looked up are cached (max 64);GenericDpAutoMapper(high confidence only, opt-in viaobservedDps).lib/tuya/TuyaZigbeeProtocolProfile.js: EF00 commands (0x01/02/03/04/05/06/0B/10/11/12/24/25), DP types, appVersion decoding, mfr-prefix generations (_TZ3000/_TZ3210/_TZ3290/_TYZB01 ZCL; _TZE200/_TZE204/_TZE284/_TZE600/_TYST11 EF00), profile 0x0104 (3.0 vs HA 1.2 decided by zclVersion), DP frame parser chain standard → short_len → lead. Native stays first in every chain.
Remaining
- Zigbee profile and generic mapper are not wired into the device runtime yet (pure modules + tests).
- Enum-backed tuya-local binary sensors skipped (need a value table).
- MCU serial and BLE versions are documented only (not a LAN or Zigbee path for us).
P2931 follow-up (2026-10-21)
- Zigbee profile wired as an optional overlay (
lib/tuya/TuyaZigbeeProfileOverlay.js): attached inTuyaZigbeeDevice.onNodeInit, one deferred Basic read (45-75 s, failure tolerated), passive EF00 listeners, store valuetuya_zb_profile, detached in onUninit/onDeleted. Native handling unchanged. - Generic auto-mapper wired in
TuyaLocalDevice._onData(once, high confidence, only capabilities the device already has). - Enum binary sensors from tuya-local: exact
dps_valmeaning true kept (on), applied viatransform(66 rows). - Catalog compaction: identical schemas stored once (689 unique for 1467 configs). File 247 535 B -> 166 589 B (gzip 48 667 B). Products 1 912.
- Audit: UDP discovery (ports 6666/6667/6668/7000, reuseAddr, 6699/ECB/raw-GCM cascade) OK; gaps fixed: device table bounded to 256, raw version label kept, 3.22 alias resolved. Active scan (TCP 6668, bounded concurrency) OK, no change. Manual IP: added normalisation (port suffix, spaces, invalid/broadcast IP, v3.x / 3.22 / 2.x labels, key spacing) in manual_add, repair configure and update_credentials.
P2932-P2934 (2026-10-21)
- Gateway sub-devices:
TuyaGatewayHubshares one gateway client (single LAN session), channels per cid;TuyaLocalClient.setSubDP/setSubDPs/refreshSubpasscidto tuyapi;dp-update-cidroutes reports. Used byTuyaLocalDevicewhen settings carrycid(ornode_id) +gateway_id(optionalgateway_local_key/gateway_ip/gateway_protocol_version). - MCU/time (
lib/tuya/TuyaMcuTimeService.js, sources: Z2M tuya.ts MIT, ZHA tuya quirks Apache-2.0, deCONZ tuya.cpp BSD-3, ZCL 3.12): 0x24 answer = size(2)+UTC(4 BE)+local(4 BE), Homey timezone with DST via Intl, epoch 2000 list kept; 0x25 answered "connected"; 0x10/0x11 version request once + decode; 0x12 = lead + wake; 0x28 and E000/E001 time-like frames = leads (no documented source); ZCL Time 0x000A server (lib/zigbee/TimeServerBoundCluster.js) bound only if free. - Wake: any frame from a battery/sleepy node, pollControl check-in, MCU-initiated 0x10, rejoin → flush pending writes (≤20, latest per label, failures kept) then time push (30 min per device; remotes flush only). Request throttle 10 s. Rejoin: DP re-query 0x03 (≤4/h). Bounded diag
tuya_time_sync_diag(20). - DP parsing variant: short-length layout used only after both standard parses fail and the buffer is consumed exactly.
- Never duplicates: request answers skip when TuyaEF00Manager/_respondToTimeSyncRequest already exists.