Playstation 4/PS4 custom component

add port: 10931 to your configuration. The number can be anything above 1024 and below 65535

I added 10931. The config now looks like this:

media_player:
  - platform: ps4
    host: 192.168.88.196
    port: 10931
    name: Playstation
    filename: /home/homeassistant/.homeassistant/.ps4-wake.credentials.js

The credential file above contains the path to the actual credential file.

But to no avail. It still won’t switch off. The funny thing is it was in an off state and I had the following errors in the log:

[pyps4.ddp] failed to send data using socket, timed out

I then switched it on manually and it switched to an idle state. The attempt to then turn it off, was not successful with no errors in the log file. I don’t know whats going on. I’m starting to think it will be easier to use shell commands rather than the media player component. :frowning:

for me the component is working on raspberry pi 3 (regular python install), but
constant

failed to send data using socket, timed out

I see there is no fix yet?

Hi @hmn,

The component is brilliant. Yesterday i submitted a pull request for FIFA 18 coverand it’s already merged!
But i can’t get the artwork in my sensor in hass.io. My config.yaml

  media_player:
  - platform: ps4
    host: http://192.168.***.***:3031
    ps4_ip: 192.168.***.***
    name: PlayStation 4
    local_store: games

Reading de code tell’s me that, by default, the online resource is used. But no image is shown.

Edit:
Removing the optional parameter: local_store gives me a config validation error:
Invalid config for [media_player.ps4]: string value is None for dictionary value @ data['local_store']. Got None.

Any suggestions?

Hey guys…

This took me a while to get working, but I got there in the end.

I’m running HA in a venv on raspbian, 0.75.

The config that finially worked for me was simply (after trying various additions):

  - platform: ps4
    host: 192.168.0.xx
    filename: /home/homeassistant/.homeassistant/ps4_wake_credentials.json
    local_store: games

After pairing ps4-waker, I copied the credentials that were displayed directly out of the terminal.

However when HA tried to run ps4-waker I got this error:

undefined:1
{ 'client-type': 'i',
  ^
SyntaxError: Unexpected token ' in JSON at position 2
    at JSON.parse (<anonymous>)
    at /usr/local/lib/node_modules/ps4-waker/dist/waker.js:170:33
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:511:3)

So I went and found the credentials file that ps4-waker makes.
(I ran ‘ls -al’ in the root directory and it showed up as .ps4-wake.credentials.json)
I did sudo nano .ps4-wake.credentials.json and copied the contents to my credentials file in HA. Now it works? The only difference seems to be the use of " instead of '.

My ps4_wake_credentials.json looks like this (with e6b27c ect instead of x’s):

{"client-type":"i","auth-type":"C","user-credential":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}

What really helped me was running the command the HA was trying to run, in the terminal to see if it worked. This was:

ps4-waker -c /home/homeassistant/.homeassistant/ps4_wake_credentials.json -d 192.168.0.xx

Anyway I don’t know if that little story will be of use to anyone, but I thought I’d post it here as I’ve been struggling to get this to work for a while.

2 Likes

Just created a summary for anybody searching for a complete PS4 Component installation guide for HASS.IO on Pi, using PuTTY on windows this is how i got it working.

Using:

  • Home Assistant version 0.77.3 (Running HASS.IO on HassOS),
  • PS4WakerBridge 0.0.2 (HASS.IO Add-On),
  • PS4 System Software 6.00 (PS4 Firmware),
  • PS4 Second Screen (iPhone App) 17.11.2,
  • Putty
  • Puttygen.exe

Note: You’ll need to SSH into HASS.IO 61 to install custom software. You should back up your Pi’s SD card using Win32DiskImager before continuing!

Install vkorn’s PS4 Waker Bridge HASS.IO Add-On

  1. Install vkorn’s PS4 Waker Bridge HASS.IO Add-On

(barebones instructions on vkorn’s github page 47) by pasting this link
into Your_HASSIO_ Setup

https://your_HASS.IO_server:8123/hassio/store

> Hass.io tab on the left
> Click the addon store.
> "Add-On Repositories" box
> Hit “SAVE”
> Scroll down to see "Vlad’s repository" and install the PS4WakerBridge.

