This repository covers Shelly scripts for automating power management and lighting based on device events, ambient light levels, motion detection, and time-of-day conditions. Each script is compatible with Shelly devices that support scripting. Check them out.
-
shelly-idle-timer.jsAutomates switch-off based on low power consumption, saving energy.
-
shelly-blu-motion.jsActivates motion detection using a Shelly Blu Motion sensor.
-
shelly-blu-motion-illuminance.jsActivates motion detection only in low light, using a Shelly Blu Motion sensor.
-
shelly-blu-motion-darknight.jsControls lighting based on motion, light levels, and night-time detection.
-
shelly-status-check.pyShelly Status Checker Script, to have a status overview of the shellies.
-
shelly-check.shShelly Device Online Status check (HTTP Check Script)
-
shelly-mqtt-config.pyMass MQTT Configuration Script for Shelly Devices
-
sbu-ws90-homie.jsShelly WS90 Weatherstation BLU Data to Homie MQTT
-
sbu-ws90-mqtt.jsShelly WS90 Weatherstation BLU Data to MQTT
-
shelly-restart.pyReboots Shelly Devices via API requests
-
`create_shelly_monitor.py``
Creates Uptime Kuma Monitors for shelly devices from a list
This Shelly script, shelly-idle-timer.js, is designed to monitor the power consumption of a specified switchID on a Shelly device. It turns off the switch automatically after a specified idle time if the power remains below a set threshold, helping save energy by turning off devices that are not actively in use.
- Starts a timer when the switch is ON and
apower < POWER_THRESHOLD. - If the condition persists for more than
IDLE_TIMEOUTminutes, the switch will be turned OFF. - Reacts to
power_update,toggle, andinputevents.
Some Shelly devices (e.g. Plug S Gen2) only emit power_update events
when power changes significantly. Small or slowly changing values
may not trigger any event.
To ensure reliable behavior in such cases, the script includes an optional polling mechanism that regularly fetches the current device state and applies the same idle logic.
To customize the behavior of this script, adjust the following parameters in the CONFIG object at the beginning of the script:
| Parameter | Description | Type | Default Value |
|---|---|---|---|
POWER_THRESHOLD |
The minimum active power (in watts) required to keep the device on. | Integer | 3 |
IDLE_TIMEOUT |
Duration (in minutes) that power must remain below the threshold before turning off the switch. | Integer | 5 |
SWITCH_ID |
The ID of the switch on the Shelly device to monitor. | Integer | 0 |
DEBUG_LOG |
Enables or disables debug logging to the console. Set to true for debugging. |
Boolean | false |
ENABLE_POLLING |
Enable ENABLE_POLLING if your device does not emit frequentpower_update events, or if you want to catch subtle idle conditions. true / false |
Boolean | false |
POLL_INTERVAL |
Polling Intervall in Seconds | Integer | 30 |
-
Power Monitoring:
- The script continually checks the power usage of the specified switch.
- When the power falls below
POWER_THRESHOLDfor theIDLE_TIMEOUTduration, the script automatically turns off the switch.
-
Event Handling:
- The script listens for
toggleevents on the specified switch. If the switch is toggled on, it starts a timer. If toggled off, it clears any active timer. - The script also responds to
power_updateevents:- If the active power is below
POWER_THRESHOLD, the timer starts. - If the active power is above or equal to
POWER_THRESHOLD, the timer is cleared.
- If the active power is below
- The script listens for
-
Debug Logging:
- When
DEBUG_LOGis enabled, the script logs detailed messages for easier troubleshooting.
- When
To use the script with a power threshold of 5 watts, an idle timeout of 10 minutes, and debug logging enabled, set up CONFIG as follows:
const CONFIG = {
POWER_THRESHOLD: 5,
IDLE_TIMEOUT: 10,
SWITCH_ID: 0,
DEBUG_LOG: true,
};This script configures and operates a Shelly Blu Motion sensor to detect motion. If motion is correctly detected, the configured switch will turned on, otherwise the switch will turned off.
Note: Bluetooth (BLE) must be enabled in the device settings for this script to function correctly.
-
allowedMacAddresses: Array of Strings — Lists the MAC addresses of approved devices for which motion and light data will be processed. Example:
allowedMacAddresses: [ "0b:ae:5f:33:9b:3c", "1a:22:33:62:5a:bc", ]
-
switchId: Number — Specifies the ID of the Shelly switch that should be activated upon motion detection in darkness. This ID is used to identify the target switch when calling
Shelly.call("Switch.Set", { id: switchId, on: motion }). Default:0
- debug:
trueorfalse— Enables debug mode to log additional information to the console. Default:false - active:
trueorfalse— Enables or disables active Bluetooth scanning. Default:false
This script configures and operates a Shelly Blu Motion sensor to detect motion and adjust behavior based on ambient light levels. The sensor activates motion detection only when it's dark, based on configurable parameters in the CONFIG object. If motion is correctly detected, the configured switch will turned on, otherwise the switch will turned off, only when there is no more detected motion from any sensor. Additionally, the light status is checked to avoid redundant on/off commands.
Note: Bluetooth (BLE) must be enabled in the device settings for this script to function correctly.
-
allowedMacAddresses: Array of Strings — Lists the MAC addresses of approved devices for which motion and light data will be processed. Example:allowedMacAddresses: [ "0b:ae:5f:33:9b:3c", "1a:22:33:62:5a:bc", ]
-
switchId: Number — Specifies the ID of the Shelly switch that should be activated upon motion detection in darkness. This ID is used to identify the target switch when callingShelly.call("Switch.Set", { id: switchId, on: motion }). Default:0 -
darknessThreshold: Number — Sets the light threshold in lux; any value below this threshold is considered "dark," triggering motion detection. Default:1
- debug:
trueorfalse— Enables debug mode to log additional information to the console. Default:false - active:
trueorfalse— Enables or disables active Bluetooth scanning. Default:false
This script provides a robust way to control lighting based on motion detection, ambient light levels, and night-time detection using Shelly devices and BLU Motion sensors. With the flexibility of configurable parameters and real-time sensor readings, it helps automate lighting efficiently and with reduced redundancy.
This script is designed to control a light based on motion detection from Bluetooth Low Energy (BLE) sensors and ambient light conditions. It ensures that the light only turns on when it’s dark and motion is detected, and turns off only when there is no more detected motion from any sensor.
The script uses geographic coordinates to calculate sunrise and sunset times, enabling it to distinguish between night and day. Additionally, the light status is checked to avoid redundant on/off commands.
Note: Bluetooth (BLE) must be enabled in the device settings for this script to function correctly.
- Motion Detection: The script monitors motion data from multiple sensors.
- Light Control: The light turns on only if:
- It’s dark enough (determined by a lux threshold),
- The current time is night (based on sunset/sunrise times), and
- Motion is detected from any sensor.
- Avoids Redundant Switching: Before changing the light state, the script checks if it’s already on or off.
- Light Turns Off: The light turns off only when no sensors report motion.
motionHandler: Handles motion events for each sensor. It increments the active motion count when motion is detected and reduces it when motion ends.illuminanceHandler: Updates the current ambient light value in lux to decide if it's dark enough.updateSunTimes: Fetches sunrise and sunset times based on geographic coordinates.
-
allowedMacAddresses(array): List of MAC addresses for allowed motion sensors to monitor for motion. Example:allowedMacAddresses: [ "0b:ae:5f:33:9b:3c", "1a:22:33:62:5a:bc", ]
-
switchId: Number — Specifies the ID of the Shelly switch that should be activated upon motion detection in darkness. This ID is used to identify the target switch when callingShelly.call("Switch.Set", { id: switchId, on: motion }). Default:0 -
latitude(float): The latitude of your location, used to calculate sunrise and sunset times. -
longitude(float): The longitude of your location. -
timezone(string): Timezone identifier (e.g.,UTC) for the sunrise/sunset API request. -
darknessThreshold(integer): Sets the lux threshold below which it’s considered "dark." If current illuminance falls below this, the system considers it dark enough to turn on the light when motion is detected.
debug(boolean): Enables or disables debug logging. Set totruefor more verbose output.active(boolean): Sets whether the BLE scanner should run in active mode.
Shelly Status Checker
This script collects status information from multiple Shelly Gen2 devices in your network and displays it in a neatly formatted table. It supports various metrics such as uptime, WiFi signal strength, MQTT status, debug UDP logging configuration, and installed scripts.
- Queries a list of Shelly devices via their IP or hostname
- Displays:
- Device type and generation
- Uptime (formatted as
Xd Xh Xm) - WiFi signal strength (RSSI)
- Eco Mode status (enable / diable)
- Bluetooth status (enable / diable)
- MQTT status (enable / diable)
- Debug UDP target
- Installed scripts
- Sortable output (by IP, uptime, or WiFi signal)
- Clean tabular display via
tabulate
-
Install required Python packages:
pip install requests tabulate
or on debian based systems
apt update && apt install python3-requests python3-tabulate -
Make the script executable (optional):
chmod +x shelly-status-check.py
-
Ensure your Shelly devices are reachable via DNS or static IP.
-
Create a list of device IPs or hostnames in a file named:
'shellies.txt' Each line should contain one hostname or IP:
shelly-kitchen.local shelly-garage.local 192.168.1.42
you can also generate your list with nmap, here is an example, all shelly devices must have shelly in their hostname:
nmap -sP 192.168.1.0/24 | grep "shelly" | awk '/Nmap scan report/ {print $5}' > shellies.txt
Run the script directly:
./shelly-status-check.py
./shelly-status-check.py --fileBy default, it sorts the table by IP address.
./shelly-status-check.py --sort uptime
./shelly-status-check.py --sort wifi| Option | Description |
|---|---|
--file </path/to/shellies.txt> |
Path to file containing IPs of Shelly devices default is ./shellies.txt |
--sort ip |
Sorts alphabetically by IP/host (default) |
--sort uptime |
Sorts by device uptime (descending) |
--sort wifi |
Sorts by WiFi signal strength (best first) |
- Python 3.6+
- Shelly Gen2 devices with RPC enabled
- Devices must be reachable over HTTP in the local network
If your Shelly devices require HTTP authentication, set:
auth = ('admin', 'yourpassword')inside the script.
+---------------------------------------+---------------------+-------------+------------+------------+--------------+-------------+--------+-------------------+--------------------------------------------------------------+
| IP | Device Typ | Reachable | Uptime | Eco Mode | WiFi (dBm) | Bluetooth | MQTT | Debug UDP | Scripts |
+=======================================+=====================+=============+============+============+==============+=============+========+===================+==============================================================+
| shelly-dl-ak.laubiot.loc | Mini1PMG3 (Gen 3) | ✅ | 15d 3h 52m | True | -67 | ❌ | ❌ | 192.168.50.20:514 | – |
+---------------------------------------+---------------------+-------------+------------+------------+--------------+-------------+--------+-------------------+--------------------------------------------------------------+
| shelly-dl-bu.laubiot.loc | Mini1PMG3 (Gen 3) | ✅ | 15d 3h 52m | False | -52 | ✅ | ❌ | 192.168.50.20:514 | oh-blu-scanner.js |
+---------------------------------------+---------------------+-------------+------------+------------+--------------+-------------+--------+-------------------+--------------------------------------------------------------+
| shelly-dl-bz.laubiot.loc | Plus1PMMini (Gen 2) | ✅ | 15d 3h 53m | True | -53 | ❌ | ❌ | 192.168.50.20:514 | – |
+---------------------------------------+---------------------+-------------+------------+------------+--------------+-------------+--------+-------------------+--------------------------------------------------------------+
| shelly-dl-carport.laubiot.loc | Plus2PM (Gen 2) | ✅ | 5d 9h 16m | False | -80 | ✅ | ❌ | 192.168.50.20:514 | ble-shelly-motion.js, shelly-blumotion-darknight.js |
+---------------------------------------+---------------------+-------------+------------+------------+--------------+-------------+--------+-------------------+--------------------------------------------------------------+Shelly Gen2 UDP Debug Configurator.
This Python script configures the UDP debug logging target for a list of Shelly Gen2 devices by sending the appropriate RPC command to each device.
- Automatically applies UDP debug configuration via HTTP.
- Supports batch configuration of multiple Shelly devices.
- Flexible input via command-line arguments.
- Designed for Shelly Gen2 firmware with
rpc/Sys.SetConfig.
- Python 3.x
requestslibrary (pip install requests)- Gen2 Shelly devices reachable over HTTP in the local network.
Create a text file (default: shelly.txt) listing one IP or hostname per line:
192.168.1.101
192.168.1.102
shelly-pro-kitchen.localpython3 shelly_debug_setter.py --host <TARGET_IP> --port <PORT> --file <DEVICE_FILE>| Argument | Required | Description |
|---|---|---|
--host |
✅ Yes | The destination IP/hostname for UDP logging |
--port |
✅ Yes | The UDP port number to send debug logs to |
--file |
❌ No | Path to file with device IPs (default: shellies.txt) |
python3 shelly_debug_setter.py --host 192.168.1.100 --port 514 --file shellies.txtThis sets all devices listed in shellies.txt to send debug logs to 192.168.1.100:514.
- Only compatible with Shelly Gen2 devices using the
/rpc/Sys.SetConfigendpoint. - Devices must be reachable over HTTP and on the same network (or VPN).
- Authentication is not currently supported — add manually if needed.
This script performs a basic health check for a list of Shelly smart devices by sending HTTP requests to their status endpoints. It helps verify whether each device is reachable and responsive.
- Pings all IPs listed in a file and checks status via Shelly HTTP API.
- Logs which devices are reachable or offline.
- Default file lookup in the script's directory (
shellies.txt). - Supports optional
--fileparameter for custom input.
./shelly-check.shThis will check all devices listed in shellies.txt located in the same directory as the script.
./shelly-check.sh --file /path/to/my/shellies.txtTo find Shelly devices on your local network, you can use nmap:
nmap -sP 192.168.10.0/24 | grep "shelly" | awk '/Nmap scan report/ {print $5}' > shellies.txtTo monitor Shelly devices continuously, you can schedule the script to run every 5 minutes using cron. If your system is configured to send cron job output via email, you'll receive notifications whenever a device is offline.
*/5 * * * * /path/to/shelly-check.sh --file /path/to/shellies.txtEnsure the script is executable:
chmod +x /path/to/shelly-check.shℹ️ Tip: Configure your system’s
postfixservice to forward cron output to your email inbox.
This script automates the MQTT configuration for multiple Shelly Gen2 devices using their RPC HTTP API.
- Sends MQTT configuration to each Shelly device listed in a file.
- Configures:
- MQTT server, username, password
- client ID and topic prefix per host
- TLS, control, and status options
- Easy bulk setup for large installations
- Python 3
requestsmodule
Install with:
pip install requestspython3 shelly-mqtt-config.py
python3 shelly-mqtt-config.py --file ./my-devices.txtMake sure your device list is valid before running the script.
| Option | Description | Default |
|---|---|---|
--file |
Path to a file with Shelly IPs or hostnames (one per line) | ./shellies.txt |
192.168.1.101
192.168.1.102
shelly-kitchen.localTo generate this list from your local network:
nmap -sP 192.168.1.0/24 | grep "shelly" | awk '/Nmap scan report/ {print $5}' > shellies.txtMake sure to edit the script to include your actual MQTT broker credentials and hostname in the base_config section.
Create HTTP monitors in Uptime Kuma for a list of Shelly devices.
This script:
- Reads Shelly device IP addresses from a text file (one IP per line).
- Optionally creates (or reuses) a monitor group in Uptime Kuma.
- Creates an HTTP monitor for each device at:
http://<IP>/rpc/Shelly.GetStatus - Skips creation if a monitor with the same URL already exists.
- Allows configuring check interval, retry interval and max retries.
- Python 3.8+ (recommended)
- A running Uptime Kuma instance (e.g.
http://127.0.0.1:3001) - Valid Uptime Kuma username and password
- The Python library
uptime-kuma-api
Install the required library with:
pip install uptime-kuma-api- Default file name:
shellies.txt(can be overridden with--file) - One IP address (or hostname) per line
- Empty lines and lines starting with
#are ignored, e.g.:
# Shelly devices
192.168.1.10
192.168.1.11
# 192.168.1.12 (disabled)
python3 create_shelly_monitors.py \
--kuma-url http://127.0.0.1:3001 \
--username admin \
--password 'Your$Secure!Password' \
--file /path/to/shellies.txt \
--interval 600 \
--retry-interval 60 \
--maxretries 0 \
--group-name "Shelly Devices"-
--kuma-url
Base URL of the Uptime Kuma instance. -
--username
Uptime Kuma username. -
--password
Uptime Kuma password. -
--file
Path to the Shelly list file (default:shellies.txt). -
--interval
Check interval in seconds (default:60). -
--retry-interval
Retry interval in seconds (default:60). -
--maxretries
Number of retries before marking the monitor as DOWN (default:0). -
--group-name
Name of the monitor group to put all Shelly monitors into.
If the group does not exist, it will be created.