Playstation 4/PS4 custom component

@Sitnalta Hey, did you manage to do something for that automation? I’m trying to do the same for Netflix/Prime Video.

@hmn is there a way the title ID can be read by Home Assistant and used in Automation or scripts?

Can’t get this to work keep getting error
[custom_components.media_player.ps4] Error decoding ps4 json : Expecting property name enclosed in double quotes: line 1 column 3 (char 2)

Running on Raspbian Stretch, HA version 51.2

Just an update to my previous post, I’m working on an automation to call Hue scenes based on the state of the media player.

With my limited (being generous :slight_smile: ) scripting/python knowledge, I couldn’t find an entry in the entity ID which indicated what title was playing, or something similar to a ‘status’ of the streaming services like Neflix/Prime when used from the PS4. So, my current automation only checks the PS4 itself. Its based on the below project:

I’ll start a new thread on it once I’ve done all the tests and confirmed its working correctly. I’ve used the Automation Editor frontend and then edited the automation.yaml file to modify the conditions with AND/OR logic.

Hi @all
i also have troubles to get it to work.

Log:

2017-08-30 18:56:05 ERROR (MainThread) [homeassistant.components.media_player] Error while setting up platform ps4
Traceback (most recent call last):
  File "/home/hass/.homeassistant/custom_components/media_player/ps4.py", line 336, in search
    data = json.loads(value)
  File "/usr/lib/python3.4/json/__init__.py", line 318, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.4/json/decoder.py", line 343, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.4/json/decoder.py", line 359, in raw_decode
    obj, end = self.scan_once(s, idx)
ValueError: Expecting property name enclosed in double quotes: line 1 column 3 (char 2)

HA Version 0.52.1

I have a problem with ps4-waker. I have RPi3 with Raspbian Jessie. I did the following:

sudo apt-get update
sudo apt-get install npm
sudo npm install ps4-waker -g

And now the ps4-waker always reports an error:

/usr/local/lib/node_modules/ps4-waker/bin/cmd.js:3
var {Detector, Device, Socket} = require ('../')
     ^
SyntaxError: Unexpected token {
     at Module._compile (module.js: 439: 25)
     at Object.Module._extensions..js (module.js: 474: 10)
     At Module.load (module.js: 356: 32)
     at Function.Module._load (module.js: 312: 12)
     at Function.Module.runMain (module.js: 497: 10)
     at startup (node.js: 119: 16)
     at node.js: 906: 3

npm and nodejs are correctly installed.

npm --version
1.4.21

nodejs --version
v0.10.29

What I’m doing wrong?

UPDATE:
I found the solution: Switch for Playstation 4

1 Like

sudo npm install -g --unsafe-perm homebridge

Try this… Mine worked after installing it. It was the only difference between my mates set up which was working and mine which wasn’t.

It worked after

Anyway to have this as a HASS.io add on?

1 Like

Nope. Hass.io blocks ssh so you won’t even be able to install it.

Isn’t that if you were to manually install, what if it was through an ‘official’ add on? Add ons like the homebridge one for HASS install additional packages.

For Hass.io search for PS4 Waker Bridge

1 Like

Does the Hassio add-on work? I haven’t yet tried. I just moved and reset my whole system with hassio. Haven’t yet gotten around to adding the PS4.

What’s the story with the github image list and it being updated? I have a lot of games and apps that are not in the list.

As for hosting the images locally, do I just add a new directory in m /www called PS4 for example and drop images in there? Say for Destiny 2, CUSA06172.jpg?

Then in my config, just add local_store: PS4 to the playstation component and reboot?

UPDATE: All good, I sorted it out. This is exactly how it works.Just a tedious effort to find decent images that look good on the HA panel.

1 Like

A summary for anybody searching for a complete PS4 Component installation guide for HASS.IO on Pi, maintained/SSH’d from Windows:

Using: Home Assistant version 0.57.2 (Running HASS.IO), PS4WakerBridge 0.0.2 (HASS.IO Add-On), PS4 System Software 5.01 (PS4 Firmware), PS4 Second Screen (iPhone App) 17.11.2, Cygwin x64 2.882 (for Windows).

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

  1. Install vkorn’s PS4 Waker Bridge HASS.IO Add-On (barebones instructions on vkorn’s github page) by pasting this link https://github.com/vkorn/hassio-addons into …
    Your_HASSIO_ Setup (https://your_HASS.IO_server/hassio/store)
    > Hass.io tab on the left
    > Click the shopping bag in the top-right corner
    > "Add-On Repositories" box
    > Hit “SAVE”
    > Scroll down to see "Vlad's repository" and install the PS4WakerBridge.
  • 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
  1. 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), you’ll need to copy a modified ps4.py file to HASSIO/config/custom_components/media_player (right click “RAW” and save-as on the github page). Eventually you’ll also need a .ps4-wake.credentials.json and ps4-games.json file in the HASSIO/config/ folder. You can create dummy files of these for now if you like.

  2. danrspencer provided more detail here on the SSH process to create credentials between the Pi and the PS4. He believes that 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).

  • SSH into the true root of your Pi running HASS.IO: Use the SSH home-assistant guide 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, put the public key onto the root of the boot partition of your HASS.IO Pi’s SD card (the only partition readable by Windows – !!!DO NOT REFORMAT THE OTHER PARTITIONS AS PROMPTED BY WINDOWS!!!), then install the private key into your SSH software on your Windows machine. Put the SD card back into the Pi, boot up, then SSH into your Pi’s root (ssh [email protected] -p 22222). For some reason, I couldn’t get PuTTY to work (even though it works fine logging into my HASS.IO's command line). But Cygwin could log in as long as it got to create its own RSA keys (though I had to use a lower-case k in Cygwin for the
    ssh-add -k ~/.ssh/id_rsa
    command).

  • Once you have root access to your Pi, follow danrspencer’s instructions. Your command-line should resemble something like this:

