NorthernMan54 / node-red-contrib-homebridge-automation

Homebridge and Node-RED Integration
Apache License 2.0
106 stars 18 forks source link

Local IP to parce accessories #23

Closed ssypchenko closed 4 years ago

ssypchenko commented 5 years ago

As I see there is a local ip address in code to parse accessories from Homebridge (127.0.0.1). But is I use Node-red in docker, 127.0.0.1 does not point to Homebridge :( Would you please add a setting for Homebridge ip address?

The reason for this issue is that I try to resolve a problem with populating accessories after the initial setup. I did everything according to instructions, and after "Deploy" I have no devices in the list :(

NorthernMan54 commented 5 years ago

Where are you seeing this in the code? I have that in the README as an example if a manual dump is needed for troubleshooting, but internally is uses Bonjour discovery to find all the instances.

What do the logs show?

ssypchenko commented 5 years ago

I found the local ip address in tools/parseAccessories.js

I tried to change it to mine in my setup without a positive result :(

Logs are as follows: This part is after install: 10 Sep 11:15:04 - [info] Server now running at http://127.0.0.1:1880/ TypeError: Cannot read property 'toList' of undefined at /usr/src/node-red/node_modules/node-red-contrib-homebridge-automation/HAP-NodeRed.js:499:34 at Layer.handle [as handle_request] (/usr/src/node-red/node_modules/express/lib/router/layer.js:95:5) at next (/usr/src/node-red/node_modules/express/lib/router/route.js:137:13) at /usr/src/node-red/node_modules/@node-red/editor-api/lib/auth/index.js:74:13 at Layer.handle [as handle_request] (/usr/src/node-red/node_modules/express/lib/router/layer.js:95:5) at next (/usr/src/node-red/node_modules/express/lib/router/route.js:137:13) at Route.dispatch (/usr/src/node-red/node_modules/express/lib/router/route.js:112:3) at Layer.handle [as handle_request] (/usr/src/node-red/node_modules/express/lib/router/layer.js:95:5) at /usr/src/node-red/node_modules/express/lib/router/index.js:281:22 at param (/usr/src/node-red/node_modules/express/lib/router/index.js:354:14)

This part is after "Deploy":

`10 Sep 11:21:26 - [info] Stopping flows 10 Sep 11:21:26 - [info] Stopped flows 10 Sep 11:21:26 - [info] Starting flows

hapNodeJSClient Starting Homebridge instance discovery +0ms hapNodeRed hbConf.register - +0ms hapNodeRed Register hb-event -> - +0ms

10 Sep 11:21:26 - [info] Started flows`

This part is after I press refresh button near the device list: hapNodeJSClient Ending Homebridge instance discovery +20s hapNodeRed Discovered 0 new evDevices +20s hapNodeRed Discovered 0 new ctDevices +1ms hapNodeRed evDevices 0 +8m hapNodeRed evDevices 0 +36ms hapNodeRed evDevices 0 +34ms hapNodeRed evDevices 0 +8s

NorthernMan54 commented 5 years ago

Your issue is with docker networking config. I’m not a user of docker so can’t provide any input into how to fix it

The 127.0.0.1 in the log file is from node-red itself and not my code. The code in the tools directory is just some test code I have for testing the device parser.

The error message is the plugin saying that you have no homebridge devices.

Homebridge device discovery is not working, and I suspect it is because your docker instance doesn’t have access to bonjour, on port 5353. As this is related to docker networking config, I really cant add anymore.

ssypchenko commented 5 years ago

Ok, thanks for the clarification. If I understand you correctly, this module can't be used now in a standard docker environment. I try to use my Synology NAS as a home automation system. I installed Homebridge in docker, Deconz, and try to connect Node-Red to make automation rules. I installed Node-Red in the separate docker container.

What I can do next:

  1. I'll try to expose port 5353 in both containers, however, I'm not sure whether bonjour is standard network protocol for Homebridge and Node-red container.
  2. I can try to install Node-red and your plugin into Homebridge container. I'm not sure would it be problems with dependances in that case.
  3. I ordered Rasberry :) which will be delivered in about a month...
ssypchenko commented 5 years ago

By the way, I see this line in HAP-NodeRed.js: var HAPNodeJSClient = require('hap-node-client').HAPNodeJSClient; However, I do not see the file hap-node-client.js in folders. Would you please clarify how it works? I mean I would check the code and try to find a solution.

PS is the bonjour included into Homebridge setup? So it used by your plugin to discovery...

NorthernMan54 commented 5 years ago

Your option 2 is the easiest workaround for the issue

Your code question is how npm and JavaScript packages work

Google bonjour, is it the device discovery protocol used by Apple with HomeKit

On Sep 10, 2019, at 8:22 AM, ssypchenko notifications@github.com wrote:

By the way, I see this line in HAP-NodeRed.js: var HAPNodeJSClient = require('hap-node-client').HAPNodeJSClient; However, I do not see the file hap-node-client.js in folders. Would you please clarify how it works? I mean I would check the code and try to find a solution.

PS is the bonjour included into Homebridge setup? So it used by your plugin to discovery...

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

ssypchenko commented 5 years ago

I've managed to install Node-Red and this plugin into "Homebrodge" container. It was not so easy :) I see my accessories in Node-Red now. Thank you for the plugin. One last question to clarify. I added a new sensor in Deconz. It becomes visible in Homebridge and Home Kit at the same time. However, it took about 10 minutes to discover it in Node-Red. I was really worried but decided to wait and found it in the Node-Red finally. Is it some schedule for the discovery or it is just feature of Bonjour protocol that Node-Red does not find the new device at the moment of its appearance in the system? (I pressed the refresh button several times after the setup of the new sensor).

PS Just recommend adding to ReadMe the requirements to have the installation of Node-Red and this plugin in one "virtual" server with Homebridge to have the possibility to discover Homebrodge accessories.

NorthernMan54 commented 5 years ago

It has a 15 minute device refresh timer, so unless you restart node-red, you need to wait 15 minutes

Sent from my iPad

On Sep 11, 2019, at 5:17 AM, ssypchenko notifications@github.com wrote:

I've managed to install Node-Red and this plugin into "Homebrodge" container. It was not so easy :) I see my accessories in Node-Red now. Thank you for the plugin. One last question to clarify. I added a new sensor in Deconz. It becomes visible in Homebridge and Home Kit at the same time. However, it took about 10 minutes to discover it in Node-Red. I was really worried but decided to wait and found it in the Node-Red finally. Is it some schedule for the discovery or it is just feature of Bonjour protocol that Node-Red does not find the new device at the moment of its appearance in the system? (I pressed the refresh button several times after the setup of the new sensor).

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

bkessels commented 2 years ago

Hi NorthernMan54,

Thanks for providing the Plugin

FYI: Solved the same problem in easier way:

In the node red docker container I added the following port mapping in "port settings" tab

After this I am able to see my homebridge devices in nodered.

Hope this helps others to use homebridge in node Red

NorthernMan54 commented 2 years ago

Tks for sharing this tip