homebridge-webos-tv: Can't get config to work

I’m trying to get the config setup to connect to my TV and I’m clearly missing something. I used this guide to setup homebridge, so my config.json is located in /var/homebridge/ directory instead of /home/pi/.homebridge.

Here’s my accessory config:

"accessories": [
 {
      "accessory": "webostv",
      "name": "My webOS TV",
      "ip": "192.168.1.27",
      "mac": "XXXXXXXXXXX",
      "keyFile": "",
      "volumeControl": "slider",
      "channelControl": false,
      "mediaControl": false,
      "pollingEnabled": true,
      "appSwitch":[
         "com.webos.app.hdmi2",
         "com.webos.app.externalinput.component"
      ]
    }
  ],

Here is the log file for the error:

Dec 09 20:21:16 raspberrypi systemd[1]: Started Node.js HomeKit Server.
Dec 09 20:21:18 raspberrypi homebridge[4544]: [2018-12-9 20:21:18] Loaded config.json with 1 accessories and 1 platforms.
Dec 09 20:21:18 raspberrypi homebridge[4544]: [2018-12-9 20:21:18] ---
Dec 09 20:21:18 raspberrypi homebridge[4544]: [2018-12-9 20:21:18] Loaded plugin: homebridge-neato
Dec 09 20:21:18 raspberrypi homebridge[4544]: [2018-12-9 20:21:18] Registering platform 'homebridge-neato.NeatoVacuumRobot'
Dec 09 20:21:18 raspberrypi homebridge[4544]: [2018-12-9 20:21:18] ---
Dec 09 20:21:19 raspberrypi homebridge[4544]: [2018-12-9 20:21:19] Loaded plugin: homebridge-webos-tv
Dec 09 20:21:19 raspberrypi homebridge[4544]: [2018-12-9 20:21:19] Registering accessory 'homebridge-webos-tv.webostv'
Dec 09 20:21:19 raspberrypi homebridge[4544]: [2018-12-9 20:21:19] ---
Dec 09 20:21:19 raspberrypi homebridge[4544]: [2018-12-9 20:21:19] Loading 1 platforms...
Dec 09 20:21:19 raspberrypi homebridge[4544]: [2018-12-9 20:21:19] [NeatoVacuumRobot] Initializing NeatoVacuumRobot platform...
Dec 09 20:21:19 raspberrypi homebridge[4544]: Sun, 09 Dec 2018 20:21:19 GMT homebridge-neato Extra Care Navigation: 1
Dec 09 20:21:19 raspberrypi homebridge[4544]: Sun, 09 Dec 2018 20:21:19 GMT homebridge-neato Get all robots
Dec 09 20:21:19 raspberrypi homebridge[4544]: [2018-12-9 20:21:19] Loading 1 accessories...
Dec 09 20:21:19 raspberrypi homebridge[4544]: [2018-12-9 20:21:19] [My webOS TV] Initializing webostv accessory...
Dec 09 20:21:19 raspberrypi homebridge[4544]: path.js:28
Dec 09 20:21:19 raspberrypi homebridge[4544]:     throw new TypeError('Path must be a string. Received ' + inspect(path));
Dec 09 20:21:19 raspberrypi homebridge[4544]:     ^
Dec 09 20:21:19 raspberrypi homebridge[4544]: TypeError: Path must be a string. Received undefined
Dec 09 20:21:19 raspberrypi homebridge[4544]:     at assertPath (path.js:28:11)
Dec 09 20:21:19 raspberrypi homebridge[4544]:     at join (path.js:1236:7)
Dec 09 20:21:19 raspberrypi homebridge[4544]:     at module.exports (/usr/lib/node_modules/homebridge-webos-tv/node_modules/persist-path/index.js:19:22)
Dec 09 20:21:19 raspberrypi homebridge[4544]:     at new LGTV (/usr/lib/node_modules/homebridge-webos-tv/node_modules/lgtv2/index.js:47:16)
Dec 09 20:21:19 raspberrypi homebridge[4544]:     at new webosTvAccessory (/usr/lib/node_modules/homebridge-webos-tv/index.js:55:17)
Dec 09 20:21:19 raspberrypi homebridge[4544]:     at Server._loadAccessories (/usr/lib/node_modules/homebridge/lib/server.js:297:29)
Dec 09 20:21:19 raspberrypi homebridge[4544]:     at Server.run (/usr/lib/node_modules/homebridge/lib/server.js:87:38)
Dec 09 20:21:19 raspberrypi homebridge[4544]:     at module.exports (/usr/lib/node_modules/homebridge/lib/cli.js:45:10)
Dec 09 20:21:19 raspberrypi homebridge[4544]:     at Object.<anonymous> (/usr/lib/node_modules/homebridge/bin/homebridge:17:22)
Dec 09 20:21:19 raspberrypi homebridge[4544]:     at Module._compile (module.js:653:30)
Dec 09 20:21:19 raspberrypi systemd[1]: homebridge.service: Main process exited, code=exited, status=1/FAILURE
Dec 09 20:21:19 raspberrypi systemd[1]: homebridge.service: Unit entered failed state.
Dec 09 20:21:19 raspberrypi systemd[1]: homebridge.service: Failed with result 'exit-code'.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 18 (5 by maintainers)