Add Media Player PS4 Config to Home Assistant configuration.yaml

Now add the following code to your configuration.yaml:

media_player:
- platform: ps4
host: http://**YourHassioIP**:3031
ps4_ip: **YourPS4's IP**
name: PlayStation 4
local_store: games

The location of ps4 images local_store: games
resides at

 \\hassio\www\games on hassio samba shares.

8

create if not already

Note
Since the PS4 Waker Bridge HASS.IO Add-On is based on hmn’s old HASSbian component (relevant, though a bit deprecated, instructions available on hmn’s github page 18), you’ll need to copy ps4.py see link to

HASSIO/config/custom_components/media_player

Create 2 new blank files

  1. .ps4-wake.credentials.json
  2. ps4-games.jsonfile

Save to the HASSIO/config/ folder. You can create dummy files of these for now if you like.

Gaining true root access to HassOS

HassOS based Hass.io

Use a USB drive formatted with FAT, ext4, or NTFS and name it CONFIG (case sensitive). Create an authorized_keys file containing your public key, and place it in the root of the USB drive. From the UI, navigate to the hass.io system page and choose "Import from USB". You can now access your device as root over SSH on port 22222. Alternatively, the file will be imported from the USB when the hass.io device is rebooted.

From <https://developers.home-assistant.io/docs/en/hassio_debugging.html#hassos-based-hassio&gt;

danrspencer provides more detail here 73 on the SSH process to create credentials between the Pi and the PS4

SSH into the true root of your Pi running HASS.IO:

Use the SSH home-assistant guide 61 to get to the true root of your Pi from Windows.

To do this, you’ll need to

  • Create a public/private RSA key pair, (use PuTTygen.exe to create a new public and private key)
  • Copy public key text generated by puttygen.exe
  • 2 ways to add the public key to hassos

Use the feature >hassio >system >import from usb. See

Put the public key text onto the root of the boot partition named authorized_keys ( save with no file extention) of your HASS.IO Pi’s SD card

  • Install the private key into your SSH software on your Windows machine.
  • Put the SD card back into the Pi,
  • Boot up,
  • SSH into your Pi’s root (ssh [email protected] -p 22222).
  • Type the passphrase you used when creating the private key with puttygen.exe earlier

Setup and install PS4Waker On Root Access of HassOS

the credential file must be created during a handshake between the PS4 and the Pi for the component to work correctly (thus necessitating SSH into the Pi to install PS4-waker).

Once you have root access to your Pi, follow danrspencer’s instructions 74. See below for summary

9
Once the command line comes up, we will need to type one more command to gain true root as our cli is started in the usual way. Type

login

Follow the below code to access the ps4-waker docker image

docker ps

This will list the containers in docker, the container id is needed for the next step. Look for and copy down this requierd container id.

docker exec -it [id for ps4-waker container] /bin/bash

Paste the ps4waker containerid remove brackets.

Install ps4-waker

npm install -g ps4-waker

Delete the ps4-creds.json for now

rm /data/ps4-creds.json

Run ps4-waker and setup again

ps4-waker -c /data/ps4-creds.json

The ps4-creds.json should get re-created after you’ve gone through the setup.

The credential is listed as ‘user-credential’: ( needed for hassio vkorm plugin installed earlier)

'x#x###x#x####x#####xxx#x##x##x#x###x##xx#########xx#x###xxx##x#' 

Copy the generated code similar to the hashes an x’s above. Save it to a text file so we can enter this into our ps4waker bridge plugin on hassio we set up earlier.

Save ps4-creds.json file data before exit. This file is deleted when the system reboots.

Hassio PS4waker Bridge Plugins Settings

This last part is extremely important As it is where the key we gained prior is saved in the hassio ps4waker plugin we set up towards the beginning of the tutorial

Set up the PS4WakerBridge Add-On:

Copy and past this into your Options area.

Note that the port should be 3031

   {
       "client_type": "i",
       "auth_type": "C",
       "credentials": "ba4abe571581xxxxxxxxxxxxxxx4dc7c8caafe0f4fcc36xxxxxxxx605"
          }
      ]
   }

Hit save.

  • Make sure that you have put your .ps4-wake.credentials.json inside the HASSIO\config folder.
  • Your ps4-games.json file should be created automatically and auto-populate inside the HASSIO\config folder. Also double-check that you’re using the correct (modified) ps4.py file inside HASSIO\config\custom_components\media_player.
  • Reboot your Pi.

If everything succeeded then you should have a new media player named Playstation 4

8 Likes

My compliments for the complete guide. I managed to figure it out a few weeks ago, but it took a while. This guide would have saved me lots of time. Brilliant!

1 Like

image PS4-2

I can not look at the images of the games on the HA dashboard.
I can see them in small if I click in the options

How can I solve this problem?

Are u using a local file or the online. My guess is local so I’ll go with that. I also use a universal media player and it displays on that ok but when I try on the overview screen it doesn’t display correctly . I named all my files capitals see below. 8 https://community-assets.home-assistant.io/original/3X/6/a/6a5e9970a79bba66f34013ba0188f68f4f778c3b.png

Tried this and restarted ran ps4 media player and they showed up…

Hi! I’m stuck at ssh key not letting me login for root access on port 22222.
I tried to understant what’s going on but keep failing.

I tried 2 different ways on here, didn’t work.

this is what I did.

  1. gen private/public key pair with gutty gen(or use ssh-keygen, not work too.)
  2. format usb as fat32(or ntfs, still not work) and named CONFIG
  3. put public key in to usb(named authorized_keys)
  4. plug usb to pi3b+
  5. at web ui of hassio > system > import from usb. ( or reboot entire hassio and pi3)
  6. try to access from putty to pi with private.key

but ssh keep saying
$ core-ssh:~/.ssh# ssh [email protected] -p 22222
The authenticity of host ‘[192.168.0.3]:22222 ([192.168.0.3]:22222)’ can’t be established.
ECDSA key fingerprint is SHA256:BeOaU0EYgnIADIp2MyMhl7012o0OsoKaILjhgck5Bes.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘[192.168.0.3]:22222’ (ECDSA) to the list of known hosts.
[email protected]: Permission denied (publickey).

or I tried to login to root directly from putty using port 22222 ,
fail in similar way. server refuse(publickey)

Am I doing it right? or miss something?
If you able to get true root, did you do it with puttygen or ssh-keygen?

-------- self figured…?
clean install from hassio
install only samba share and ssh-server addon.
I use ssh-keygen and move private and public key to window.
use puttygen, I re-made a private key.
and add key to pageant.
move pub key to usb and import from usb & put the same file in sd card’s root.
and than attemp to login from putty to local:22222 directly.
it worked.

Have no idea what actually fix problem but, I hope this can help somebody, or future me.

Thanks a lot for your guide! I finally got ssh as root to hassio.
but I got another error right after that.

when I try to install ps4-waker on my hass.io it become like this.

~ # docker exec -it [ps4waker docker ID] /bin/bash
bash-4.3# npm install -g ps4-waker
Error: could not get uid/gid
[ 'nobody', 0 ]

    at /usr/lib/node_modules/npm/node_modules/uid-number/uid-number.js:37:16
    at ChildProcess.exithandler (child_process.js:211:5)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:886:16)
    at Socket.<anonymous> (internal/child_process.js:342:11)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at Pipe._handle.close [as _onclose] (net.js:497:12)

What should I do with this? I have no idea how can I fix this…

again, self fix lol.
I type this, after that, it worked fine.

bash-4.3# npm config set unsafe-perm true

ps. I think this cuased by hassio x64 ver. I changed it to 32bit ver. it worked fine.

2 Likes

See u sorted it out. I use puttygen

1 Like

Finally! Thanks for everyone on the page!
Especially cheynespc and wheezy for wonderful guide!

These are the point I had a truble.

  1. getting root to hassio
    make authrized_key file from ssh-keygen. authrized_key must dont’t have a comment in the first line when you open it with note+++
  2. install ps4-waker on docker.
    dont use 64bit ver. of hassio. it has problem to install on docker.
  3. initial setup of ps4 waker
  • turn of ps4
  • install ps4 second screen app on phone
  • connect phone to ps4.
  • start setup at ssh
    $ rm /data/ps4-creds.json (this will be helpful when you want to reset start setup, too.)
    $ ps4-waker -c /data/ps4-creds.json
  • open second screen app.
  • there is ps4-waker as another ps4.
  • connect phone to ps4-waker(ps4-waker on ssh ask pin code to you)
  • type pin code to ssh.
    done. follow guides after this.

