Switch for Playstation 4

Thanks for this!

Can you try
sudo find / -name "*ps4-wake.credentials*"
Perhaps your credentials file is not located there

I created a custom media player instead of all of the custom switches, but it still uses the ps4-waker tool.

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

Any feedback is apreciated

2 Likes

@hmn that sounds really cool. About to start playing with it. How do you declare it in configuration.yaml? Is it autodiscovered?

you just create a media_player like this

media_player:
  - platform: ps4
    host: 10.254.2.191

This looks incredible! Sorry to be such a noob, but where do I add the .py file? Do I just add it to my .homeassistant folder where my configuration.yaml is?

look at the file structure in https://github.com/hmn/home-assistant-config you just have to add the custom_components folder to your config dir

itā€™s also described here https://home-assistant.io/developers/component_loading/

Ah brilliant, itā€™s up and running!

Weirdly though it looks like I canā€™t wake/unwake the ps4 anymore. When I use

sudo ps4-waker

from ssh, it works fineā€¦ but my switch and media player donā€™t turn the ps4 on or off respectively.

Is there a setting somewhere I need to tweak?

I use docker so it might be why I donā€™t need to sudo, try changing the command in the module to sudo ps4-waker

I changed the bit just after ā€˜cmd=ā€™ to add sudo (in the python script) and it didnā€™t work. Although I did also change the command in the switch to sudo too, as below:

switch:

  • platform: command_line
    switches:
    playstation_4:
    command_on: ā€˜sudo ps4-wakerā€™
    command_off: ā€˜sudo ps4-waker standbyā€™
    command_state: 'nmap -p 9295 my_ps4_ip_address | grep -w -Eo ā€œopenā€ ā€™
    value_template: ā€˜{{ value == ā€œopenā€ }}ā€™
    friendly_name: ā€œPlaystation 4ā€

and that didnā€™t work either. Itā€™s really bizzare, it was working this morning! This leads me to believe maybe something else is going on.

Iā€™ve updated my node-js to the latest stable release too, as others mentioned in this thread.

Thanks for your help on this, us noobs greatly appreciate it! Also Iā€™m learning python atm so this is a great .py script to start with!

Edit: Just followed some instructions above that got me into /root/ on my pi and change visudo. Did all that and my switch now works - woo! Media player recognises the ps4 when itā€™s on, but the on/off button doesnā€™t quite work. For now Iā€™m just going to disable it and Iā€™ll try again later.

Iā€™m only 4 days into using Home Assistant but Iā€™m incredibly impressed at the amazing work from all contributors!

@hmn , Iā€™ve tried your script and it works flawlessly so far. My only issue was that my credentials file was stored at /home/homeassistant/ and not /home/homeassitant/.homeassistant/ .

I would love to add button controls inside the PS4 media player front end so you can navigate simple applications such as YouTube and Netfilx. I will try work on it to help out.

It looks like I keep getting this error:

17-04-26 16:09:57 ERROR (Thread-9) [homeassistant.components.switch.command_line] Command failed: nmap -p 9295 PS4_IP_ADDRESS | grep -w -Eo ā€œopenā€

Not sure why this is erroring since my ps4 waker actually works from the switch. nmap is installed too.

Someone has posted the answer above:

Making it work in HA
Great change that this command will not be working yet if you try to run it as a shell command in Home Assistant.
So what i did is:
Login to putty and then:
sudo su
visudo

then find this line:

User privilege specification

root ALL=(ALL:ALL) ALL

copy and past the root line. So now you have two the same lines under each other. Then change root to the username where Home Assistant is running. ( you can find that name in the path to you configuration.yaml.) I think for an all in one install it will be ā€œhassā€ and for a hassbian install like i have it is ā€œhomeassistantā€

So the result will be:

User privilege specification

root ALL=(ALL:ALL) ALL
homeassistant ALL=(ALL:ALL) ALL

press ctrl + x and then Y and then Enter.

After this go to the sudoers.d folder:
cd /etc/sudoers.d

And create a new file like this:
sudo nano 010_homeassistant-nopasswd

In this file copy the following line
homeassistant ALL=(ALL) NOPASSWD: ALL

and close it with ctrl + X, then Y then press Enter.

I tried all that and just double checked, and itā€™s definitely all done. Just checked visudo and all those edits are completed, same with the cd /etc/sudoers.d folder contents.

I did all that and the switch started working, but the media player still wonā€™t budge.

This looks nice! What does the ps4-games.json file look like?

Would love to see an official PR.

the ps4-games.json is auto updated every time you start a game and it looks like this

{
  "CUSA01116": "YouTube", 
  "CUSA02676": "DRTV", 
  "CUSA02491": "Mass Effect\u2122", 
  "CUSA01703": "Plex", "CUSA00127": "Netflix"
}

I can add it to the main project and create a pull request, but I was unsure if it was a good idea because of the ps4-waker requirements

Yeah, I forgot about that. Being that itā€™s not in Python I doubt it would be allowed.

I run in Docker and use a different default port, anyway I can specify that in the configuration.yaml?

Edit: Add to schema and then adjust on line 203-ish? Is that it? testing now.

I added an option to specify the port but it doesnā€™t seem to register the proper state of the PS4