shnhrrsn / homebridge-openzwave

OpenZWave platform for Homebridge.
MIT License
18 stars 4 forks source link

Unable to connect to device #4

Closed ne0nex closed 4 years ago

ne0nex commented 4 years ago

A bit of a process installing this on a Raspberry Pi 3, but finally got the project to build without module errors/missing symbols.

Now I'm getting: [OpenZWave] Unable to connect to device.

After the home bridge init. I've added the relevant sections in config.json and MinOZW can talk to the correct device at /dev/ttyACM0, (I get proper device enumeration and can see the ZWave switch node using the command MinOZW /dev/ttyACM0 which is the same devicePath I have in the config. I've supplied the config snippet below for the openzwave platform and a simple binary switch I have as node2:

{
            "platform": "openzwave",
            "name": "OpenZWave",
            "zwave": {
                "devicePath": "/dev/ttyACM0"
            },
            "accessories": {
                "2": {
                    "name": "ASwitch",
                    "classes": {
                        "ignored": [
                            128
                        ],
                        "rewrite": [
                            {
                                "from": 37,
                                "to": 999001,
                                "indexes": {
                                    "5": 0
                                }
                            }
                        ]
                    }
                }
            }
        },

Note that even without the accessories: object, I still get the Unable to connect to device error. Is there some way to turn on logging or something for this module so I can see what it's doing with the openzwave binary? Earlier in the log output from Homebridge I see:

May 16 10:38:22 pihomebridge homebridge[3554]: [16/05/2020, 10:38:22] [OpenZWave] Initializing openzwave platform...
May 16 10:38:22 pihomebridge homebridge[3554]: Initialising OpenZWave 1.6.1123 binary addon for Node.JS.
May 16 10:38:22 pihomebridge homebridge[3554]: #011OpenZWave Security API is ENABLED
May 16 10:38:22 pihomebridge homebridge[3554]: #011ZWave device db    : /usr/local/etc/openzwave
May 16 10:38:22 pihomebridge homebridge[3554]: #011User settings path : /usr/lib/node_modules/homebridge-openzwave/node_modules/openzwave-shared/build/Release/../../
May 16 10:38:22 pihomebridge homebridge[3554]: #011Option Overrides : --ConsoleOutput false --Logging false --SaveConfiguration false
May 16 10:38:22 pihomebridge homebridge[3554]: Could Not Open OZW Log File.

Which has the option overrides to not log, as options.xml in the config/ dir of the 'user options path' specified above, has logging set to true.

I want to ensure that it's not attempting to execute on an incorrect device path.

ne0nex commented 4 years ago

I'd like to report that I was able to self resolve this. I used: find /usr/lib/node_modules/homebridge-openzwave/ -type f -name '*.js' | xargs grep -al Logging

to find that /usr/lib/node_modules/homebridge-openzwave/lib/Platform.js is where the overrides are set. Turned "Console Output" to true, and found that the error was: ERROR: Cannot open serial port /dev/ttyACM0. Error code 13

Good old permission denied to /dev/ttyACM0. But why, if I was able to run it myself.

Well that's the thing. I'm logged in running these commands and doing this install as the user 'pi' the home bridge service on my installation runs as user: homebridge. Doing ls -al /dev/ttyACM0 returned root:dialout as the owner/group of the device with perms: CRW-RW---- so only root and members of dialout had permission.

checking homebridge user's group membership found the problem:

groups homebridge
homebridge : homebridge avahi

homebridge isn't in the needed group. added homebridge user to the dialout group: sudo adduser homebridge dialout and rebooted for good measure as the user is logged in at service init time and presto.

[16/05/2020, 12:57:29] [OpenZWave] Node Available: ZW090 Z-Stick Gen5 US
[16/05/2020, 12:57:30] [OpenZWave] Node Available: ASwitch
[16/05/2020, 12:57:30] [OpenZWave] Finished Scanning

Home app on iOS sees the node and is able to turn it off and on.

In the words of young Anakin Skywalker: "IT'S WORKING"

raspbian seems to restrict what users have access to /dev/tty devices (and maybe others) if a user of your project is attempting to install this on such a device, and sets up homebridge as a system service (for auto-launching, restarting, etc) then they need to ensure that the service's user has permission to access the serial device.

I will post a separate issue and mark as resolved for the symbol not found and general learnings for installing on Raspberry Pi/Raspbian as I started writing it up here and it went way too long and out of scope for this one issue.

Marking this as closed.

shnhrrsn commented 4 years ago

Appreciate this! I definitely need to update the readme to include the dialout group, I’m pretty sure I saw that on a different OZW plugin.

Any learnings you can share for rpi would be huge too!

Be sure to let me know if you run into any other issues.