NorthernMan54 / homebridge-alexa

Expose your homebridge controlled devices to Amazon Alexa.
https://www.homebridge.ca
446 stars 77 forks source link

Changing light colour via Alexa crashes homebridge #446

Closed mvondemhagen closed 3 years ago

mvondemhagen commented 3 years ago

I run a Docker container with homebridge-alexa v0.5.20, node v14.16.1, homebridge v1.3.4 and can reproduce that all works fine until I try to change colour or colour temperature of a connected light, which throws the following message:

[5/5/2021, 10:30:13 AM] TypeError: Cannot read property 'RegisterPin' of undefined
    at /homebridge/node_modules/homebridge-alexa/node_modules/hap-node-client/HAPNodeJSClient.js:131:14
    at Timeout._onTimeout (/homebridge/node_modules/homebridge-alexa/node_modules/hap-node-client/HAPNodeJSClient.js:194:7)
    at listOnTimeout (internal/timers.js:554:17)
    at processTimers (internal/timers.js:497:7)
[5/5/2021, 10:30:13 AM] Got SIGTERM, shutting down Homebridge...
[5/5/2021, 10:30:18 AM] [deconz] goodbye
[5/5/2021, 10:30:18 AM] [HB Supervisor] Homebridge Process Ended. Code: 143, Signal: null
[5/5/2021, 10:30:23 AM] [HB Supervisor] Restarting Homebridge...

This does NOT happen when I use a voice command to change the colour, but ALWAYS when I use the Alexa ios app (e.g., with routines).

I saw a few other issues mentioning this error message, but none mentioned changing colour. Maybe this helps to find the bug.

NorthernMan54 commented 3 years ago

@dxdc am thinking it is related to this change

https://github.com/NorthernMan54/Hap-Node-Client/pull/49

dxdc commented 3 years ago

Agreed; please check: https://github.com/NorthernMan54/Hap-Node-Client/pull/52

NorthernMan54 commented 3 years ago

@mvondemhagen Can you update to v0.5.35 to see if this is resolved ?

mvondemhagen commented 3 years ago
[5/5/2021, 4:44:58 PM] [Homebridge UI] Running Command: npm install --save homebridge-alexa@latest
[5/5/2021, 4:46:32 PM] TypeError: Cannot read property 'RegisterPin' of undefined
    at /homebridge/node_modules/homebridge-alexa/node_modules/hap-node-client/HAPNodeJSClient.js:131:14
    at Timeout._onTimeout (/homebridge/node_modules/homebridge-alexa/node_modules/hap-node-client/HAPNodeJSClient.js:194:7)
    at listOnTimeout (internal/timers.js:554:17)
    at processTimers (internal/timers.js:497:7)
[5/5/2021, 4:46:32 PM] Got SIGTERM, shutting down Homebridge...

[5/5/2021, 4:47:57 PM] [Alexa] PowerController TurnOff 0E:D1:96:54:78:96 undefined null
[5/5/2021, 4:48:05 PM] TypeError: Cannot read property 'RegisterPin' of undefined
    at /homebridge/node_modules/homebridge-alexa/node_modules/hap-node-client/HAPNodeJSClient.js:131:14
    at Timeout._onTimeout (/homebridge/node_modules/homebridge-alexa/node_modules/hap-node-client/HAPNodeJSClient.js:194:7)
    at listOnTimeout (internal/timers.js:554:17)
    at processTimers (internal/timers.js:497:7)
[5/5/2021, 4:48:05 PM] Got SIGTERM, shutting down Homebridge...

This made is worse, I fear :-) Now even voice commands (although they work) trigger a crash.

dxdc commented 3 years ago

@NorthernMan54 I'm not sure what the issue is, exactly, but maybe it was getting an error and we didn't fix that one.

I created another PR, not sure if it would have caused the problem though, but probably helpful in any case.

https://github.com/NorthernMan54/Hap-Node-Client/pull/53

hkdan commented 3 years ago

Hi everybody. Same issue here after update to v0.5.35: "TypeError: Cannot read property 'RegisterPin' of undefined..." Voice command leads to a crash. No problems before v0.5.35. Going back to 34 does not resolve the problem.

NorthernMan54 commented 3 years ago

I have been looking at this deeper and can NOT recreate the issue with my test environment.

My environment

OSX homebridge-alexa v0.5.35, node v14.16.0, homebridge v1.3.4

Is the common factor here the usage of DOCKER ?

hkdan commented 3 years ago

Sorry for the missing information. No, I am not using Docker. I am running homebridge on a raspberry pi, node v14.16.1, homebridge v1.3.4.

NorthernMan54 commented 3 years ago

Okay played around a bit more and was able to recreate the issue. To confirm my suspicion are you seeing an ENDPOINT_UNREACHABLE message in DEBUG mode prior to the exception ?

And if you are, can you take the ENDPOINTID value and stick it into this website to decode the field ( it is a base64 encoded unique identifier for your device ) https://www.base64decode.org

Is the decoded value a valid device in your current setup ? In my case it was not a valid device, but was one that I was testing for another user last month.

