Restart binding from Rule


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: ./, and the binding is restarting.

sshpass -p ‘habopen’ ssh openhab@localhost -p8101 ‘bundle:restart org.openhab.binding.spotify’

BUT, i can not get my rule to execute the python script without error.


rule "Restart Spotify Binding"
Thing “spotify:device:dd997e5e:1a729da3-76b9-4234-a426-1c445aa638a2” changed or
Item Restart_Spotify received command ON

	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")


2017-09-16 19:54:17.434 [INFO ] [] - executed commandLine '/etc/openhab2/scripts/’
2017-09-16 19:54:19.090 [WARN ] [shd.server.session.ServerSessionImpl] - exceptionCaught(ServerSessionImpl[null@/])[state=Opened] IOException: Connection reset by peer
Any advise would be appreciated :slight_smile:

Best regards

Hi Chris,

have you been able to solve this?


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"
	Item Restart_Spotify received command ON
       //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")
			//logInfo(logfile, "Command result: " + output);			

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.

The script:

sudo -u openhabian sshpass -p habopen ssh openhab@localhost -p8101 bundle:restart org.openhab.binding.spotify

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.

Hope this helps.


1 Like

I am bit stuck and hope someone could help.

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.

sudo -u openhabian sshpass -p habopen ssh openhab@localhost -p8101 bundle:restart org.openhab.binding.openwebnet


2020-03-17 08:49:27.813 [ERROR] [.smarthome.model.script.Thing_Status] - BUS gateway is OFFLINE

2020-03-17 08:49:27.831 [INFO ] [] - executed commandLine '/etc/openhab2/scripts/'

2020-03-17 08:49:27.835 [ERROR] [.smarthome.model.script.Thing_Status] - openwebnet binding restarted

Any ideas or does this not work anymore with OH2.5. I have added the command to the whitelist.

edit … got it working but changed from sshpass to rsa keys