Switch for Playstation 4

Got an error that the JSON was not valid, it contains ’ and not ".

When adding this line of code, it worked fine:

could try running ps4-waker search and add the raw json

I added some debug so you can get the raw json, but I tried “faking” the json and added a game with a colom in the name and it worked fine for me

this is the generated ps4-games.json i got out of it

"CUSA02491": "Mass Effect\u2122", 
"CUSA01116": "YouTube", 
"CUSA01262": "Tom Clancy's The Division\u2122", 
"CUSA02152": "Mittelerde: Mordors Schatten - Game of the Year Edition"

the text change you made for replacing ’ with " seems to be problematic, because ’ should not be replaced or escaped inside the string

I thought the same about replacing the ’ with ". But strangely it worked even on titles that contain '.

Here is the JSON the component gets:
17-05-01 17:42:28 DEBUG (Thread-6) [custom_components.media_player.ps4] Return value: b"{ type: ‘device’,\n statusLine: ‘200 Ok’ …

As you see, they use ’ which is not valid for JSON.

Edit 1:

Edit 2:

I opened a ticket on the ps4-waker repo: https://github.com/dhleong/ps4-waker/issues/38

I created a PR on the ps4-waker repo, which should fix the dumping of the ugly JSON. So no more regex hacks.


Edit 1:

After looking deeper into the API, we will have a little Problem.
When getting the status, the running-app-name is a short version of the full game (Which is not being exposed).
Now, when adding a game to the game.json file, they may not be distingishable by the user. This is in cases when

  1. Two or more games have the same name. (Example: BioShock: The Collection)
  2. Two or more games have similar names. (Example: Hatsune Miku: Project DIVA X, Hatsune Miku: Project DIVA Future Tone and Hatsune Miku: VR Future Live)

I created a new thread just for the custom component, this one started to get a bit messy if any new people wanted to use it

1 Like

I’ve followed your tip and it has worked like a charm. Thanks for the information!

1 Like

I have been trying to set this up, but it is proving frustrating. When I run sudo ps4-waker I get ‘No credentials; Use playstation app and connect to ps4 waker’. I have no idea how to do that in the App and can’t find anything relating to ps4 waker in there.

If I run node v it says v8.2.1
If I run nodejs -v it says v7.10.1
If I run npm -v it says 5.3.0

I have installed netcat and ps4-waker so I think I have installed what I needed to correctly.

Any ideas?

Yeah you have to run sudo ps4-waker then open your ps app and connect to the other “PS4” with the name ps-waker. Then you can use ps-waker.
In the app there should be something like connect to ps4 or so.

I hope it helps.

This time I closed the app on the phone and restarted it and it prompted to say it had found it. I clicked on ps4-waker and it just said connecting…

I went to my ps4 to get the code and entered it, but it failed. Now when I type sudo ps4-waker it says;

WAKEUP sent to device…
Logging in…

If I go into the playstation app now the only device it is finding is PS4-484 and not PS4-waker? Not sure if that is what it is meant to do or not?

maybe you should ask directly at github https://github.com/dhleong/ps4-waker because I don’t know either.

Sorry that i can’t help that much

Thanks for your help. I feel I have got a little further thanks to your previous post. I’m new to this so maybe a case of trying to run before I can walk.

OK so I have tried again and this time when I entered sudo ps4-waker -c .ps4-wake.credentials.json -d it has worked when entering the PIN from my ps4. I think previously I had put the space in the PIN number as displayed on the screen of my playstation rather than just typing it as an 8 digit number without spaces.

So I am a little bit further now! The next step is to save the credentials file in the config dir. Is there an easy way to do this or do I need to hook my raspberry pi to a monitor? I only have access to the HASSBIAN folder and its contents from my windows pc. There probably is an easier way, but as a newbie I have plenty to learn! Thanks for all the help so far you guys are great!

After that I am a little unsure of this section Test that ps4-waker -c .ps4-wake.credentials.json -d search works . It seems to be the same command as I previously entered to initialise the pairing process. Do I just do it again from the terminal?

Anybody able to advise on this? The next step is Save credentials file in the config dir, default location is .ps4-wake.credentials.json in the config dir.What command do I need to enter to copy this file to the config dir?


the config-file should be in the right directory
try ps4-waker to start your ps4 (note: your ps4 has to be in sleep/suspend-mode) if it works then you’re good.
if not you maybe have to copy it to /root/.ps4-wake.credentials.json you do that with sudo cp [sourcefile] [destinationfile]

Anyone trying to get this to work with Hass.io as an addon?

My mate tried and failed… Has.io doesn’t allow ssh or have sudo… So you’re very limited with it.

Tbh, hass.io only appears to benefit beginners of HA. Granted it makes things easier (updating, ssl etc) but without ssh you’re limited to the components already available in homeassistant.

I rely heavily on sudo/ssh as most of my switches do something on the cmd line. The pros certainly don’t outway the cons imo

1 Like

running all in one and so close I think to getting it to work. Error log is showing below multiple times. ps4-waker can suspend and wake the PS4 up but not showing up from HA. Have added to custom_components/media_player… then added in the mediaplayer but no dice. :frowning:

2017-08-15 22:23:44 ERROR (Thread-5) [custom_components.media_player.ps4] Command failed: ps4-waker -c /home/homeassistant/.homeassistant/.ps4-wake.livingroom.credentials.json -d -t 5000 search

1 Like

Thanks for the info on that, I’ll guess I’ll wait a bit with Hass.io aswell then (if it ever will support this).

Hello everyone! Some time ago my PS4 switch state stopped reflecting the actual state of the PS4. It’s just the switch state element that’s broken, actual operation of the commands is fine.

“nc -z -w” was working but has since stopped, I believe this coincided with the release of a new firmware for the PS4.

Trying nmap and “ps4-waker search” and grep the relevant parts does not seem to work either. If anyone has a working command_state section I would greatly appreciate it if you could share it.

Edit: found the issue with telnet, I mixed a { with a ( where I shouldn’t have. Nothing quite like posting on the internet to make you feel stupid :slight_smile: