Open Erriez opened 3 years ago
Removing the commented optimization below looks like a workaround in lib/MiLightState/GroupState.cpp
:
bool GroupState::setState(const MiLightStatus status) {
//if (!isNightMode() && isSetState() && getState() == status) {
// return false;
//}
setDirty();
...
In this case the state topic is always sent, even when MiLight-Hub thinks there is no light change. Then both Homeassistant and MiLighthub becomes in sync about every light state and the light button does not flip back.
Can someone review this proposal? Then I'm happy to create a pull request.
Nice, noticed this bug also... not always. Only when reboot HA and my lights went on even when they where off in HA Maybe this happen because of above issue.
Nice, noticed this bug also... not always. Only when reboot HA and my lights went on even when they where off in HA Maybe this happen because of above issue.
You can give it a try to open the MiLight-Hub
project in VCode, comment the lines in my previous comment and flash it to the board.
Yesterday I noticed that Homeassistant also contains a Scene optimization that it won't send a light state when it thinks the light is already in a specific state. This also results in lights out of sync after a restart or missing packets. I'm not sure if this optimization can be disabled. Switching to another scene is only reliable when all lights are always refreshed.
Nice, noticed this bug also... not always. Only when reboot HA and my lights went on even when they where off in HA Maybe this happen because of above issue.
You can give it a try to open the
MiLight-Hub
project in VCode, comment the lines in my previous comment and flash it to the board.Yesterday I noticed that Homeassistant also contains a Scene optimization that it won't send a light state when it thinks the light is already in a specific state. This also results in lights out of sync after a restart or missing packets. I'm not sure if this optimization can be disabled. Switching to another scene is only reliable when all lights are always refreshed.
I really dont know how to do that. I will wait for a possible update. I have tried this kind of tweaks in past, but always brick my things haha
I was just trying to make an HA automation so when I change the state of the "All / 0" group, all the lights to adopt that same state. It was not working however, the changes were not propagating correctly. Now with this change, all the lights follow the All group successfully:
bool GroupState::setState(const MiLightStatus status) { //if (!isNightMode() && isSetState() && getState() == status) { // return false; //} setDirty(); ...
My automation:
- alias: Mi / Bedroom / Follow
trigger:
platform: state
entity_id: light.mi_bedroom
action:
choose:
- conditions: "{{ is_state(trigger.entity_id, 'off') }}"
sequence:
service: light.turn_off
entity_id:
- light.mi_bedroom_clau
- light.mi_bedroom_miha
default:
service: light.turn_on
entity_id:
- light.mi_bedroom_clau
- light.mi_bedroom_miha
What's more is that I don't have to manually specify the attributes (brightness, rgb, etc), they are automatically copied (not sure how though but I don't really care now).
Describe the bug
A light state may be out of sync between Homeassistant - MiLight-Hub. In this case the light on/off button in Homeassistant flips back to the previous state after a few seconds.
Root cause: MiLight hub does not send a MQTT state topic when it receives a command topic without a change.
A possible solution would be send the light state always after each light command.
Steps to reproduce
Expected behavior
Always send a MQTT state after a command. Consider to make this permanent, or configurable.
Setup information
Firmware version
See next.
Output of http://milight-hub.local/about
Output of http://milight-hub.local/settings
Homeassistant configuration.yaml
Additional context
See screen capture above.