@dxdc my working theory is that the device lookup is failing, as it is non-existent deviceid and that is why this is failing

  alexaActions alexaMessage: Response {
  "event": {
    "header": {
      "namespace": "Alexa",
      "name": "ErrorResponse",
      "messageId": "903b7ac4-4700-4660-8fa2-a9923c95ac4a",
      "correlationToken": "AAAAAAAAAABmGzenc7lh9ksMaDxy3iHc/AEAAAAAAAB3FvvXnyVh8Exz8iYEY2Wnfl7d55RxzY65leYOWuKn1PMl+vXCsfx9QJ7eyAOBhpOSlI88NnLc4sZHjiWbgPemJ1aSIIJpxVaEoVQ4JMf8VH3dYNelEFsccVVz05lNnHddtoGEYU8NlHKGPGKMPAdthQXWbDtJYpuLaGqAWS8fkB4LnDyorly6r29WIrlm70NsIkW2YJW2u9BL7FE9RMZQ/ayp/5T3LaxABETuGFq2rXLchDmkOB20yqCujzs4b3ePZi0YyHpiF2keI1ZgIOQRnCv3pThcsx1cGM8pmbYDu99ux/eUpURCmJtc3sSm+9+ZE6/H5IBN9XVDNH8Uo2LT9HpyNo35ZqsVNI3tn7Nh/Tpve9tZDG5cSOxfECybHFZpWOXMuPMy2DRCX5m4A5vVz7gNjv26R561HewZk83KPdi+IoplH4msoSCpUxFHBVvEiHBF3nlJeGe5iCF9U6/qRpc39xwveqzkxH0m7bB+j0726W0cKo0AB3hr7On6QnNJYSl36Xox5BCiFlnfiYX9EosMXuMwpbGiGX9O6fy8uCR4UbvYicRjI4cbR5pZqBBO2mR8WFGSnK3fR1wFTfmnpz2Wo5bWbVg4v/FODLOPxhaUK676kPVIz4M69BNwBrnrC8z8oxULxv6rZFg5K9v2wY3QZTN2H3voXjJI",
      "payloadVersion": "3"
    },
    "endpoint": {
      "endpointId": "Q0M6MjI6M0Q6RTM6Q0U6MzAtcGFyc2VUZXN0LUlLRUEgb2YgU3dlZGVuLUJhbGtvbiBEZWNrZW5sYW1wZS0wMDAwMDA0My0wMDAwLTEwMDAtODAwMC0wMDI2QkI3NjUyOTE="
    },
    "payload": {
      "type": "ENDPOINT_UNREACHABLE",
      "message": "ERROR: HB Instance not found"
    }
  }
} +0ms
  hapNodeJSClient HAP Device discovered Leonard-NodeRed-1C5E +613ms
TypeError: Cannot read property 'RegisterPin' of undefined
    at /Users/Code/homebridge-alexa/node_modules/hap-node-client/HAPNodeJSClient.js:131:14
    at Timeout._onTimeout (/Users/Code/homebridge-alexa/node_modules/hap-node-client/HAPNodeJSClient.js:194:7)
    at listOnTimeout (internal/timers.js:554:17)
    at processTimers (internal/timers.js:497:7)
Got SIGTERM, shutting down Homebridge...
dxdc commented 3 years ago

@NorthernMan54 did you see my latest PR? Not sure if this would fix it, but it did fix the error condition.

https://github.com/NorthernMan54/Hap-Node-Client/pull/53

hkdan commented 3 years ago

I guess I am now able to reproduce the crash. After restarting homebridge I alway trigger a search for devices in the alexa app (that was the normal procedure in the past because otherwise alexa would not be able to control my tv). If I do so homebridge crashes after the following voice command. If I do not manually search for devices, everything works fine and homebridge does not crash after voice command....

Does this information help? Just saw your comment, I try to follow your description.

hkdan commented 3 years ago

So I made the step: yes, there are a lot of lines with endpoint unreachable..the devices are particularly a lot of blinds I am using (all these devices are connected via the homebridge-homematic plugin). Since one of the last updates (prior to the current one) of your plugin, all of these devices were shown as not responding in the alexa app (that was not the case before). But it was no problem to control them via the app or voice command. After the update to v35: they are still shown as not responding. It is now as I wrote before. If I try to control them right after homebridge restart, no problem. But as soon as I am triggering a device lookup, the next voice command leads to a crash.

NorthernMan54 commented 3 years ago

Okay spent the afternoon working thru this issue and have just published v0.5.36. And can now see my color LED's consistently in the home app, and the constant crashing has stopped.

image

@dxdc I ended up removing that code block as the this reference was not consistently available from the various clients. For the original issue lets monitor the issue and see what occurs. A workaround could be to predefine the IP address and Port.

mvondemhagen commented 3 years ago

Okay spent the afternoon working thru this issue and have just published v0.5.36. And can now see my color LED's consistently in the home app, and the constant crashing has stopped.

I can confirm the crashing behaviour stopped, the issue seems resolved. I'd like to thank you for the very fast response and resolution, very much appreciated.

NorthernMan54 commented 3 years ago

Tks for confirming

hkdan commented 3 years ago

Can confirm as well. Thank you very much for your help.