Xiaomi Mi Smart Home Bridge - never goes online by itself

I hope that I finally figured out a way to sort this out. The only way that comes to my mind is to restart the whole binding every time that it will go offline.

I used this tutorial to create SSH keys Tutorial: Restart Binding from rule

Here is the rule that checks the status every 10 min

rule "restart mihome binding when thing is offline"
when
	Time cron "0 0/10 * * * ?"   // every 10 minute
then
	var Status = getThingStatusInfo("mihome:gateway:7c49ebb19279").getStatus().toString()
	if (Status == "OFFLINE" || Status == "UNINITIALIZED") {
	    logInfo("mihome:gatewayOFFLINE", "mihome:gateway is offline! Restarting bridge!")
		sendNotification("XXXXi@gmail.com", "mihome:gateway is offline! Restarting bridge!" )
		var String result = executeCommandLine("sudo /home/openhabian/restart_mihome.sh", 6000)
		logInfo("result", result)
		logInfo("mihome:binding", "mihome:binding restarted")
	}
end

Apart from that I have rule that tries to execute the restart immediately after bridge goes offline

rule "XiaomiBridge offline"
when
    Thing 'mihome:bridge:7c49ebb19279' changed from ONLINE to OFFLINE or
	Thing 'mihome:bridge:7c49ebb19279' changed from ONLINE to UNINITIALIZED
then
    logInfo("XiaomiBridgeOffline", "XiaomiBridge is offline!")
    sendNotification("XXXXX@gmail.com", "XiaomiBridge is offline!!")
	var String result = executeCommandLine("sudo /home/openhabian/restart_mihome.sh", 6000)
	logInfo("result", result)
	logInfo("mihome:binding", "mihome:binding restarted test")
end

Now the content of the file for execution is:

sudo -u openhabian ssh -p 8101 -i /home/openhabian/karaf_keys/openhabian.id_rsa openhabian@localhost bundle:restart org.openhab.binding.mihome

I wanted to execute the command directly in the rule but couldn’t figure it out instead
I configured the script to be allowed to be executed without password prompt like in topic below:

So:

sudo visudo -f /etc/sudoers.d/010_pi-nopasswd

add

openhab ALL=(ALL) NOPASSWD: /path/to/file/to/execute/

in my case

openhab ALL=(ALL) NOPASSWD: /home/openhabian/restart_mihome.sh

What didn’t work

I wanted to execute it as a command directly like here

var String result = executeCommandLine("sudo -u openhabian ssh -p 8101 -i /home/openhabian/karaf_keys/openhabian.id_rsa -t openhabian@localhost bundle:restart org.openhab.binding.mihome", 6000)

But I got error like that one
_

“Sorry, user openhab is not allowed to execute ‘/usr/bin/ssh -p 8101 -i /home/openhabian/karaf_keys/openhab.id_rsa openhab@localhost bundle:restart org.openhab.binding.mihome’ as openhab on openHABianPi.”
_

I tied to configure ssh as command but it didn’t worked.

Second approach was something like this one

var String result = executeCommandLine("sudo openhab-cli console bundle:restart org.openhab.binding.mihome", 6000)

Error:

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: no tty present and no askpass program specified

It would be far easier to figure this out so files wouldn’t be needed.