Switch for Playstation 4

strange… i don’t get it running at all:

Okay i noticed there a few people having issues with the on/off button showing the incorrect state.
I have found a solution for this, it’s basically using another program to check on the network if the ps4 is up.

So with this solution there still will be an small delay. When you press the button it will go to on for a few seconds and then go back to off and as soon as the ps4 is fully booted up the switch will stay on until the ps4 is shutdown.( This will all happen in the first 1 to max 2 minutes i think.)

Solution
Install if you don’t have it installed already:
sudo apt-get install nmap

Edit your command line switch.

  playstation_4:
    command_on: 'ps4-waker -d 192.168.1.10 -c /home/pi/Documents/ps4beneden/.ps4-wake.credentials.json'
    command_off: 'ps4-waker standby -d 192.168.1.10 -c /home/pi/Documents/ps4beneden/.ps4-wake.credentials.json'
    command_state: 'nmap -p 9295 192.168.1.10 | grep -w -Eo "open" '
    value_template: '{{ value == "open" }}'
    friendly_name: "Playstation 4"

small explanation what’s going on
As you see the command_state has changed and the value_template is added.
The nmap command will look at port 9295 on the ip address of the ps4 (if correctly specified.) and if it finds the word open it will change the button to on.
if you want you can try this command nmap -p 9295 192.168.1.10 in the console to see what the output is.

Hi, Thanks for reply
I install map and add the command like yours ( I changed my IP)
But I look my log it shows

17-04-01 10:53:32 ERROR (MainThread) [homeassistant.loader] Unable to find component command_on
17-04-01 10:53:33 ERROR (MainThread) [homeassistant.loader] Unable to find component switches
17-04-01 10:53:33 ERROR (MainThread) [homeassistant.loader] Unable to find component value_template
17-04-01 10:53:33 ERROR (MainThread) [homeassistant.loader] Unable to find component platform
17-04-01 10:53:33 ERROR (MainThread) [homeassistant.loader] Unable to find component friendly_name
17-04-01 10:53:33 ERROR (MainThread) [homeassistant.loader] Unable to find component command_off
17-04-01 10:53:33 ERROR (MainThread) [homeassistant.loader] Unable to find component ps4

It looks like an error wich has to do something with indentation (formatting) of your config file.
It looks like you have every line starting at the same proint.
Can you post your config?

here is my config thanks a lot

emulated_hue:
exposed_domains:
- switch

switch:
platform: command_line
switches:
ps4:
command_on: ‘ps4-waker -d 192.168.0.120 -c /home/pi/Documents/.ps4-wake.credentials.json’
command_off: ‘ps4-waker standby -d 192.168.0.120 -c /home/pi/Documents/.ps4-wake.credentials.json’
command_state: 'nmap -p 9295 192.168.0.1 | grep -w -Eo “open” ’
value_template: ‘{{ value == “open” }}’
friendly_name: “ps4”

Track the sun

sun:

switch 2:
platform: broadlink
host: 192.168.0.117
mac: ‘34:EA:34:E3:95:36’
timeout: 15
switches:

Will work on most LG tvs

tv_lg:
  friendly_name: "LG Tv Power"
  command_on: 'JgBYAAABIJISExETETcSEhISEhQQFBETETcROBESEjcRNhM1EjcTNRMTERISNxEUERMSExE2EjYSNhM2EhIROBE3ETcREhITEgAFGwABH0oSAAwzAAEfShEADQU='
  command_off: 'JgBYAAABJ5YSExIUETgTExAVEhMSExEUEjgTNxITEjgRORE5ETkROREUExMQFBE5EhMRFQ8VEhMRORE5EjgSExE5EjgSOBM3EwAFLgABKEsRAAxoAAEnTBEADQU='
fan:
  friendly_name: "Fan"
  command_on: 'JgBYAAABKZEUERU2FTUWDhQRFRAVEBU0FTMVNxUPFTQWDxU1FDUVEBQ0FREVDxUQFBEVEBUPFRAUERU0FTUVNBU1FDUVNRI3FAAFDgABKUcUAAw9AAEpRxUADQU='
  command_off: 'JgBYAAABKZEUERU2FTUWDhQRFRAVEBU0FTMVNxUPFTQWDxU1FDUVEBQ0FREVDxUQFBEVEBUPFRAUERU0FTUVNBU1FDUVNRI3FAAFDgABKUcUAAw9AAEpRxUADQU='
appletv:
  friendly_name: "Apple TV"
  command_on: 'JgBQAAABKJMTEhI3EzYSNxMREzYTNhI3EzYSNxM2ExISEhQREhMTNhMSEjcTERQRExITEhITExETEhI3ExISExI3ExEUERITFAAFeAABKUgUAA0FAAAAAAAAAAA='
  command_off: 'JgBQAAABKJMTEhI3EzYSNxMREzYTNhI3EzYSNxM2ExISEhQREhMTNhMSEjcTERQRExITEhITExETEhI3ExISExI3ExEUERITFAAFeAABKUgUAA0FAAAAAAAAAAA='
light:
  friendly_name: "Light"
  command_on: 'sgCKAAsbDBoMChwaDBsLGwwKGwodGgwbCxsLGwwKHAocGwsbCxsMxhwbCxsMCRwcCwocChwbCxsMGgwJHRsLGwsbDAkdCR0aDBsLGwsbDAobCxwaDBsLGwvHHBsLGwsKHBsLCh0K$
  command_off: 'sgDSAAwKHRsLGwvHHBsMGwsKHBsMChwKHRsLGwwaDAocGwwbCxsMChwKHRoMGwwaDBsLCh0bCwodGgwbDMYdGgwbCwodGgwKHQkdGwsbDBoMCh0bCxsMGgwKHAodGwsbCxsMGws$

