Playstation 4/PS4 custom component

It seems my problem is that HA running as homeassistant user in a python venv can’t get root privileges to wake my ps4.

I am set
cmd: sudo ps-waker'

and I have allow this user in my sudoers config file.

I looked at ps4.py and there is no mention of “cmd” config, is this is still used ?

Try giving it full path. It runs fine in my venv:
cmd: '/usr/bin/sudo /usr/bin/ps4-waker'

Fixed !

I use now an old version of ps4.py and it works.

commit 4c8f409ab4950148ba94032cca451819dbc3aaff

Just updating this thread: I’m using HASS.IO v0.73.1 and still have the ability to stop apps/games, put the PS4 into rest mode, wake up the PS4, and play apps/games all from HASS.IO. I haven’t played with configs to try to get artwork working, so my art still doesn’t work. Sometimes “stopping” apps from HASS actually just pauses the app on the PS4 though and I have to just put the PS4 into rest mode to actually close an app.

Do you think its possible to fix the artwork problem? Everything else is working fine.

How do you put the PS4 into rest mode?

You can put the PS4 into rest mode from the PS4’s main menu, or by pressing the PS4’s power button in ‘HASS.IO’.
@davidlamd89 It should be theoretically possible to fix the art problem, but I don’t know how to code python well enough to fix it (I think the solution may be in the .py file? - maybe another programmer can take a look at it)

1 Like

Mines been working fine for months, just bought a ps slim and its working but the configurator will not dissappear despite already entering the json.

If I restart ha the component stops working until I provide my credentials json again.

Any ideas?

Here’s a pic of the component working but configurator stil showing

I have the same problem. From the command line I can change the source and power the PS4 using the homeassistant user without sudo just fine. The component doesn’t work but shows the current source correctly. Anyone else got a solution?

I got around this by using a command line switch

switch ps4_gta:
  platform: command_line
  switches:
    gta:
      command_on: 'sudo ps4-waker start CUSA00411'
      command_off: 'sudo ps4-waker standby'
      friendly_name: GTA 5

Makes it alot easier to control in automations and emulated hue - so alexa can do it.

1 Like

You may need to give sudo permissions to the ha user - that’s what I did. I also added sudo to the commands in the ps4 python script

I managed to create a command switch; see below. However the switch bounced back after a few seconds. I think this has to do with the fact that the ps4 need some time to start. So is it possible to add a delay to the command_state??

  - platform: command_line
    switches:
      playstation4:
        command_on: 'ps4-waker -d 192.168.1.110 -c /home/homeassistant/.homeassistant/ps4-wake.credentials.json'
        command_off: 'ps4-waker standby -d 192.168.1.110 -c /home/homeassistant/.homeassistant/ps4-wake.credentials.json'
        command_state: 'sudo ps4-waker search | grep -i "200 Ok" > nul && (echo "true") || (echo "false")'
        value_template: '{{ value }}'
        friendly_name: "Playstation"

So it turns out that when i discovered my new ps4 through ps4 waker and re added it, it created the credentials file in a different format to what my old one was in.

I’ve lost the credentials file that caused all the misery (pretty sure it didnt have an ip in it but cannot remember) but here’s the one which does work.

{
    "192.168.0.65": {
        "credentials": "{\"client-type\":\"a\",\"auth-type\":\"C\",\"user-credential\":\"** STRING HERE \"}"
    }
}

Its also worth noting that i did this on 73.1 so that might explain the change - @hmn. Possible?

1 Like

This seems to have worked for me also. Shame the newer versions are so stuffed up.

Does anyone can help me with this?
I have Hass io and RESTwrapper for ps4-waker.
After put ps4 to standby mode i have this 3 times in minute
Failed to call info: {“status”:“Could not detect any matching PS4 device”}

Hello, Can you share ps4.py for the commit 4c8f409ab4950148ba94032cca451819dbc3aaff

I couldn’t find where to download.

Here we go mate. It took me a bit to find it initially, and then again to get the link. I’m yet to get my head around how github works. Anyway, below is the link.

https://github.com/hmn/home-assistant-config/blob/4c8f409ab4950148ba94032cca451819dbc3aaff/custom_components/media_player/ps4.py

Thank you very much @cjsimmons . I will try now. Currently with the latest one. I cannot change the game through HA and seem like the status of media player ps4 say OFF although it actually ON

Hi there,

I am trying to get this up and running. This will make my life so much easier! Thanks for the good work!

I installed nodejs and ps4-waker got everything working. ps4-waker can see my ps4 and control it. I added the custom component, configured the following:

media_player:
  - platform: ps4
    host: 192.168.88.196
    name: Playstation

and it popped up in my home assistant. The problem is, I cant control the ps4 from HA. The media player sits in off state permanently. I think I have done something wrong around the credentials files. I copied the the .ps4-wake.credentials.json credentials file from /root/ to my home-assistant config directory and the contents of the file seem to be good.

I then tried the following config:

media_player:
  - platform: ps4
    host: 192.168.88.196
    filename: /root/.ps4-wake.credentials.json
    name: Playstation

I just get a bunch of permissions issues in the log and errors that the json file could not be read.

I then tried this one:

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

but this just pops up a configurator card in home assistant. entering the same file name does not work.

with the first set of config and the actual credential file in the home assistant configuration directory, I also get the following in the log file:

2018-08-05 10:10:40 ERROR (Thread-3) [pyps4.ddp] failed to send data using socket, timed out
2018-08-05 10:10:49 WARNING (Thread-4) [netdisco.ssdp] Found malformed XML at http://192.168.88.198:59215:
invalid request
2018-08-05 10:10:53 ERROR (Thread-6) [pyps4.ddp] failed to send data using socket, timed out
2018-08-05 10:11:15 ERROR (Thread-3) [pyps4.ddp] failed to send data using socket, timed out
2018-08-05 10:11:37 ERROR (Thread-22) [pyps4.ddp] failed to send data using socket, timed out

I tried everything here. even creating the credentials file in the home-assistant user’s directory. The log reports no errors apart from

[netdisco.ssdp] Found malformed XML at http://192.168.88.198:59215:
invalid request

but the media player does not do anything!

Cant wait to get this running!!!

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