Skip to content

Read the live API client count for the RGB status LED - #80

Merged
ptr727 merged 1 commit into
developfrom
fix/rgb-led-status-api-latch
Aug 6, 2026
Merged

ptr727 merged 1 commit into
developfrom
fix/rgb-led-status-api-latch

Conversation

@ptr727

@ptr727 ptr727 commented Aug 6, 2026

Copy link
Copy Markdown
Owner

The status LED on a deployed proxy sat white while Home Assistant held an unbroken API connection and every entity was live.

The connected color was driven by an api_ok global, set in on_client_connected and cleared in on_client_disconnected. The API server accepts max_connections clients, 5 by default, so any one of them disconnecting cleared the flag for all of them. Nothing re-evaluated while Home Assistant stayed connected, so the LED latched white until some new client happened to connect.

The api.connected condition reads APIServer::is_connected(), the live connection count, so it cannot be wrong about a client that is still there. Upstream fires the disconnect trigger after removing the client, so the condition reads the true state from inside it. The two triggers stay, but only to re-run the script.

Verification

esphome config passes for every consumer of the template: both Bluetooth proxies, the HVAC compressor sensor, and the eight test/ devices whose board templates include it.

The fix is flashed to the office proxy. With one log client attached alongside Home Assistant, a second client was connected and then disconnected. The disconnect fires the trigger and re-drives the LED green, 0% / 100% / 10%, because two clients remain. Before the change the same sequence set it white, 70% / 70% / 70%.

The connected color latched a boolean that any one of the API server's
client slots could clear, so a second client disconnecting left the LED
white while Home Assistant was still connected and reporting the device
online.

The api.connected condition reads the live connection count instead.
Upstream fires the disconnect trigger after removing the client, so the
condition sees the true state from inside it.
Copilot AI lite review requested due to automatic review settings August 6, 2026 12:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes incorrect RGB status LED behavior when multiple API clients are connected by switching from a latched api_ok global to ESPHome’s live api.connected condition, preventing the LED from falsely turning white when any one client disconnects.

Changes:

  • Remove the api_ok global and re-drive the LED status script based on api.connected.
  • Keep API connect/disconnect triggers solely to re-run the LED evaluation script.
  • Document the multi-client API caveat and the “read live, don’t latch” rule in OPERATIONS.md.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
templates/rgb-led-status.yaml Replace latched API state with live api.connected and keep triggers to re-evaluate LED status.
OPERATIONS.md Add operational guidance explaining why API connection state must be read live and link to the connection-cap section.

Comment thread OPERATIONS.md
@ptr727
ptr727 merged commit ff1cc89 into develop Aug 6, 2026
3 checks passed
@ptr727
ptr727 deleted the fix/rgb-led-status-api-latch branch August 6, 2026 12:28
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