In this guide, we describe how to control a Shelly Dimmer 2 wireless from a Shelly Plus I4 input module.
We will be working from the web interface of the Shelly devices.
We will use a script to emulate the dimming functionality. When the script is set up, you get the following functionality:
Single push: on/off
Double short push: 100 % light
Long push: Brightness up/down
Step 1: Access the device's web interface
Find the device’s IP address in your router, via the Shelly Smart Control App or control.shelly.cloud
Access the device’s web interface by typing its IP address into a browser.
Step 2: update firmware
Make sure your Shelly Plus I4 is updated to the latest firmware.
Press the “cog wheel”
Tap firmware
Update to the latest firmware
Step 3: Set input mode to "button".
Tap the home icon
Select the input you want to use
Press “See more” under Input mode
Select “Button” under input mode
Step 4: Insert and prepare script
Turn on Websocket debug
In order to see the status in the log, we must first turn on WebSocket debug (this is not necessary).
Press the “cog wheel”.
Select Debug.
Check “Enable Websocket Debug”
Press “Save Settings”
Insert script
Tap the script icon (<>)
Press “Create new script”
Give your script a name
Now copy the entire code below into the new script. (Press Copy in the top right corner of the script)
/**
* @copyright shelly-tools contributors
* @license GNU Affero General Public License (https://www.gnu.org/licenses/agpl-3.0.de.html)
* @authors https://github.com/shelly-tools/shelly-script-examples/graphs/contributors
*
* This script is intended to remote control a Shelly Dimmer / Dimmer2 and emulates the locally conencted button.
* short_press = on/off toggle, double_press = on with 100% brightness, long_press cylce between dimming and brightening.
*/
// CONFIG START
// IP address / hostname from Shelly Dimmer device
let REMOTE = {
ip: '192.168.178.166',
input: 0, // ID from the push button: 0 for Shelly Plus 1 / Plus 1 PM or 0,1,2 or 3 for the Shelly I4.
};
// CONFIG END
let dim = false;
let up = false;
// add an evenHandler for button type input and various push events
Shelly.addEventHandler(
function (event, user_data) {
//print(JSON.stringify(event));
if (typeof event.info.event !== 'undefined') {
if (dim === true && event.info.event === 'btn_up' && event.info.id === REMOTE.input) {
dim = false;
print("release");
Shelly.call(
"http.get", {
url: 'http://' + REMOTE.ip + '/light/0?dim=stop'
},
function (response, error_code, error_message, ud) { },
null
);
}
if (event.info.event === 'single_push' && event.info.id === REMOTE.input) {
Shelly.call(
"http.get", {
url: 'http://' + REMOTE.ip + '/light/0?turn=toggle'
},
function (response, error_code, error_message, ud) { },
null
);
} else if (event.info.event === 'double_push' && event.info.id === REMOTE.input) {
Shelly.call(
"http.get", {
url: 'http://' + REMOTE.ip + '/light/0?turn=on&brightness=100'
},
function (response, error_code, error_message, ud) { },
null
);
} else if (event.info.event === 'long_push') {
dim = true;
if (up === true) {
up = false;
Shelly.call(
"http.get", {
url: 'http://' + REMOTE.ip + '/light/0?dim=down&step=100'
},
function (response, error_code, error_message, ud) { },
null
);
} else {
up = true;
Shelly.call(
"http.get", {
url: 'http://' + REMOTE.ip + '/light/0?dim=up&step=100'
},
function (response, error_code, error_message, ud) { },
null
);
}
print("cycle");
} else {
return true;
}
} else {
return true;
}
},
);
Trin 5: Konfigurer script
Find and change IP address
When the script is copied in, find line 13.
On the line: ip: ip: ‘192.168.178.166’, (line 13)
Insert the IP address of your Shelly Dimmer 2.
If your Dimmer has the IP address 192.168.1.34, then this is what you should change it to.
Before
let REMOTE = {
ip: '192.168.178.166',
input: 0, // ID from the push button: 0 for
After
let REMOTE = {
ip: '192.168.1.34',
input: 0, // ID from the push button: 0 for
Find and change input
Now you have to define which input on your Shelly Plus I4 you have connected to your switch. Shelly Plus I4 has four inputs which are designated from input 0-3. So if you want to use input 1 (SW1) to control your dimmer, then you must use ID 0.