command: docker ps

root@hassio:~# docker ps
CONTAINER ID        IMAGE                                      COMMAND                                                                                  CREATED             STATUS              PORTS       NAMES
1808b5652af8        vkorn/armhf-ps4waker                       "/usr/bin/entry.sh..."   7 minutes ago       Up 7 minutes       addon_e5829d31_ps4waker
138929e07d9d        homeassistant/raspberrypi3-homeassistant   "/usr/bin/entry.sh..."   7 minutes ago       Up 7 minutes       homeassistant
99954083a6f4        homeassistant/armhf-addon-samba            "/usr/bin/entry.sh..."   8 minutes ago       Up 7 minutes       addon_core_samba
dbaeba95d8a1        homeassistant/armhf-addon-ssh              "/usr/bin/entry.sh..."   8 minutes ago       Up 7 minutes        0.0.0.0:22->22/tcp       addon_core_ssh
8e5ea1a5ca0c        homeassistant/armhf-addon-duckdns          "/usr/bin/entry.sh..."   8 minutes ago       Up 7 minutes       addon_core_duckdns
21d9085195e1        homeassistant/armhf-addon-rpc_shutdown     "/usr/bin/entry.sh..."   8 minutes ago       Up 7 minutes       addon_core_rpc_shutdown
1b2b91e3589d        homeassistant/armhf-addon-mosquitto        "/usr/bin/entry.sh..."   12 minutes ago      Up 8 minutes        0.0.0.0:1883->1883/tcp, 0.0.0.0:       8883->8883/tcp   addon_core_mosquitto
2b568e890a3c        homeassistant/armhf-hassio-supervisor      "/usr/bin/entry.sh..."   10 days ago         Up 12 minutes       resin_supervisor

commands:
docker exec -it [id for ps4-waker container] /bin/bash
npm install -g ps4-waker

root@hassio:~# docker exec -it 1808b5652af8 /bin/bash
bash-4.3# npm install -g ps4-waker
/usr/bin/ps4-waker -> /usr/lib/node_modules/ps4-waker/bin/cmd.js
/usr/lib
└─┬ [email protected]
  ├── [email protected]
  └─┬ [email protected]
    └── [email protected]

Attempt to remove any data:

bash-4.3# rm /data/ps4
rm: can't remove '/data/ps4': No such file or directory

Run ps4-waker to authenticate Pi to PS4:

bash-4.3# ps4-waker -c /data/ps4-creds.json
WAKEUP sent to device... 192.168.1.19
Error: Device didn't wake in time
    at loop (/usr/lib/node_modules/ps4-waker/dist/waker.js:286:26)
    at /usr/lib/node_modules/ps4-waker/dist/detector.js:141:9
    at Detector.<anonymous> (/usr/lib/node_modules/ps4-waker/dist/detector.js:120:26)
    at emitTwo (events.js:106:13)
    at Detector.emit (events.js:191:7)
    at Socket.<anonymous> (/usr/lib/node_modules/ps4-waker/dist/detector.js:61:18)
    at emitTwo (events.js:106:13)
    at Socket.emit (events.js:191:7)
    at UDP.onMessage (dgram.js:549:8)

Ok, that time crashed and burned. Try again. Don’t forget that you need to install the PS4 Second Screen app on your phone, and head to your PS4’s Settings > PlayStation App Connection Settings to get a PIN code.

bash-4.3# ps4-waker -c /data/ps4-creds.json
WAKEUP sent to device... 192.168.1.19
Logging in...
Login error: PASSCODE_IS_NEEDED
bash-4.3# rm /data/ps4-creds.json
bash-4.3# ps4-waker -c /data/ps4-creds.json
No credentials; Use the PS4 Second Screen App and try to connect to PS4-Waker
Got credentials!  { 'client-type': 'i',
  'auth-type': 'C',
  'user-credential': 'x#x###x#x####x#####xxx#x##x##x#x###x##xx#########xx#x###xxx##x#' }
Go to 'Settings -> PlayStation(R) App Connection Settings -> Add Device' on your PS4 to obtain the PIN code.
Pin code> ########
Logged into device! Future uses should succeed

That worked! The credential is listed as 'user-credential': 'x#x###x#x####x#####xxx#x##x##x#x###x##xx#########xx#x###xxx##x#' Copy the long string, and save it in a text file for now.

Don’t forget to nab the ps4-creds.json file data before we exit. If you miss it now, it seems to get destroyed on system reboot. (Your key seems to always stay the same though, even if you re-do the ps4-waker installation and everything.) I don’t know how to copy the file, but we can extract its contents using a text editor:

bash-4.3# ls
bin        dev        home       media      proc       run        sbin       sys        tmp        var
data       etc        lib        mnt        root       run.sh     srv        templates  usr
bash-4.3# cd data
bash-4.3# ls
options.json    ps4-creds.json
bash-4.3# "${EDITOR:-vi}" ps4-creds.json

You should see this inside the key file:
{"client-type":"i","auth-type":"C","user-credential":"x#x###x#x####x#####xxx#x##x##x#x###x##xx#########xx#x###xxx##x#"}
Copy that and paste it into a file named .ps4-wake.credentials.json and save that file into your HASSIO\config folder.

Use :q, Enter, to quit the text editor. Then exit bash.

bash-4.3# exit

We’re almost done. This last bit is subtle and SUPER important.

  1. Set up the PS4WakerBridge Add-On:
    Copy and past this into your Options area. Note that the port should be 3031 and that you should use your credential key.
{
  "port": 3031,
  "devices": [
    {
      "client_type": "i",
      "auth_type": "C",
      "credentials": "x#x###x#x####x#####xxx#x##x##x#x###x##xx#########xx#x###xxx##x#"
    }
  ]
}
  • Hit save.

  • Make sure that you 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. Everything should work

Best of luck

19 Likes

nice, thanks for the clear guide. I struggled getting this setup before you have inspired me to try again!

2 Likes

Much appreciated for the detailed walkthrough for those not familiar with HA yet. I was also trying to follow all the different advice listed here but was currently stuck using PuTTY to accept the key. I’ll try your advice using Cygwin!

1 Like

That’s a nice guide that will help a bunch of people. Thanks! :slight_smile:

1 Like

New to home assistant, i’ve mostly set up the component according to Wheezy’s guide but have hit one snag. The log reads as follows:

2017-12-12 16:44:40 ERROR (SyncWorker_3) [custom_components.media_player.ps4] Failed to call on: HTTPConnectionPool(host=‘172.30.33.0’, port=3031): Max retries exceeded with url: /ps4/192.168.0.110/on (Caused by NewConnectionError(’<urllib3.connection.HTTPConnection object at 0x71f5a790>: Failed to establish a new connection: [Errno 111] Connection refused’,))

2017-12-12 16:44:44 ERROR (SyncWorker_13) [custom_components.media_player.ps4] Failed to call info: HTTPConnectionPool(host=‘172.30.33.0’, port=3031): Max retries exceeded with url: /ps4/192.168.0.110/info (Caused by NewConnectionError(’<urllib3.connection.HTTPConnection object at 0x71b51bd0>: Failed to establish a new connection: [Errno 111] Connection refused’,))

it appears like a network issue but not sure how to go about solving it.

never mind I was able to get it to work, although I’m not sure exactly how.

1 Like

Also want to say thank you for this - I’m sure you’ve saved me hours of hassle! I finally got it running and can select ‘source’ (aka launch a game), and turn off the PS4. Oddly, I can’t turn it on though.

For anyone stuck with the SSH key not letting you login for root access on port 22222, I had the same problem until I copied the public key text from the HA config screen for normal SSH access. That was one long text string without the comments before and after versus the PUTTY file which had comments. Once I switched for the single long line of text in authorized_keys it was fine.

1 Like

I get this message when the PS4 is unplugged sometimes. Not sure if that was part of the problem or not. But I’m glad it resolved itself