Restart binding from Rule

Hi NCO,

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.

The script:
restartspotify.py

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.

BR
Chris

1 Like