Im so happy that I finally figured it out.
Thanks again! bye!

2 Likes

I use local file, in the same folder indicated / config / www / games.

Changing the folder does not show me the logo of the game in small (circle), so the configuration is right.

I still do not see the big one in the dashboard.

I have HA installed in docker running on an OSMC install on a RPI3.
On OSMC I have installed node and ps4-waker, then added the component to HA config and set up the creds.

If I SSH into OSMC I can switch the PS4 on/off by running ps4-waker commands but the HA component doesn’t work. I now realise that’s because ps4-waker is outside of the docker container so HA can’t access it.

Is there anyway to get this working within docker?
I tried to build my own docker image with node/ps4waker but can’t install them as there’s no apt-get in the container.

Edit: I got ps4-waker installed inside docker by using this dockerfile:

FROM homeassistant/raspberrypi3-homeassistant
RUN apk add nodejs
RUN apk add npm
RUN npm i ps4-waker -g

Then building the image like this

sudo docker build -t "nadnerb33/raspberrypi3-homeassistant" .

Hi, I lost many hours with this but I can not get it.

I think I’m near but something is wrong.

From ssh all ok. I have exported the .ps4-wake.credentials.json file, with the result of ssh. Here a doubt already, in everything what I have read your client_type is “i”, mine is “a”. I have tried modifying both with “i” and “a” in ps4 waker config and in credentials, without any success

Once installed when start h.a. asked me to set up the mediaplayer, there I paste the credentials as I read. And it generates a new file called .ps4.conf

{   
   "http://192.168.1.xx:3031": {
        "credentials": "{\"client-type\":\"a\",\"auth-type\":\"C\",\"user-credential\":\"ad604c7eae7xxxxxxxxxxxxxxxxxxx0e3d4\"}"
    }
}

And nothing. Of this I am also worried that in the ps4 waker app log it always puts me listening 0.0.0.0:3031, I do not know if it is by default or when it works I will stop seeing 0.0.0.0.

I use duckdns, and that’s why all my connections must be with httpS: \, I’ve tried all the http / https combinings / without anything just the ip … And nothing.

I’m desperate not to get it. Any ideas?

This is my original .ps4-wake.credentials.json

{"client-type":"a","auth-type":"C","user-credential":"ad604c7eaxxxxxxxxxxxxxxxxa4e0e3d4"}

This is my original config. yaml

media_player:
  - platform: ps4
    host: https://192.168.1.xx:3031
    ps4_ip: 192.168.1.xx
    name: PlayStation 4
    local_store: games

I update,

I do not know how I can now see what ps4 does, but I can not control it

When the shutdown generates a lot of errors in the log.
I copy the most extensive

Error doing job: Task exception was never retrieved

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/service.py", line 224, in _handle_service_platform_call
    await getattr(entity, func)(**data)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/media_player/ps4.py", line 390, in turn_off
    self.ps4.standby()
  File "/config/deps/lib/python3.6/site-packages/pyps4/ps4.py", line 89, in standby
    self.open()
  File "/config/deps/lib/python3.6/site-packages/pyps4/ps4.py", line 58, in open
    self._connection.connect()
  File "/config/deps/lib/python3.6/site-packages/pyps4/connection.py", line 46, in connect
    self._socket.connect((self._host, self._port))
socket.gaierror: [Errno -2] Name does not resolve

I think something might be broken in the compnent.

I’m running HASSOS and a while back I lost control of the PS4, it still reads status, but does not take commands.

EDIT: I just redit the connection from inside the ps4 docker and it’s working again. Now I have 2 identical setups, maybe something gets broken with PS4 system update ?

The error is coming from the Python PS4 library in the ddp.py component. My best guess is that there should be a try/execept in the def _send_recv_msg function.

Did you ever figure this out? I’m having the same issue right now.

Thanks

So I think I followed all the instructions, but I’m getting “Platform not found: media_player.ps4” in the logs.
Not even sure how to start troubleshooting…