Scripts Shelly troubleshooting
Shelly script won't start or keeps stopping
You click Run and the script stops straight away, or it works until the next restart. The Scripts page and the console tell you which cause you have.
- Gen2
- Gen3
- Gen4
- Pro
Start here
What are you seeing?
Pick the closest match and we'll point you to the fix most likely to sort it.
Why it happens
A Shelly script runs on the device itself, in a cut-down version of JavaScript that Shelly built for small devices. It stops the moment it hits an error, and it only starts again after a restart if it's set to.
The device's web page tells you most of what went wrong. The Scripts list shows whether a script is running and its last error, and the console under the code shows the line it failed on.
Everything here is done on the device's web page, from a browser on your home Wi-Fi, or in the Shelly app. Scripts run on Gen2 devices and newer, not on Gen1.
Quick checks first
Run these checks before moving on to the fixes.
On the device's web page, open Scripts from the menu. Each script shows whether it's running or stopped, and the last error under its name.
Click the script to open it. The console under the code shows its log and any error, with the line it happened on.
If three other scripts are already running, a fourth can't start.
Fixes, most likely first
Work down the list and stop when it's fixed.
- Most likely for you
The code has an error
How to tell. The script shows Stopped with an error under its name, such as Incorrect JavaScript syntax. Shelly stops the whole script on any error.- Read the error
Open the script. The Error box under the code gives the message and points at the line, and the console below repeats it.
- Fix it, save, and run it
Correct the line, click Save, then click Run. If you copied the script from a page, copy it again in full in case part of it was missed.
- Catch errors inside callbacks
Shelly says an error inside a callback, such as the one passed to Shelly.call, ends the script unless that callback catches it. Wrap the code inside in try and catch.
Did this fix it? - Read the error
- Most likely for you
Run on startup is off
How to tell. The script runs when you click Run, but after a power cut, a restart or a firmware update it's stopped. Starting a script doesn't set it to start again by itself.- Turn on Run on startup
In the Scripts list, turn on the toggle beside the script. It starts again by itself after every restart.
- In the app
Open the device, then Scripts, and turn on the toggle beside the script.
Did this fix it? - Turn on Run on startup
- Most likely for you
It crashed the device
How to tell. The device restarted by itself and the script came back stopped. Shelly says a script that crashes the device is turned off at the next boot.- Look for long loops
Scripts share the processor with the device itself. Shelly says code that runs for a long time without stopping, such as a long or endless loop, can crash it. Move the work into timers or callbacks.
- Flatten nested functions
Shelly says nesting more than two or three anonymous functions inside each other can crash the device. Give the callbacks names and define them at the top level.
- Start it again
Once the code is fixed, click Run, then check Run on startup is on in the Scripts list.
Did this fix it? - Look for long loops
- Most likely for you
Three scripts are already running
How to tell. Other scripts on the device are running and the new one won't join them. A device holds up to 10 scripts, but only 3 run at once.- Stop one you don't need
Open a script you no longer use and click Delete, or stop it from the Scripts list. Then run the new one.
- Or combine them
Two small scripts that do related jobs can often be one script, which takes one of the three places.
Did this fix it? - Stop one you don't need
- Most likely for you
The code uses JavaScript Shelly leaves out
How to tell. The error points at something that works in a web browser. Shelly's engine is a cut-down JavaScript with no classes, no Promises and no async functions.- Use callbacks instead
Replace Promises and async functions with callbacks, and classes with plain functions. Shelly also says functions aren't hoisted, so define one before the line that calls it.
- Check for newer features
ArrayBuffer and AES only work on Gen3 and Gen4 devices, from firmware 1.6.0.
Did this fix it? - Use callbacks instead
- Most likely for you
It ran out of memory or a limit
How to tell. The error says out of memory or out of code space, or the script stops when it sets up a timer or a handler. All the scripts on a device share one pool of memory.- Stop other scripts
A large script running beside it uses memory it would need. Stop the others and try it on its own.
- Keep under the per-script limits
Shelly allows each script 5 timers, 5 event handlers, 5 status handlers and 5 RPC calls in flight at once. Clear timers you no longer need and send calls one after another.
Did this fix it? - Stop other scripts
- Most likely for you
The device started in safe mode
How to tell. None of the scripts started after a restart, and schedules didn't run either. Shelly says the device starts in safe mode if it detects a restart loop, and scripts don't start by themselves in safe mode.- Restart it normally
Safe mode only lasts until the next restart. Go to Settings and click Reboot.
Did this fix it? - Restart it normally
- Most likely for you
The firmware is older than the script
How to tell. The error names a Shelly function that exists in Shelly's docs, such as Script.storage, which arrived in firmware 1.5.0.- Update the firmware
On its web page, go to Settings, then Firmware, and click Check for updates.
Did this fix it? - Update the firmware
Frequently asked questions
Related problems
Still need a hand?
We answer most messages within one business day. If your question is about an existing order, have your order number ready. It speeds things up.
Contact us