How to self-reboot on ZHA failure on VM

I have HA running in a VirtualBox VM. I have a USB passthru on a Zigbee/Z-Wave combo dongle. I had to set it to USB 1.1 passthru or it was super unreliable. Even with all that, the USB passthru stops working like every 7-10 days and all Zigbee stops working. So my questions are as follows:

  1. What entity/trigger do I use to detect a ZHA add-on failure?
  2. How do I make HA self-reboot on that? And like a full hardware (container) reboot not just the standard restart but a reboot. The reason for this is that a standard restart doesn’t typically bring it back. Actually, even a reboot sometimes won’t but it’s at least something.
  3. I also need a way to detect when the last reboot was (or even a way to keep a count/history) so it doesn’t keep rebooting over and over if it doesn’t bring back ZHA

In the absence of all that not working, I’d love a way to get the container restarted from outside virtual box. I have some ideas like if the reboot doesn’t bring back ZHA I could do a full shutdown. Then using a script on the host I can then have it restart the VM.

I think if it keeps doing this I’ll eventually have to get that external IP-based Zigbee bridge but I’m afraid of losing all my device configs. I know there’s a way of keeping it but I don’t want the headache just yet unless I have to.

The service is

hassio.host_reboot

Don(t know. With Zigbee2MQTT I have a sensor that keeps track of the last message of a router. But I don’t know if that works with ZHA.

1 Like

Ok I figured it out, at least 1 method. I did HubZ ZigBee HUSBZB-1 if it shows device offline and then I added a few of the sensors also showing offline, then call hassio.shutdown. On the host side (a windows 10 VM), I have a batch script running vboxmanage.exe to monitor it showing running. Once it shows not running for 4 mins, it restarts it. Kinda clunky but it works 100%. And this is a full shutdown and VM restart which always brings the USB back.

Thanks!