Switch for Playstation 4

Just wanted to show you, how to switch your ps4 on/off with ha & ps4-waker.
For the switch itself I use the Command-Line Switch to trigger the shell commands of ps4-waker.

- platform: command_line
      command_on: 'ps4-waker'
      command_off: 'ps4-waker standby'
      command_state: 'telnet playstation4 9295 | grep "Connected" > nul && (echo "true") || (echo "false")' 
      value_template: '{{ value }}'
      friendly_name: "Playstation 4"

Greets Jacko


Will this work for the PS3 as well?

1 Like

I don’t think so, because ps4-waker acts like a Playstation App and the App only supports the PS4 with it’s start & sleep features.

no worries, will try a WOL for my PS3

Thanks for sharing. I’m having a bit of difficulty controlling the ps4 through HA. I’ve installed ps4-waker on my raspberry pi and I am able to wake and sleep the ps4 from the command line. However in HA it is always showing as off? I ran the command_state code in the command line and it does return “true” if the ps4 is on but it takes around 15 seconds to complete, is this normal?

yes thats normal.
And sorry it’s not a binary switch it’s a command-line switch.


Hi thank you for sharing! I am trying to set it up aswell.
I have now a switch that i can use to turn it on. But it goes back to off after a few seconds.
So i can’t use it to turn off the ps4.

This command should get the state if i understand well.

command_state: ‘telnet playstation4 9295 | grep “Connected” > nul && (echo “true”) || (echo “false”)’

When i run this command on the pi it wil return true if ps4 is on. But when i run it in the virtual environment (where i installed hass) i get a message: permission denied and it will return false.

Do you know how i can fix this?

Is your virtual Environment a linux system or what?
then try it with a sudo in front of the command.

Yep. My system is RPI 2 with Raspbian jessie and hass installed using the all in one installer. But when i do that with the sudo in the virtual enviroment is asks for a password. But there is no password for hass user in the virtual enviroment.

I know it’s a dumb question, but is telnet even installed?
Because on some rpi’s I had to install it first.

Yes i did install it like this:

pi@raspberrypi:~ $ sudo apt-get install telnet

And in the “pi” promt it is working it shows this (ps4 is on):

pi@raspberrypi:~ $ telnet 9295 | grep "Connected" > nul && (echo "true") || (echo "false")
Connection closed by foreign host.

And this is when i run it in the hass virtual enviroment:

(hass_venv) hass@raspberrypi:/home/pi$ telnet 9295 | grep "Connected" > nul && (echo "true") || (echo "false")
bash: nul: Permission denied

So it looks,like it needs permission, but i can’t give it with the sudo command because then i have to enter a password.

I got mine to work by changing the command state to use nc instead of telnet, which in my case was much quicker at responding. The value template is not needed because nc will return 0 on success, 1 on failure.

Here’s a snippet of my switch definition:

- platform: command_line
      command_on: 'sudo ps4-waker'
      command_off: 'sudo ps4-waker standby'
      command_state: 'nc -z -w 5 9295'

The -z parameter tells netcat to scan for the open port, -w 5 tells netcat to timeout after 5 seconds otherwise it will wait endlessly. If testing in the command line is needed add -v for a more verbose output.

I just got the command_state to execute by changing nul to /dev/nul when i saw your post.

command_state: telnet 9295 | grep "Connected" > /dev/null && (echo "true") || (echo "false")
But i was messing arround with the value template but didn’t get it to work unfortunately.

So i did what you said and it is now working perfectly! thank you!
I installed netcat by:

sudo apt-get install netcat

This is what my config looks like:

- platform: command_line
       command_on: 'ps4-waker -d -c /home/pi/Documents/.ps4-wake.credentials.json'
       command_off: 'ps4-waker standby -d -c /home/pi/Documents/.ps4-wake.credentials.json'
       command_state: 'nc -z -w 5 9295'
       friendly_name: "Playstation 4"

I used the -c parameter to specify where the credentials are stored. Because it was originally stored at a location where from it could not be accessed from the virtual environment. So i copied it to my documents folder.

Maybe this can be some help for someone who is also trying to get this to work.


Do we still need the PS app, or does this method skip it?

You need the ps app one time to get your credentials file.

That’s awesome! I’m gonna try this out myself!

Awesome. I’ve got it all up and running. :slight_smile:

I tried to install ps4-waker but i receive a strange error when I try to execute:

pi@raspberrypi:$ ps4-waker
    var keyNames = argv._.slice(remote).map((key) => key.toUpperCase());                                                  
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   

What’s the problem?



I work throw this thread a couple of Days ago and had a similar Problem.
I had to update nodejs to Version 7.

Run these Commands to update nodejs to latest stable Version:

sudo npm cache clean -f
sudo npm install -g n
sudo n stable




Yeah man!! It works!! Thanks so much!! :slight_smile: