This repository contains two JavaScript scripts designed for the Shelly Plus 2PM smart relay, equipped with a Shelly Addon featuring two DS18B20 temperature sensors. These scripts provide an automated, safe, and configurable solution for managing a sauna heater, ensuring efficient operation while maintaining safety standards.
This script is responsible for the real-time monitoring and control of the sauna heater. It continuously reads the temperature from two DS18B20 sensors placed at different locations within the sauna, ensuring safe and efficient heating.
- Web UI configuration (NEW in v1.1): For Gen3/Gen4/Pro devices, all settings are adjustable through Virtual Components in the web interface - no code editing required!
- Automatic temperature regulation: Maintains the sauna at a user-defined setpoint.
- Temperature fluctuation control: Prevents excessive temperature variations by turning the heater on/off within a defined range.
- Overheating protection: Automatically stops the heater if:
- The maximum allowed temperature is exceeded.
- The temperature difference between the two sensors exceeds a predefined safety threshold.
- Configurable sensor failure handling: The heater will only shut down if sensor readings fail for a configurable number of consecutive attempts (
consecutive_null_threshold). - Maximum operation time: Prevents the sauna from running indefinitely by enforcing a hard limit on operating time.
- User control via Shelly input: Allows manual activation and deactivation of the sauna via a connected switch.
- Visual status indicator: Green LED shows sauna status (on/blinking when error).
- Integrated safety script monitoring: Ensures that the heater does not operate if the safety watchdog script is not running.
- Debug mode for troubleshooting: Provides detailed logs for system diagnostics.
- Backward compatible: Older devices automatically use KVS storage mode.
Starting from version 1.1, the script supports two configuration modes:
For Shelly Gen3, Gen4, and Gen2 Pro devices (firmware >= 1.4.3), settings are automatically stored as Virtual Components and can be adjusted directly through the Shelly web UI without editing the script:
- Navigate to your Shelly device's web interface
- Go to the "Components" section
- Find the "Sauna Control" group
- Adjust settings using the interactive sliders
Available Virtual Component settings:
- Target Temperature (40-120°C) - Default: 80°C
- Temperature Delta (1-15°C) - Default: 5°C
- Max Runtime (hours) (1-12h) - Default: 5h
- Sensor Diff Limit (10-50°C) - Default: 30°C
- Max Safety Temp (80-150°C) - Default: 110°C
- Sensor Fail Threshold (1-20 attempts) - Default: 5
For older Shelly devices that don't support Virtual Components, settings are stored in KVS (Key-Value Storage):
To modify settings:
- Navigate to Menu → Advanced → KVS in the Shelly web interface
- Find the
SaunaConfigkey - Edit the JSON values
- Restart the script to apply changes
All parameters with their defaults:
| Parameter | Description | Default Value |
|---|---|---|
temp_setpoint |
Target sauna temperature | 80°C |
temp_delta |
Allowed temperature fluctuation before toggling the heater | 5°C |
timer_on |
Maximum sauna runtime (in milliseconds) | 5 hours |
switch_id |
Shelly switch ID controlling the heater | 0 |
greenlight_id |
Shelly switch ID controlling the indicator light | 1 |
input_id |
Shelly input ID for manual sauna activation | 0 |
thermal_runaway |
Maximum allowed temperature difference between sensors | 30°C |
thermal_runaway_max |
Maximum safe temperature | 110°C |
safety_script_name |
Name of the safety watchdog script | "heater_watchdog" |
consecutive_null_threshold |
Number of consecutive failed sensor readings before stopping the heater | 5 |
debug |
Enable/disable debug logs | false |
manualKVS |
Force KVS mode instead of Virtual Components | false |
This script acts as a fail-safe mechanism, ensuring that the main control script is running and that the heater is not left on unintentionally.
- Periodically checks if the
sauna_heater_control.jsscript is running. - Automatically turns off the sauna heater if the primary control script stops or encounters an error.
- Provides an extra layer of safety and reliability by preventing unexpected heater operation.
These scripts are specifically designed for Shelly Plus 2PM smart relays and can be used in home automation setups where sauna safety, efficiency, and automation are priorities.
Users with basic JavaScript knowledge and experience with Shelly devices can easily modify the scripts to fit their specific needs.
To install and use these scripts:
- Set up your Shelly Plus 2PM with the necessary addons and DS18B20 temperature sensors.
- Customize the script configuration (
CONFIGobject) to match your sauna setup. - Upload the scripts to your Shelly device:
- Navigate to the Shelly Script Editor in the Shelly web interface.
- Copy and paste the scripts (
sauna_heater_control.jsandheater_watchdog.js) into separate scripts. - Save and run the scripts.
- Configure the startup behavior:
- Ensure that both scripts start automatically when the Shelly device is powered on.
- Monitor the system logs (if debug mode is enabled) to verify correct operation.
- To adjust the sauna temperature: Use the "Target Temperature" slider in the Shelly web UI
- To change temperature hysteresis: Adjust the "Temperature Delta" slider (1-15°C)
- To prevent temporary sensor failures from shutting down the heater: Increase "Sensor Fail Threshold"
- Changes take effect immediately - no script restart required
- To adjust the sauna temperature: Modify
temp_setpointin theCONFIGobject or KVS - To prevent temporary sensor failures from shutting down the heater: Increase
consecutive_null_thresholdin KVS - To disable debugging messages: Set
debug: falsein theCONFIGobject - Restart the script after making changes
- To change how often sensor readings are checked: Adjust the
Timer.set()interval (default10 seconds) - To force KVS mode on newer devices: Set
manualKVS: truein theCONFIGobject
Contributions and improvements are welcome! If you encounter any issues or have suggestions for enhancements, feel free to:
- Open an issue to report a bug or suggest a feature.
- Submit a pull request with code improvements or optimizations.