home-assistant / homebridge-homeassistant

DEPRECATED in favor of native HomeKit support. -  Homebridge plugin for Home Assistant
https://www.home-assistant.io/components/homekit/
Other
683 stars 144 forks source link

Homebridge color picker sync problem in homeassistant, bulbs stop responding #266

Closed badstraw360 closed 2 years ago

badstraw360 commented 6 years ago

Home Assistant release (hass --version): 0.60.0

Platform: limitlessled

Description of problem: When I'm using any limitlessled light in homeassistant and try to change bulb colors using the color picker in homekit and save them to use later, homeassistant won't update the color and the bulb stops responding. So even If I try to turn it off using homeassistant after the bulb stops responding, I need to reset the pi to make it work again. Here is a video of the problem: https://vimeo.com/248093143

Expected: Change colors accordingly.

light:
  platform: limitlessled
  bridges:
    - host: 192.168.0.50
      groups:
      - number: 1
        type: rgbww
        name: lámpara
      - number: 2
        type: rgbww
        name: luz
        fade: on
{
    "bridge": {
        "name": "Homekit",
        "username": "CC:17:3D:E5:CE:30",
        "port": 51826,
        "pin": "031-45-154"
    },
    "platforms": [{
        "platform": "HomeAssistant",
        "name": "HomeAssistant",
        "host": "http://hassbian.local:8123",
        "supported_types": [
            "rollershutter",
            "binary_sensor",
            "climate",
            "cover",
            "device_tracker",
            "fan",
            "group",
            "input_boolean",
            "light",
            "lock",
            "media_player",
            "scene",
            "sensor",
            "switch"
        ],
        "logging": true
    }]
}
platdesign commented 6 years ago

same here. Two different sets of rgb-values are sent on a single change.

[2017-12-27 15:23:48] [HomeAssistant] Successfully set saturation on the 'testlight' to 98
[2017-12-27 15:23:48] [HomeAssistant] Successfully set rgb on the 'testlight' to 5,255,18
[2017-12-27 15:23:48] [HomeAssistant] Successfully set hue on the 'testlight' to 23
[2017-12-27 15:23:48] [HomeAssistant] Successfully set rgb on the 'testlight' to 255,101,5
battistaar commented 6 years ago

I'm experiencing the same issue. After a bit of debug i think i figured out the problem. It seems that saturation and hue have different values in setSaturation and setHue methods. I solved the problem moving the rgb conversion logic to a different method and checking if both values has changed.

setHue(level, callback, context) {
    if (context === 'internal') {
      callback();
      return;
    }

    this.data.attributes.hue = level;

    if (this.cachedColor) {
      this._setColor(callback);
    } else {
      this.cachedColor = true;
      callback();
    }
  },
  setSaturation(level, callback, context) {
    if (context === 'internal') {
      callback();
      return;
    }
    this.data.attributes.saturation = level;

    if (this.cachedColor) {
      this._setColor(callback);
    } else {
      this.cachedColor = true;
      callback();
    }
  },
  _setColor(callback) {
    const that = this;
    this.cachedColor = false;
    const serviceData = {};
    serviceData.entity_id = this.entity_id;
    const rgb = LightUtil.hsvToRgb(
      (this.data.attributes.hue || 0) / 360,
      (this.data.attributes.saturation || 0) / 100,
      (this.data.attributes.brightness || 0) / 255
    );

    if (this.data.attributes.hue !== undefined) {
      if (this.is_supported(this.features.XY_COLOR)) {
        serviceData.xy_color = LightUtil.rgbToCie(rgb.r, rgb.g, rgb.b);
      } else {
        serviceData.rgb_color = [rgb.r, rgb.g, rgb.b];
      }
    }

    this.client.callService(this.domain, 'turn_on', serviceData, (data) => {
      if (data) {
        if (that.is_supported(that.features.XY_COLOR)) {
          that.log(`Successfully set xy on the '${that.name}' to ${serviceData.xy_color}`);
        } else {
          that.log(`Successfully set rgb on the '${that.name}' to ${serviceData.rgb_color}`);
        }
        callback();
      } else {
        callback(communicationError);
      }
    });

I hope this helps. Great work, i love this project!

badstraw360 commented 6 years ago

Great!!! Would you share the file with the new code so that I can replace the old one please?

I'm really glad that you figured it out!! This bug is driving me crazy..

battistaar commented 6 years ago

Here it is. Github doesn't accept .js Actually i have no idea why it happens, those methods doesn't look async. I will try to investigate further as soon as I reinstall HA, at the moment i'm using hassio and making live changes is a pain.

light.txt

badstraw360 commented 6 years ago

Thank you, I appreciate your help! I replaced the old light.js file with the new one, but I'm still having the same problem. Maybe it's because I'm using hassbian. I'm going to try to install hassio... :)

battistaar commented 6 years ago

The problem using Hassio is that it uses docker images and the file is restored every time you restart the server. I don’t know how hassbian works. Send me the log, I’ll check ASAP.

badstraw360 commented 6 years ago

Awesome, thank you !! Would you need this log? daemon.log

Im getting tail: cannot open '/var/log/homebridge.log' for reading: No such file or directory

Actually homebridge is set up as a service in systemd and writes its log (together with all other processes) in /var/log/daemon.log

badstraw360 commented 6 years ago

Here's just part of the bigger one... newlog.txt

I have a huge 200 mb log file, if you need it let me know.

battistaar commented 6 years ago

Sorry, I don't know why you are still having problems. Maybe we were experiencing different issues. In my case the light color was changing twice (going back to the previous one)

dharrison8815 commented 6 years ago

Experiencing the same issues here... Can someone walk me through replacing the light.js file that @battistaar posted above?

Many thanks!