[BUG] Powered Off Lights Display Wrong Color When Scene is Set
Describe the bug
While using the HomeKit app on iPhone, if a scene activates a light with firmware version 2,3,4,5, or 8, it turns on the wrong color / brightness. This only occurs with scenes.
To Reproduce
Steps to reproduce the behavior:
- In the HomeKit app, create a scene that sets the color and brightness of a light
- Turn that light off
- Run the scene
- Observe that the light has the wrong color
Expected behavior
When running the scene, the light should both turn on and display the correct brightness / color.
Possible causes
-
A race condition may still be occurring where the color command is sent before the power command. This was not an issue before as we relayed commands from HomeKit to the lights as they came in to Homebridge. Now that we are waiting for all commands before sending, this race condition is occurring. The color command is sent, but falls on deaf ears as the MagicHome light will not accept any commands while in an 'off' state, then, the on command is sent and the MagicHome light turns on the last color data it received.
-
Somehow white color data is not being sent to the device, only RGB color data.
Possible Solutions
- Add a delay between the 'power on' command and the 'color' command
Test Cases
Run some test cases to help narrow down the possible source of the issue
-
Add a few scenes including an 'off' scene and a few color scenes. Alternate between these 'off' and color scenes e.g. off>red scene > off > blue + CCT scene > off > green scene > off > red scene. See if there is a pattern.
-
Try to get the error to occur when the light is already in a 'powered on' state.
Needed debug statements
- Output the name and exact order of commands being sent
- Output color data being sent
To clarify, in my case it happens when the scene is triggered by an automation, if you run the scene manually it's fine.