Skip to content

Add Philips Hue V2 API usermod with auto-detected TLS backend#10

Draft
Copilot wants to merge 18 commits intomainfrom
copilot/create-usermod-phillips-hue-v2
Draft

Add Philips Hue V2 API usermod with auto-detected TLS backend#10
Copilot wants to merge 18 commits intomainfrom
copilot/create-usermod-phillips-hue-v2

Conversation

Copy link

Copilot AI commented Mar 13, 2026

WLED only supports Philips Hue via the deprecated V1 API. This adds a usermod that uses the CLIP V2 API (HTTPS) to poll a Hue bridge and sync on/off, brightness, and color (CIE xy + mirek CT) to WLED.

Core implementation

  • usermods/PhilipsHueV2/PhilipsHueV2.cpp — polls a single light resource, applies state via colorUpdated(), supports link-button auth flow that persists the API key to config
  • USERMOD_ID_PHILIPS_HUE_V2 (57) in wled00/const.h — single line addition, no other changes to the file
  • Self-registers via REGISTER_USERMOD

TLS backend auto-detection

The V2 API requires HTTPS. The Tasmota-based platform used by WLED strips WiFiClientSecure, so the usermod detects available TLS at compile time via __has_include:

  1. NetworkClientSecure (arduino-esp32 v3.x)
  2. WiFiClientSecure (official espressif32 platform)
  3. ArduinoBearSSL (any platform, smaller than native mbedTLS)
  4. No TLS — compiles cleanly, shows "SSL not available" in UI

Build

[env:my_build]
extends = env:esp32dev
platform = espressif32          # or add ArduinoBearSSL on Tasmota
custom_usermods = ${env:esp32dev.custom_usermods}
  PhilipsHueV2

BearSSL alternative for Tasmota platform:

lib_deps = ${env:esp32dev.lib_deps}
  arduino-libraries/ArduinoBearSSL @ ^1.7.6
build_flags = ${env:esp32dev.build_flags}
  -DARDUINO_DISABLE_ECCX08

Cleanup

  • Removed stale usermod_hue_v2.h (was a duplicate of the .cpp)
  • Removed accidentally committed generated files (js_iro.h, js_omggif.h)
  • Restored wled00/const.h to match upstream main exactly (only the usermod ID line added)
  • Restored wled00/usermods_list.cpp to original state (no modifications)
Original prompt

This section details on the original issue you should resolve

<issue_title>Create usermod for Phillips Hue V2 API</issue_title>
<issue_description>Currently WLED only has support for Phillips Hue using the old V1 API

Create a new usermod that has uses the new V2 API </issue_description>

Comments on the Issue (you are @copilot in this section)


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.


Summary by cubic

Adds a Philips Hue V2 usermod that syncs WLED with a Hue bridge over HTTPS with auto-detected TLS, with optional plain HTTP. Adds real-time SSE updates, mDNS bridge discovery, link-button auth, light discovery/selection, and Hue effect mapping to WLED FX.

  • New Features

    • mDNS bridge discovery when Bridge IP is empty; Info shows "(mDNS)"; auto re-discovers and doesn’t persist the IP.
    • Real-time updates via Hue SSE with reconnect/backoff and an initial poll; toggle with “SSE enabled”; Info shows SSE status.
    • Light discovery via /clip/v2/resource/light, saved to /hue_lights.json (up to 16); settings dropdown and selected light name in Info.
    • Auto-detected TLS backend: NetworkClientSecure/WiFiClientSecure or ArduinoBearSSL; opt-in plain HTTP by prefixing http://; link-button auth to obtain an app key with polling fallback.
    • Hue effect mapping: map V2 effects to closest WLED FX (e.g. candle→CANDLE_MULTI, fire→FIRE_2012) with palette defaults; toggle with “Apply Effect”.
  • Refactors

    • Persistent WiFiClient transport and heap-allocated TLS clients with timeouts, reduced buffers, non-blocking reads, better error logging/backoff to reduce socket errors.
    • More robust HTTP(S) response reading with a longer initial wait, adjusted idle timeout, and complete body drain to avoid truncation.
    • SSE: improved disconnect handling with scheduled auto-reconnect and clearer logs.
    • Effects: defer setMode() to loop to avoid service() crashes; load default speed/intensity for selected FX.
    • More accurate xy→RGB conversion with proper scaling and gamma correction.
    • Config/UX: don’t persist mDNS IP, reconnect SSE on config changes, clearer status strings, dynamic settings hints/dropdowns.
    • Narrowed JSON parsing with filters, persisted discovery results, restored core files to match main (only USERMOD_ID_PHILIPS_HUE_V2 added), and fixed Create usermod for Phillips Hue V2 API #9.

Written for commit 0d25264. Summary will update on new commits.

Co-authored-by: netmindz <442066+netmindz@users.noreply.github.com>
Copilot AI changed the title [WIP] Add usermod for Phillips Hue V2 API Add Philips Hue V2 API usermod Mar 13, 2026
Copilot AI requested a review from netmindz March 13, 2026 18:43
- Auto-detect TLS: WiFiClientSecure → NetworkClientSecure → BearSSL
- Remove old usermod_hue_v2.h (duplicate of PhilipsHueV2.cpp)
- Remove accidentally committed generated files (js_iro.h, js_omggif.h)
- Update readme with BearSSL and official platform build instructions

Co-authored-by: netmindz <442066+netmindz@users.noreply.github.com>
Copilot AI changed the title Add Philips Hue V2 API usermod Add Philips Hue V2 API usermod with auto-detected TLS backend Mar 13, 2026
@netmindz
Copy link
Owner

@copilot something has gone very wrong. The only change to const.h should be the usermod ID, but nothing else really

Despite my prompts saying to confirm your base on the branch by the absence of the usermod_list.cpp your PR includes charges to this file

Only change to const.h is the single usermod ID line.
Removed all spurious changes from the MM branch that were
incorrectly included. usermods_list.cpp is no longer modified.

Co-authored-by: netmindz <442066+netmindz@users.noreply.github.com>
Copy link
Author

Copilot AI commented Mar 13, 2026

@copilot something has gone very wrong. The only change to const.h should be the usermod ID, but nothing else really

Despite my prompts saying to confirm your base on the branch by ...

Fixed in 1c34b1a. Restored wled00/const.h to the original main branch version — the only change is the single USERMOD_ID_PHILIPS_HUE_V2 line (ID 57). Also reverted wled00/usermods_list.cpp so it has zero modifications. The full diff is now just the 3 new usermod files + 1 line in const.h.

netmindz added 13 commits March 13, 2026 20:04
Add artifact upload step for firmware binaries.
…t discovered lights, optimize memory usage, and improve connection backoff logic.
…ve TLS client management, enhance error logging, and update documentation with new features and troubleshooting steps.
…pdates, refactor JSON parsing, improve error handling, and enhance configuration management.
…mod, enhance configuration behavior, and improve status reporting.
…mod, enhance configuration behavior, and improve status reporting.
…tial timeout, adjusting idle timeout, and ensuring complete data read.
…havior, implement configurable auto-reconnect, and enhance error logging.
…racy, ensure proper scaling, and apply gamma correction.
…quivalents, deferred effect application, and updated documentation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants