For project overview, see the main README
This watchdog script monitors other Shelly scripts and automatically restarts them if they crash or stop running. It performs periodic checks and ensures critical automation scripts remain operational.
- Periodically checks if the target script is running
- If script is stopped, validates that it contains code
- Automatically restarts the script if it has crashed
- Logs all restart events for troubleshooting
- Continues monitoring in the background
- Deploy your target script first (e.g., power control script)
- Verify the target script is working correctly
- Create a new script in Shelly web interface
- Paste the contents of
check_script_running.js - Configure TARGET_SCRIPT_NAME to match your target script name exactly
- Save and start the watchdog script
- Enable "Run on startup" for the watchdog
Important: The target script must be running and configured before starting the watchdog.
| Name | Description |
|---|---|
| TARGET_SCRIPT_NAME | Exact name of the script to monitor (must match exactly) |
| CHECK_INTERVAL_MS | Check interval in milliseconds (default: 60000 = 1 minute) |
| DEBUG | Enable debug logging (true/false) |
Recommended for:
- Power control scripts (Zendure, OpenDTU)
- Critical automation scripts
- Scripts that run continuously
Not needed for:
- One-time setup scripts
- Scripts that are already stable
- Default (60000ms / 1 minute): Good for most use cases
- Shorter interval (30000ms): For critical scripts requiring faster recovery
- Longer interval (300000ms / 5 minutes): For stable scripts to reduce overhead
Monitor Shelly logs to:
- Verify watchdog is running
- Track restart events
- Identify recurring failures that need investigation
If a script repeatedly crashes:
- Check the target script logs for error messages
- Verify configuration variables in the target script
- Ensure network connectivity to external devices
- Review resource constraints on Shelly device
let TARGET_SCRIPT_NAME = "Zendure Power Control";
let CHECK_INTERVAL_MS = 60000; // Check every minute
let DEBUG = false;- Script name must match exactly (case-sensitive)
- Watchdog cannot restart scripts with empty code
- Multiple watchdog instances can monitor different scripts
- The watchdog itself should be set to auto-start
- Check Shelly device logs regularly to monitor watchdog activity