Power-cycling Hubitat when it becomes unresponsive

Lots of folks asking how to reboot their Hubitat because of unresponsive issues. I’m not doing regular reboots but I am monitoring it for network connectivity and cycling power if it’s unresponsive. The benefit is it’s not rebooted unless it needs it. The drawback is that this could happen at an inopportune time. You also need to make sure your monitoring doesn’t reboot your device during an upgrade!

My C4 device is running lots of custom code with 139 devices has been relatively stable and not required an unresponsive reboot recently that wasn’t induced by me adding something or by me leaving many tabs open within the GUI and logs running (I try to close all GUI tabs unless I’m working on something, but I do forget).

To do this, you need a get a sonoff/tasmota-compatible smart plug and monitor and trigger power cycles via another device on your network (Rpi) running Monit.

For the outlet, see this post. You can get 2 plugs for $12.99 on Amazon and can flash via your Rpi: [Release] Tasmota Sonoff Hubitat Driver & Device Support

Install monit on your Rpi and add a hubitat.conf file in the /etc/monit/conf.d dir. Note, if you just want to ping and not connect to port 80 to check for web, you can comment out the last lines starting with “if failed port 80”. Checking ping is probably sufficient and will not put unnecessary taxing on the web server. I’m doing both and haven’t had an issue.

$ more hubitat.conf
check host hubitat with address HUBITAT.IP.ADDRESS
        if failed icmp type echo
                count 5 with timeout 5 seconds
                3 times within 5 cycles
        then exec "/etc/monit/pushover-hubitat-restart.sh"  
    else if succeeded for 3 cycles then exec "/etc/monit/pushover.sh"
        if failed port 80
       for 3 times within 5 cycles
    then exec "/etc/monit/pushover-hubitat-restart.sh"
    else if succeeded for 2 cycles then exec "/etc/monit/pushover.sh"

Here are my Restart and pushover files. You’ll need to create pushover apps and add your appid and userid. You’ll need the IP of the smart outlet so that monit can do the restart.

$ more pushover-hubitat-restart.sh 
#!/bin/bash
OUT1=`curl -s http://IP.OF.PLUG/cm?cmnd=Power%200`
sleep 3
OUT2=`curl -s http://IP.OF.PLUG/cm?cmnd=Power%201`
/usr/bin/curl -s --form-string "token=APPTOKENID" \
--form-string "user=USERAPIID" \
--form-string "message=[$MONIT_HOST] $MONIT_SERVICE - $MONIT_DESCRIPTION $OUT1 $OUT2" \
https://api.pushover.net/1/messages.jsonop

$ more pushover.sh 
#!/bin/bash
/usr/bin/curl -s --form-string "token=APPTOKENID" \
--form-string "user=USERAPIID" \
--form-string "message=[$MONIT_HOST] $MONIT_SERVICE - $MONIT_DESCRIPTION" \
https://api.pushover.net/1/messages.jsonop
1 Like

That sounds like a lot of work. I just use this rule and also have a virtual Switch on my dashboard that I hit if things start getting slow, which hasn’t happened (so far) since I added the second hub.

2 Likes

Agreed it won’t work for everyone. It also doesn’t help if things are slow, but if the device is unreachable from the network, it will reboot it.

3 Likes

If your hub is working, then you would have no need to reboot it. The beauty of the Sonoff devices is that they have an HTTP REST API built in so that they can accept commands independent of Hubitat.

@brianwilson, you might want to watch out for this being automatic though. I had something similar built in ST to reboot my hub. However, this almost triggered when I was performing a firmware upgrade on the hub. And that is the LAST time that I allowed power to be pulled from the hub automatically. I now have port forwarding set up on my router on a random port to port 80 of the hub's power supply and I have authentication turned on on the Sonoff. That way, I can request the power cycle when I'm not at home if necessary. Just make sure you have a vehicle to disable the hard reboot when you need to. Otherwise it's going to cause more trouble than it will solve.

2 Likes

Good point on pulling the plug during a firmware upgrade.