I have a problem with Xiaomi Mi Smart Home Bridge. If for any reason bridge will lose connectivity to WiFi (router restart/lack of power) the bridge stays offline.
If I will disable/enable it everything starts to work normally. Do I need to write a rule to periodically check if it’s offline and try to turn it online or it’s a bug in the bridge and it should try to heal it self after some time?
I don’t think it’s an issue in the bridge, all the device in the mi app still works. Interesting enough is that renaming the bridge will bring all the things back online.
Maybe a rule that checks the status of the bridge and when it’s online it renames the bridge with an added increasing number?
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.
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
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:
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.