Can you format the upper part of your post like you did with the part under ‘Will work for on most lg tv’

So that i can see if there is something wrong with the spacing.
Because there should be some spaces in front of ps4: and the lones under it.

after format the command

emulated_hue:
exposed_domains:
- switch

switch:
platform: command_line
switches:
ps4:
command_on: ‘ps4-waker -d 192.168.0.120 -c /home/pi/Documents/.ps4-wake.credentials.json’
command_off: ‘ps4-waker standby -d 192.168.0.120 -c /home/pi/Documents/.ps4-wake.credentials.json’
command_state: 'nmap -p 9295 192.168.0.1 | grep -w -Eo “open” ’
value_template: ‘{{ value == “open” }}’
friendly_name: “ps4”

Track the sun

sun:
switch 2:
platform: broadlink
host: 192.168.0.117
mac: ‘34:EA:34:E3:95:36’
timeout: 15
switches:

I see the problem. you need spaces in front of the most lines. It should look like the picture beneath.

This is the code:

switch:
- platform: command_line
  switches:
   ps4:
    command_on: 'ps4-waker -d 192.168.1.10 -c /home/pi/Documents/ps4beneden/.ps4-wake.credentials.json'
    command_off: 'ps4-waker standby -d 192.168.1.10 -c /home/pi/Documents/ps4beneden/.ps4-wake.credentials.json'
    command_state: 'nmap -p 9295 192.168.1.10 | grep -w -Eo "open" '
    value_template: '{{ value == "open" }}'
    friendly_name: "Playstation 4"

You can copy and paste this code if you are using a text editor like notepad++ to edit your config. I find it too hard to do with nano. I just use my windows pc to edit the files on the nano. If you are interested in this you can watch this video which explains it.

Yes, the button on home assistant is back
but still have the first question " turn it on, and goes back to off after a few seconds. _"
I’m curious about the path atfer /home/pi/Documents/
ps4beneden <-- in my case, do I add this command too?

/home/pi/Documents/ and everything behind it, is the path to the .ps4-wake.credentials.json file.
ps4beneden is just a folder i created to store this file.

You need to find out your path to this file ( i dont remember where ps4 waker originally stored the file). another handy program which also enables you to search trough the pi is winscp.It can also be done within linux i think but i don’t know much about it.

Edit: You should just use the same path you were using, because you were able to turn on the ps4 when you first messaged me.

Did work for me :slight_smile: thnx

Hi

I have installed nodejs, npm and ps4-waker and tried the waker command “ps4-waker” but im getting this error:

pi@raspberrypi:~ $ sudo npm install ps4-waker -g
/usr/local/bin/ps4-waker -> /usr/local/lib/node_modules/ps4-waker/bin/cmd.js
[email protected] /usr/local/lib/node_modules/ps4-waker
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
└── [email protected] ([email protected])
pi@raspberrypi:~ $ ps4-waker
/usr/bin/env: node: No such file or directory

Any ideas?

Thanks all

this post 20
Explains how to setup node and npm

You may need to restart your session to update paths

Thanks @madbuda.

I’m now getting g an error saying it can’t find my credentials file, try connect to ps4-waker.

Iv connected my ps4 to my app and followed instructions but it’s not going through the credential process people mention here.

Any ideas?

@Rich_Paul if you search this thread most of your questions will be answered…

post 31
copy file from /root to someplace HA can see and change ownership

I reinstalled my home assistant today and right now I’m setting everything back up.
My config used to be this:

  - platform: command_line
    switches:
      playstation4:
        command_on: 'ps4-waker'
        command_off: 'ps4-waker standby'
        command_state: 'ps4-waker search | grep -i "200 Ok" > nul && (echo "true") || (echo "false")'
        value_template: '{{ value }}'
        friendly_name: "Playstation"
      netflix:
        command_on: 'ps4-waker start CUSA00127'
        command_off: 'ps4-waker remote ps'
        command_state: 'ps4-waker search | grep -i "CUSA00127" > nul && (echo "true") || (echo "false")'
        value_template: '{{ value }}'
        friendly_name: "Netflix"```

But not the State is not working any more. Testing it in the command line works. It returns true/false. And I can also see it being called in the log.
But the State in HA does not change. Does anyone have a tipp for me?

Hi there, sorry if the answer to my question is already in this topic here, but there’s a lot to read.
In the moment i have a commandline switch which does nothing, only showing me if the PS4 is on or off.

- platform: command_line
  switches:
    playstation4:
      command_on: "echo on"
      command_off: "echo off"
      command_state: "nc -z -w 5 192.168.xxx.xxx 9295"
      friendly_name: Playstation 4

The History Statistics Sensor shows me how long it was on today.
Is it possible to push a notification to the PS4 screen?
I want to show my son when his 2 hours of playing time per day are over.

Iv tried moving the file (both locations) and it doesn’t exist so I can’t. Even searched the entire pi for a credentials file but hasn’t returned anything.

I installed mine using sudo so would expect to see something on the root folder…

hi mate - im getting the same errors as you, tried running your copy statement and it asks me for credentials - even to move it.

homeassistant@raspberrypi:~ $ cp /root/.ps4-wake.credentials.json /home/homeassistant/ cp: cannot stat ‘/root/.ps4-wake.credentials.json’: Permission denied homeassistant@raspberrypi:~ $ sudo cp /root/.ps4-wake.credentials.json /home/homeassistant/

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

[sudo] password for homeassistant:

any ideas?

pi@raspberrypi:~ $ sudo cp /root/.ps4-wake.credentials.json /home/homeassistant/
cp: cannot stat ‘/root/.ps4-wake.credentials.json’: No such file or directory

also doesnt work…
Any help would be appreciated