luisiam / homebridge-cmdswitch2

CMD Plugin for HomeBridge (API 2.0): https://github.com/nfarina/homebridge
Apache License 2.0
176 stars 29 forks source link

Failed to determine Playstation state #22

Open Pe8er opened 7 years ago

Pe8er commented 7 years ago

ps4-waker doesn't seem to play well with cmdswitch2 on my system. When I invoke it from Terminal, it works properly. However, it disappeared from Home app and homebridge log shows me the following:

[8/12/2017, 12:22:04 PM] [CMD Switch] Failed to determine Playstation state.
[8/12/2017, 12:22:04 PM] [CMD Switch] /bin/sh: grep: command not found

My config:

    "platforms": [{
        "platform": "cmdSwitch2",
        "name": "CMD Switch",
        "switches": [{
            "name": "Playstation",
            "on_cmd": "ps4-waker -c ~/.homebridge/ps4-wake.credentials.json",
            "off_cmd": "ps4-waker -c ~/.homebridge/ps4-wake.credentials.json standby",
            "state_cmd": "ps4-waker -c ~/.homebridge/ps4-wake.credentials.json search | grep -i '200 Ok'",
            "polling": true,
            "interval": 5,
            "timeout": 2000,
            "manufacturer": "Sony Corporation",
            "model": "CUH-1001A",
            "serial": "XXXXXXXXXXX"
        }]
    }]

I'm running it on a Mac Mini with macOs 10.12.6 and node.js 8.2.1.

Any help would be greatly appreciated!

luisiam commented 7 years ago

What if you run that search command on the terminal directly? Can you see your device?

Pe8er commented 7 years ago

Yes, it works in terminal every time. Only through cmdswitch2 it pops up these errors every now and then. And I do have grep installed on my system too, so that one is particularly strange.

brandonb927 commented 6 years ago

I ran into this exact issue and it turned out to be a PATH-related issue. I'm running homebridge with systemd and the system user didn't have a PATH set, therefore when it tried to call ps4-waker, the bin directory for node it wasn't in the path. By simply specifying the full bin path to the command, I was able to get around this.

nicktones commented 6 years ago

PATH issue is a problem as @brandonb927 suggests. I also found that the system user can't access the .ps4-wake.credentials.json file in a users (any) home folder. Setup ps4-waker, then copy the .ps4-wake.credentials.json file to a folder that all users can access.

See example working commands below...

"on_cmd": "node /opt/node/lib/node_modules/ps4-waker/bin/cmd.js -c /var/homebridge/.ps4-wake.credentials.json", "off_cmd": "node /opt/node/lib/node_modules/ps4-waker/bin/cmd.js -c /var/homebridge/.ps4-wake.credentials.json standby", "state_cmd": "node /opt/node/lib/node_modules/ps4-waker/bin/cmd.js -c /var/homebridge/.ps4-wake.credentials.json search | grep -i '200 Ok'",

brandonb927 commented 6 years ago

@nicktones this is exactly how I needed to call mine with a slightly different install path, but nonetheless.

ryanschmidt commented 6 years ago

I've tried the approaches mentioned above and I can't tell if my issue is different or the same.

On homebridge load:

[CMD Switch] Initializing platform accessory 'Playstation'...

When switching the device in Home app on iOS:

[CMD Switch] Turning on Playstation took too long [1s], assuming success.
[CMD Switch] Playstation is turned on.
[CMD Switch] Playstation is off.

When the above is happening, the PS4 shows that a device has connected and then it shows it's disconnected. Those interactions match up to the timing of the above "on" and "off" log entries.

My current config

   "platform": "cmdSwitch2",
    "name": "CMD Switch",
    "switches": [{
        "name" : "Playstation",
        "on_cmd": "ps4-waker",
        "off_cmd": "ps4-waker standby",
        "state_cmd": "ps4-waker search | grep -i '200Ok'",
        "polling": true,
        "interval": 5,
        "manufacturer": "Sony Corporation",
        "model": "CUH-1001A",
        "serial": "XXXXXXXXXXX"
    }]

Any ideas for me to try?

mitch7391 commented 6 years ago

@ryanschmidt I have had the exact same issues and tried just about everything. With a lot of trial and error today I managed to get this config to work using this path:

"platforms": [{ "platform": "cmdSwitch2", "name": "CMD Switch", "switches": [{ "name": "Playstation 4", "on_cmd": "node /opt/node/bin/ps4-waker -c /var/homebridge/.ps4-wake.credentials.json", "off_cmd": "node /opt/node/bin/ps4-waker -c /var/homebridge/.ps4-wake.credentials.json standby", "state_cmd": "node /opt/node/bin/ps4-waker -c /var/homebridge/.ps4-wake.credentials.json search | grep -i '200 Ok'", "polling": true, "interval": 5, "timeout": 2000, "manufacturer": "Sony Corporation", "model": "CUH-1102A", "serial": "XXXXXXXXXXX" }] }]

Hope this helps. The only problem I have now is the command takes so long to execute that Siri says it is unresponsive; but it does actually end up working.

mreassassin commented 6 years ago

I'm not able to get this to work... if the ps4 is on and I turn it off, it will just switch back to on and tell me it's on (and vice versa). here's what I get:

[2018-7-5 20:46:46] [CMD Switch] Initializing platform accessory 'PS4'... [2018-7-5 20:46:46] [CMD Switch] PS 4 is removed from HomeBridge. [2018-7-5 20:46:46] Homebridge is running on port 51826. [2018-7-5 20:46:46] [Wink] Refreshing devices... [2018-7-5 20:46:46] [CMD Switch] PS4 is on. [2018-7-5 20:46:46] [Wink] Refreshing access token... [2018-7-5 20:46:47] [Wink] Refreshed access token [2018-7-5 20:46:48] [CMD Switch] PS4 is on. [2018-7-5 20:46:50] [Wink] Devices refreshed [2018-7-5 20:46:50] [Wink] Checking if hub is reachable (MarHub, 192.168.1.26)... [2018-7-5 20:46:50] [Wink] Hub is reachable locally (MarHub, 192.168.1.26) [2018-7-5 20:46:50] [CMD Switch] PS4 is on. [2018-7-5 20:46:50] [Wink] Authenticated with local hub (MarHub, 192.168.1.26) [2018-7-5 20:47:34] [CMD Switch] PS4 is turned off. [2018-7-5 20:47:36] [CMD Switch] PS4 is on. [2018-7-5 20:47:53] [CMD Switch] PS4 is on. [2018-7-5 20:47:58] [CMD Switch] PS4 is turned off. [2018-7-5 20:48:01] [CMD Switch] PS4 is on. [2018-7-5 20:48:07] [CMD Switch] PS4 is turned off. [2018-7-5 20:48:11] [CMD Switch] PS4 is on. [2018-7-5 20:48:17] [CMD Switch] PS4 is turned off. [2018-7-5 20:48:22] [CMD Switch] PS4 is on.

I can turn on/off just fine with the 2nd screen app.

I don't quite understand how I can test this by manually running ps4-waker is there a way? I was able to connect to ps4-waker in the 2nd screen app.

thanks!

mreassassin commented 6 years ago

got it to work! found the answer here.

ryanschmidt commented 6 years ago

It's true! The above worked for me.

{
    "platform": "cmdSwitch2",
    "name": "CMD Switch",
    "switches": [{
        "name" : "Playstation",
        "on_cmd": "sudo ps4-waker -c /var/homebridge/.ps4-wake.credentials.json",
        "off_cmd": "sudo ps4-waker -c /var/homebridge/.ps4-wake.credentials.json standby",
        "state_cmd": "sudo ps4-waker -c /var/homebridge/.ps4-wake.credentials.json search | grep -i '200 Ok'",
        "polling": true,
        "interval": 5,
        "manufacturer": "Sony Corporation",
        "model": "CUH-1001A",
        "serial": "XXXXXXXXXXX"
    }]
  }
mreassassin commented 6 years ago

anybody able to get this to work with an xbox?