A long story short, I cannot get PS4-waker to work from within OpenHAB. I can only find the 1 article on here, where someone said they were having problems getting it to work, but switched from Windows to Debian and they got it to work.
For reference, Im on Armbian (Ubuntu) on an ARM install.
Because the website here thinks Im posting links, when Im not, my pson.sh file will be called pson.shELL in this forum post.
I have:
Created a pson.shELL in /etc/openhab2/scripts
Set execute permission on that (when logged in as myself) - chmod +x pson.shELL
Logged in as myself and confirmed the script works - sudo bash /etc/openhab2/scripts/pson.sh also bash /etc/openhab2/scripts/pson.sh
Ensured the openhab user has sudo permissions - sudo adduser openhab sudo
Edited the passwd file to ensure openhab user is true on bash
openhab:x:116:125:openhab2 runtime user,:/var/lib/openhab2:/bin/false
to
openhab:x:116:125:openhab2 runtime user,:/var/lib/openhab2:/bin/bash
Run the script as the openhab user (when logged in as myself) - sudo --user=openhab bash pson.shELL (which works fine)
Tried multiple variations within my rules to get this thing to work or log results (Note the creation of a directory at the bottom of the rule, which that directory DOES get created, so the rule is working)
rule “PlaystationOn”
when
Item PLAYSTATION received command ON
then
val String results = executeCommandLine=(“sudo bash $OPENHAB_CONF/scripts/pson.sh”)
logInfo(“PlaystationOn”, results)
val String results1 = executeCommandLine=(“bash $OPENHAB_CONF/scripts/pson.sh”)
logInfo(“PlaystationOn”, results1)
val String results2 = executeCommandLine=(“bash@@$OPENHAB_CONF/scripts/pson.sh”)
logInfo(“PlaystationOn”, results2)
val String results3 = executeCommandLine=(“sudo --user=openhab /usr/local/bin/ps4-waker”)
logInfo(“PlaystationOn”, results3)
val String results4 = executeCommandLine=(“sudo /usr/local/bin/ps4-waker”)
logInfo(“PlaystationOn”, results4)
val String results5 = executeCommandLine=("/usr/local/bin/ps4-waker")
logInfo(“PlaystationOn”, results5)
val String results6 = executeCommandLine=(“mkdir /etc/openhab2/NEWDIR1”)
logInfo(“PlaystationOn”, results6)
end
As you can see, Ive tried calling the script pson.shELL multiple ways from the rule, as well as directly calling ps4-waker directly (and created a directory to prove that openhab is executing my commands). Ive added the val String result bits, which seems to be the correct way to output any errors etc back into the openhab logs?
Of which the openhab.log shows the following when I flip the switch on the Basic UI:
Thanks for the quick reply. I cut down my rules file and did as you said. OpenHAB still says its executing the script and still has a null output. Ive cut the rules down to this (two different attempts):
rule “PlaystationOn”
** when **
** Item PLAYSTATION received command ON**
** then**
** val String results7 = executeCommandLine=(“sh@@/etc/openhab2/scripts/pson.sh”)**
** logInfo(“PlaystationOn”, results7, 100000)**
** val String results8 = executeCommandLine=(“ps4-waker”)**
** logInfo(“PlaystationOn”, results8, 100000)** end
My shell script is now as simple as this:
ps4-waker
Ive tried it without #!/bin/bash at the top. Ive tried multiple methods for executing ps4-waker in the shell script:
The above 3 examples say “Command not found” when I run from the command line as either bash or sh (but do work from command line), which is why I simply went for ps4-waker. Ive tried to sudo from within the shell script, outside of it… all work, if I run in from the command line… but not if I run it from within OpenHAB.
The only thing I note that my limited knowledge of Ubuntu has, is that…I installed ps4-waker as my own user account, it is in /usr/local/bin and the file is a symbolic link, pulling in files from around other places (I assume).
So I dont think this is an OpenHAB specific problem as such? Perhaps Ive messed up my permissions somehow? Perhaps I need to setup some other environment permissions?
Any other thoughts? Has anyone who has gotten this working any thoughts/information on how they got it working?
EDIT - Ive logged into the console as the OpenHAB user account and re-run the setup for ps4-waker… and it now works!! I began to suspect that ps4-waker stores information on a user account specific basis, hence if scripts run as OpenHAB user… then OpenHAB user needs to have run the basic setup for ps4-waker.
However, Im still curious as to why my timeout settings didnt work, if anyone can tell me?
That is what I thought, however I had problems and seen someone do it differently. I didnt notice the change you guys specified about being on the execute line… but Im now back at my previous problem. The log file states:
2018-01-15 16:34:35.640 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'home.rules’
2018-01-15 16:34:35.649 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘home.rules’ is either empty or cannot be parsed correctly!
2018-01-15 16:34:35.712 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘home.rules’ has errors, therefore ignoring it: [5,81]: mismatched input ‘,’ expecting ‘)’
[5,87]: mismatched input ‘)’ expecting ‘end’
This is my rules file:
rule "PlaystationOn"
when
Item PLAYSTATION received command ON
then
val String results7 = executeCommandLine=(“sh@@/etc/openhab2/scripts/pson.sh”,30000)
logInfo(“PlaystationOn”, results7)
val String results8 = executeCommandLine=(“sudo ps4-waker”,30000)
logInfo(“PlaystationOn”, results8)
end
If anyone can explain why my timeout settings above didnt work (2 posts above), id really like to know as it looks useful for debugging. EDIT - Double = in the command line!!
For anyone in the future trying to get ps4-waker working, here is my simple switch to turn on your ps4.
To make sure it works, you need to log into the openhab user account at the console and run ps4-waker to set it up AS the openhab account. There may be another way of doing this, but this is the only way I got it to work.
The contents of all my files are as below:
FILE “pson.sh” in the scripts folder
ps4-waker
ITEMS File
String PLAYSTATION “Playstation On/Off”
RULES File
rule "PlaystationOn"
when
Item PLAYSTATION received command ON
then
executeCommandLine=(“sh@@/etc/openhab2/scripts/pson.sh”)
end
Ive only just picked up on this and seen the re-opening of the post.
EDIT: I see youve solved it, but for anyone else, hope this helps
Im having to think back as to what I did, however, you have to log into the server as the Openhab user account, at the desktop. Im not sure if this is what you are doing or not, however, my best guess is that if you are logged in as another user account, and run a shell as the openhab account, some environment variables arent created correctly/used. So please confirm you have logged in as the openhab user.
Additionally, I cannot remember now if I set any other permissions… I dont think so, however, I did write a full post on everything I did to get my whole openhab setup working, including any strange permissions I set. You can find that here
Finally, heres a selection of the way I got the rules working eventually. As you can see, I am not calling a separate script in the end. Eventually, openhab would call the ps4-waker directly without the need for a script. so examples below.
// *************************
// ** PLAYSTATION 4 RULES **
// *************************
// Update switch status to On/Off if device manually switched on
rule "Update Playstation state"
when
Item PSResult changed
then
if (PSResult.state == 0) PLAYSTATION.postUpdate("ON") else PLAYSTATION.postUpdate("OFF")
end
// PLAYSTATION - On/Off
rule "PlaystationOn"
when
Item PLAYSTATION received command ON
then
executeCommandLine=("ps4-waker")
Thread::sleep(2000)
end
rule "PlaystationOff"
when
Item PLAYSTATION received command OFF
then
executeCommandLine=("ps4-waker standby")
Thread::sleep(2000)
end
// PLAYSTATION - Activities
rule "Playstation-Amazon"
when
Item PLAYSTATIONACT received command 0
then
executeCommandLine=("ps4-waker start CUSA00126")
Thread::sleep(2000)
end
rule "Playstation-Netflix"
when
Item PLAYSTATIONACT received command 1
then
executeCommandLine=("ps4-waker start CUSA00127")
Thread::sleep(2000)
end
To see how the PSResult for On/Off works, check this post: