How I Made My Unraid VM Self-Heal with Discord Alerts

πŸ’‘ "My Home Assistant VM paused itself randomly. One day my lights didn't turn on and I knew it had to be fixed... permanently."

Running Home Assistant in a VM on Unraid is a solid approach β€” until the VM unexpectedly pauses and takes your smart home with it. This happened to me daily at one point.

So I built a simple, self-healing watchdog script:

  • Detects when a VM is paused
  • Sends me an instant Discord alert
  • Automatically resumes the VM
  • Confirms whether the resume was successful

No plugins, no docker containers, no fancy packages β€” just a clean Bash script and a Discord webhook.


πŸ“¦ What You'll Need:

  • Unraid (6.12+ or 7.x)
  • virsh (comes with Unraid)
  • Discord (with webhook)
  • User Scripts plugin (available via Community Apps)

πŸ› οΈ Step-by-Step Setup

1. Create a Discord Webhook

  • Go to your server > channel > βš™οΈ β†’ Integrations β†’ Webhooks
  • Create one, name it (e.g. "Unraid Alerts")
  • Copy the webhook URL

2. Install User Scripts Plugin

  • Go to Apps > Install User Scripts
  • Open it via Settings > User Scripts

3. Add the Script

#!/bin/bash
VM_NAME="Hass"
STATE_FILE="/tmp/vm_${VM_NAME}_last_state"
WEBHOOK_URL="https://discord.com/api/webhooks/your-webhook-url"

CURRENT_STATE=$(virsh domstate "$VM_NAME" 2>/dev/null)
LAST_STATE=$(cat "$STATE_FILE" 2>/dev/null || echo "unknown")
echo "$CURRENT_STATE" > "$STATE_FILE"

if [[ "$CURRENT_STATE" == "paused" && "$LAST_STATE" != "paused" ]]; then
  curl -H "Content-Type: application/json" -X POST \
    -d '{"content": "🚨 VM '"$VM_NAME"' paused. Trying to resume..."}' "$WEBHOOK_URL"

  virsh resume "$VM_NAME"
  sleep 5

  NEW_STATE=$(virsh domstate "$VM_NAME" 2>/dev/null)
  if [[ "$NEW_STATE" == "running" ]]; then
    curl -H "Content-Type: application/json" -X POST \
      -d '{"content": "βœ… VM resumed successfully."}' "$WEBHOOK_URL"
  else
    curl -H "Content-Type: application/json" -X POST \
      -d '{"content": "❌ VM could not be resumed."}' "$WEBHOOK_URL"
  fi
fi

4. Schedule It

  • Set the script to run every 5 minutes using cron: */5 * * * *

πŸ§ͺ Result:

  • I pause my VM β†’ get notified on Discord β†’ it resumes automatically.
  • I get a second message confirming it worked β€” or didn’t.

πŸ” Bonus Ideas:

  • Extend it to multiple VMs
  • Add Telegram or Pushover alerts
  • Write logs to flash for auditing:
    echo "$(date): VM $VM_NAME paused/resumed" >> /boot/logs/vm_watchdog.log

πŸ’¬ Final Thoughts

This lightweight solution gives me peace of mind. My VM can still fail β€” but now it won't go unnoticed or unresolved. And if Home Assistant is critical in your setup like mine, it’s 100% worth the few minutes to set up.