cflurin / homebridge-mqtt

Homebridge-mqtt is a Plugin for Homebridge.
Apache License 2.0
229 stars 39 forks source link

iPhone shows "Updating..." until "No Response" even though device is online #76

Closed ericcastro closed 5 years ago

ericcastro commented 5 years ago

I created a light switch, which works on all aspects except one. When the Home app is launched on the iPhone, it requests the switch current status, homebridge-mqtt sends a message on the homebridge/from/get topic, and I get it correctly on my ESP32.

My ESP32 is running the following code:

void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {

  if (strcmp(topic, "homebridge/from/get") == 0)
  {
    Serial.println("Asked for switch status");
    Serial.println(switchIsOn);
    if (switchIsOn)
    {
        mqttClient.publish("homebridge/to/set", 0, true, "{\"name\": \"neopixel_livingroom\", \"service_name\": \"light\", \"characteristic\": \"On\", \"value\": true}");
    }
    else
    {
        mqttClient.publish("homebridge/to/set", 0, true, "{\"name\": \"neopixel_livingroom\", \"service_name\": \"light\", \"characteristic\": \"On\", \"value\": false}");
    }
  }

  if (strcmp(topic, "homebridge/from/set") == 0)
  {
    /* Here goes the code when user changes the switch from the Home app */
  }
}

The problem is that neither homebridge-mqtt is sending any cached values back to the Home app, and also when I respond to Home's app update request, that doesn't seem to do anything either.

Home app hangs at "Updating..." and during this time, the switch on the iPhone is unusable until it times out with a red "No Response" error message: at that point the switch can be used again and behavior is restored.

Am I doing something wrong or is this a bug ?

cflurin commented 5 years ago

Hi,

  1. Use a tool like: https://github.com/thomasnordquist/MQTT-Explorer and check what you are sending.
  2. start homebridge in debug mode to see what is going on:
    homebride -D
bohtho commented 5 years ago

I’ve been using this for 2 years without trouble (it’s actually the most stable Homebridge plugin and also the most stable HomeKit implementation I’ve tried) but I also retain messages in the Mqtt broker and also set the reachable status in addition to every update so this has never been an issue for me. Sorry to not be of more help.

ericcastro commented 5 years ago

@cflurin when I push the physical button on my ESP32, I send the message updating its On characteristic value to true or false- this is properly reflected in the Home app.

I send this exact same message (as shown above) whenever anything comes from the homebridge/from/get topic, but iPhone keeps showing "Updating..."

Even if I didn't send anything, why is homebridge-mqtt not using the cached value ? has this behavior even been observed ?

By the way, homebridge is running on Windows.

I will try the debug mode as soon as I get home to see what I can find.

@bohtho your comment is reassuring nonetheless, as it seems that it's something only happening to my setup

cflurin commented 5 years ago

Even if I didn't send anything, why is homebridge-mqtt not using the cached value ? has this behavior even been observed ?

The cached value default is blank, so if you didn't set the value, there is no cached value.

ericcastro commented 5 years ago

Even if I didn't send anything, why is homebridge-mqtt not using the cached value ? has this behavior even been observed ?

The cached value default is blank, so if you didn't set the value, there is no cached value.

but doesn't publishing to the homebridge/to/set topic actually set that value ? this is what I do when I push the manual button on the ESP32 - which in turn also updates the Home app properly. But it's only if I quit the app (or move to background), then put it back into foreground, and then it freezes in "Updating.."

ericcastro commented 5 years ago

OK, I have found the exact scenario that causes this problem.

  1. I have two platforms in my config.json, homebridge-mqtt and DysonPlatform which comes from the following homebridge plugin: homebridge-dyson-link
  2. If I remove the DysonPlatform from the configuration, I no longer have this problem with homebridge-mqtt, the values update instantly on the Home app and no freezing occurs.
  3. If I re-add the DysonPlatform but the dyson fan isn't connected to power (so it won't respond to any requests from homebridge), then I have this problem again with homebridge-mqtt - both dyson and mqtt devices cannot update on the Home app.
  4. If I connect the dyson device to power, it starts responding again to homebridge: both homebridge-mqtt and DysonPlatform work correctly and update their values instantly

What I don't know yet is who's responsible of interfering with each other's update requests. However, homebridge-mqtt does send a update request to the homebridge/from/get topic, as soon as the Home app is launched.

The simplest way to reproduce this problem is to test a setup with a DysonPlatform config, even if you don't have any dyson device, because the fact that a Dyson fan isn't responding will produce this behavior in homebridge-mqtt

My sample config json (I zeroed out my own values):

{
  "bridge": {
    "name": "Homebridge",
    "username": "00:00:00:00:00:00",
    "port": 51826,
    "pin": "000-00-000"
  },
  "Description": "JSON API",
  "accessories": [],
  "platforms": [
    {
      "platform": "mqtt",
      "name": "mqtt",
      "url": "mqtt://127.0.0.1",
      "port": "1883",
      "topic_type": "multiple",
      "topic_prefix": "homebridge",
      "qos": 1
    },
    {
      "platform": "DysonPlatform",
      "name": "DysonPlatform",
      "accessories": [
        {
          "ip": "192.168.1.24",
          "displayName": "Dyson",
          "serialNumber": "DYSON-000-00-00000000-000",
          "password": "000000000"
        }
      ]
    }
  ]
}
cflurin commented 5 years ago

Have a look here: https://github.com/joe-ng/homebridge-dyson-link/issues/67

Please, open an issue on: https://github.com/joe-ng/homebridge-dyson-link

ericcastro commented 5 years ago

Yes, this seems to be caused by the Dyson plugin. I also found more related open issues: https://github.com/joe-ng/homebridge-dyson-link/issues/61 https://github.com/joe-ng/homebridge-dyson-link/issues/15

The author has not been very responsive about it. I guess we can close this one here.