# Xiaomi Mi Smart Home Bridge - never goes online by itself

**URL:** <https://community.openhab.org/t/xiaomi-mi-smart-home-bridge-never-goes-online-by-itself/58605>\
**Category:** Items & Sitemaps\
**Tags:** bridge, xiaomi, xiaomibinding\
**Created:** [December 2, 2018, 10:15pm UTC](https://community.openhab.org/t/xiaomi-mi-smart-home-bridge-never-goes-online-by-itself/58605 "2018-12-02T22:15:31Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Dominik\_Jeziorski](https://community.openhab.org/user_avatar/community.openhab.org/dominik_jeziorski/32/44855_2.png) [@Dominik\_Jeziorski](https://community.openhab.org/u/Dominik_Jeziorski)\
**Post date:** [January 13, 2019, 4:30pm UTC](https://community.openhab.org/t/xiaomi-mi-smart-home-bridge-never-goes-online-by-itself/58605/4 "2019-01-13T16:30:58Z")

</div>

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](https://community.openhab.org/t/tutorial-restart-binding-from-rule/37047)

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:

> [@OpenHAB sudo \[Exec Binding\]](https://community.openhab.org/t/openhab-sudo-exec-binding/34988):
>
> There are situations where you want to use the Exec Binding to trigger something. Sometimes you need the sudo privilege to do this. I would rather try some group specification to reduce the user rights to a minimum, but here is how i got openHAB to be able to execute sudo. Try executing a command as openhab sudo -u openhab sudo -l 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 other…

So:

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

```

add

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

```

in my case

```auto
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.

---

_[View the full topic](https://community.openhab.org/t/xiaomi-mi-smart-home-bridge-never-goes-online-by-itself/58605)._