Most upvoted comments

Had the same error with a Raspberry Pi 2 (Raspbian), using systemd and the following config,:

{
      "accessory": "webostv",
      "name": "Living Room TV",
      "ip": "...",
      "mac": "...",
      "keyFile": "/var/homebridge/webostvKeyFile",
      "prefsDir": "/var/homebridge/webostvPrefsDir",
      ...
}

TL;DR… The problem’s not in this library. It’s not even in lgtv2. It’s in a library called persist-path.

Basically, persist-path can’t find a good place to store temporary data because it can’t find my home directory. To fix this problem, I had to go into my systemd service

sudo nano /etc/systemd/system/homebridge.service 

And make sure a User was defined, like so:

[Unit]
Description=Node.js HomeKit Server
After=syslog.target network-online.target

[Service]
Type=simple
User=homebridge
EnvironmentFile=/etc/default/homebridge
ExecStart=/usr/local/bin/homebridge $HOMEBRIDGE_OPTS
Restart=on-failure
RestartSec=10
KillMode=process

[Install]
WantedBy=multi-user.target

How did I get there?

Here's the unnecessary, long story

Stuck in some console.log in and here’s what I found…

The error’s being thrown when the Lgtv2 instance is being created.

this.lgtv = new Lgtv2({
            url: this.url,
            timeout: 5000,
            reconnect: 3000,
            keyFile: this.keyFile
        });

The this.keyFile being passed into the instance, at least in my case, is definitely a string. So, diving deeper… lgtv2/index.js:47:16

It looks like the fun happens around here:

    if (typeof config.clientKey === 'undefined') {
        mkdirp(ppath('lgtv2'));
        config.keyFile = (config.keyFile ? config.keyFile : ppath('lgtv2/keyfile-') + config.url.replace(/[a-z]+:\/\/([0-9a-zA-Z-_.]+):[0-9]+/, '$1'));
        try {
            that.clientKey = fs.readFileSync(config.keyFile).toString();
        } catch (err) {}
    } else {
        that.clientKey = config.clientKey;
    }

So config.clientKey is undefined (expected behavior), so we proceed to mkdirp(ppath('lgtv2'));, where we crash. Not too surprising, considering that the stack trace came from persist-path/index.js:19:22. So what’s going on in there?

Here’s the entirety of persist-path.

module.exports = function () {
    var args = Array.prototype.slice.call(arguments);
    var pathArr = [];
    if (process.env.APPDATA) {
        pathArr.push(process.env.APPDATA);
    } else if (process.platform === 'darwin') {
        pathArr.push(path.join(process.env.HOME, 'Library/Preferences'));
    } else {
        pathArr.push(process.env.HOME);
        if (args.length > 0) {
            args[0] = '.' + args[0];
        }
    }
    if (args.length > 0) {
        pathArr = pathArr.concat(args);
    }
    return path.join.apply(this, pathArr);
};

The error is occurring in the return statement. Why? because pathArr is defined as [ undefined, '.lgtv2' ]. There’s our undefined! How did we get here? Well, we’re actually going to the else block at the end of the config because we’re not on a darwin mac. And I’m not sure what that process.env.APPDATA is about. Windows, probably. And of course, because I’m running from systemctl, process.env.HOME is undefined. Bam. Error.

What do we do now to fix it? Well, the problem’s not in this project. It’s not even in lgtv2, though it looks like they’re aware. If I had found that thread earlier, I could’ve skipped this whole effort… It’s lower, in persist-path.

And really, all that can be done is run on a mac or in an environment where process.env.APPDATA or process.env.HOME is defined. So how do we define HOME for a systemd service?

We make sure a user is defined. Which I didn’t define in my /etc/systemd/system/homebridge.service.

Fixing that fixed the problem.

Ok I just installed homebridge on a spare Pi I had left. Now it works, I wonder where is the plugin trying to put the file if you leave the path option blank. I guess I need to set specific rights for the homebridge user to that directory.