I need some advise regarding restarting a binding from rules.
I have installed sshpass, and can run the command from from ssh terminal and restart binding without typing karaf password. I have created a python script and put it in script folder. I can run the script from ssh terminal
like: ./restartspotify.py, and the binding is restarting.
BUT, i can not get my rule to execute the python script without error.
rule:
rule "Restart Spotify Binding"
when
Thing “spotify:device:dd997e5e:1a729da3-76b9-4234-a426-1c445aa638a2” changed or
Item Restart_Spotify received command ON
then
var status = ThingAction.getThingStatusInfo("spotify:device:dd997e5e:1a729da3-76b9-4234-a426-1c445aa638a2").getStatus()
//logError("Debug", "AudioGruppe status | " + status)
if (status.toString() == 'OFFLINE')
{
//logError("Debug", "Attempting to restart spotify binding")
executeCommandLine("/etc/openhab2/scripts/restartspotify.py")
}
end
openhab.log
2017-09-16 19:54:17.434 [INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine '/etc/openhab2/scripts/restartspotify.py’
2017-09-16 19:54:19.090 [WARN ] [shd.server.session.ServerSessionImpl] - exceptionCaught(ServerSessionImpl[null@/127.0.0.1:40886])[state=Opened] IOException: Connection reset by peer
Any advise would be appreciated
Yes, It is working fine now. What I did was the following:
Install sshpass
Make a rule
Make a script, which is chmod 0755 and chown openhab:openhabian.
rule file:
rule "Restart Spotify Binding"
when
Item Restart_Spotify received command ON
then
//logInfo(logfile, "AudioGruppe spotify device changed to " + spotify:device:xxxxxxxx.state);
var status = ThingAction.getThingStatusInfo("spotify:device:xxxxxxx").getStatus()
logError("Debug", "AudioGruppe status | " + status)
//if (status.toString() == 'OFFLINE'&& Spotify_AudioGruppe_SpotifyConnectDeviceActive.state=="ON")
{
logError("Debug", "Attempting to restart spotify binding")
executeCommandLine("/etc/openhab2/scripts/restartspotify.py")
//logInfo(logfile, "Command result: " + output);
}
end
The rule is not clean, as I have used different logics inside it over the last few weeks. But I it executes a script file when i toggle my item: Restart_Spotify. It should be possible to restart binding when detecting that channel is offline.
I’m using openhabian and standard habopen password for the karaf console. So that’s what is used in the python script. So when using sshpass, the script will fill in authentication automatically when executing a script.
I have a script in the folder with owner and permissions as suggested.
If I run the script from console it executes my binding restarts. If I run it from a rule I can see that the rule ran and the command was sent but the binding does not restart.