Wireless dimming
- Home
- Application guide
- Wireless dimming
Wireless dimming between Shelly Plus I4 and Shelly Dimmer 2 / Pro Dimmer
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
Step 2: update firmware
Step 3: Set input mode to "button".
Step 4: Insert and prepare script
Turn on Websocket debug
Insert script
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.
*/
// Array of dimmers to be controlled
let dimmer = [
'192.168.61.240', // dimmer controlled with button 0
// '192.168.61.241', // dimmer controlled with button 1
// '192.168.61.242', // dimmer controlled with button 2
// '192.168.61.243', // dimmer controlled with button 3
];
// CONFIG END
let dimstate = [
false,
false,
false,
false,
];
let up = [
false,
false,
false,
false,
];
// add an evenHandler for button type input and various push events
Shelly.addEventHandler(
function (event) {
if (typeof event.info.event !== 'undefined') {
let i = event.info.id;
if (typeof dimmer[i] !== 'undefined') {
if (dimstate[i] === true && event.info.event === 'btn_up') {
dimstate[i] = false;
print("release");
Shelly.call(
"http.get", {
url: 'http://' + dimmer[i] + '/light/0?dim=stop'
},
function (response, error_code, error_message, ud) { },
null
);
}
if (event.info.event === 'single_push') {
Shelly.call(
"http.get", {
url: 'http://' + dimmer[i] + '/light/0?turn=toggle'
},
function (rs, ec, em) { },
null
);
} else if (event.info.event === 'double_push') {
Shelly.call(
"http.get", {
url: 'http://' + dimmer[i] + '/light/0?turn=on&brightness=100'
},
function (rs, ec, em) { },
null
);
} else if (event.info.event === 'long_push' && up[i]) {
dimstate[i] = true;
up[i] = false;
print("cycle");
Shelly.call(
"http.get", {
url: 'http://' + dimmer[i] + '/light/0?dim=down&step=100'
},
function (rs, ec, em) { },
null
);
} else if (event.info.event === 'long_push' && up[i] === false) {
dimstate[i] = true;
up[i] = true;
print("cycle");
Shelly.call(
"http.get", {
url: 'http://' + dimmer[i] + '/light/0?dim=up&step=100'
},
function (rs, ec, em) { },
null
);
}
else {
return true;
}
}
} else {
return true;
}
},
);
For the Pro dimmer there are two scripts.
One for controlling Channel 1 and another for Channel 2
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.
*/
// Array of dimmers to be controlled
let dimmer = [
'192.168.61.240', // dimmer controlled with button 0
// '192.168.61.241', // dimmer controlled with button 1
// '192.168.61.242', // dimmer controlled with button 2
// '192.168.61.243', // dimmer controlled with button 3
];
// CONFIG END
let dimstate = [
false,
false,
false,
false,
];
let up = [
false,
false,
false,
false,
];
// add an evenHandler for button type input and various push events
Shelly.addEventHandler(
function (event) {
if (typeof event.info.event !== 'undefined') {
let i = event.info.id;
if (typeof dimmer[i] !== 'undefined') {
if (dimstate[i] === true && event.info.event === 'btn_up') {
dimstate[i] = false;
print("release");
Shelly.call(
"http.get", {
url: 'http://' + dimmer[i] + '/rpc/Light.DimStop?id=0'
},
function (response, error_code, error_message, ud) { },
null
);
}
if (event.info.event === 'single_push') {
Shelly.call(
"http.get", {
url: 'http://' + dimmer[i] + '/light/0?turn=toggle'
},
function (rs, ec, em) { },
null
);
} else if (event.info.event === 'double_push') {
Shelly.call(
"http.get", {
url: 'http://' + dimmer[i] + '/rpc/light.set?id=0&on=true&brightness=100'
},
function (rs, ec, em) { },
null
);
} else if (event.info.event === 'long_push' && up[i]) {
dimstate[i] = true;
up[i] = false;
print("cycle");
Shelly.call(
"http.get", {
url: 'http://' + dimmer[i] + '/rpc/Light.DimDown?id=0&fade_rate=4'
},
function (rs, ec, em) { },
null
);
} else if (event.info.event === 'long_push' && up[i] === false) {
dimstate[i] = true;
up[i] = true;
print("cycle");
Shelly.call(
"http.get", {
url: 'http://' + dimmer[i] + '/rpc/Light.DimUp?id=0&fade_rate=4'
},
function (rs, ec, em) { },
null
);
}
else {
return true;
}
}
} else {
return true;
}
},
);
/**
* @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.
*/
// Array of dimmers to be controlled
let dimmer = [
'192.168.61.240', // dimmer controlled with button 0
// '192.168.61.241', // dimmer controlled with button 1
// '192.168.61.242', // dimmer controlled with button 2
// '192.168.61.243', // dimmer controlled with button 3
];
// CONFIG END
let dimstate = [
false,
false,
false,
false,
];
let up = [
false,
false,
false,
false,
];
// add an evenHandler for button type input and various push events
Shelly.addEventHandler(
function (event) {
if (typeof event.info.event !== 'undefined') {
let i = event.info.id;
if (typeof dimmer[i] !== 'undefined') {
if (dimstate[i] === true && event.info.event === 'btn_up') {
dimstate[i] = false;
print("release");
Shelly.call(
"http.get", {
url: 'http://' + dimmer[i] + '/rpc/Light.DimStop?id=1'
},
function (response, error_code, error_message, ud) { },
null
);
}
if (event.info.event === 'single_push') {
Shelly.call(
"http.get", {
url: 'http://' + dimmer[i] + '/light/1?turn=toggle'
},
function (rs, ec, em) { },
null
);
} else if (event.info.event === 'double_push') {
Shelly.call(
"http.get", {
url: 'http://' + dimmer[i] + '/rpc/light.set?id=1&on=true&brightness=100'
},
function (rs, ec, em) { },
null
);
} else if (event.info.event === 'long_push' && up[i]) {
dimstate[i] = true;
up[i] = false;
print("cycle");
Shelly.call(
"http.get", {
url: 'http://' + dimmer[i] + '/rpc/Light.DimDown?id=1&fade_rate=4'
},
function (rs, ec, em) { },
null
);
} else if (event.info.event === 'long_push' && up[i] === false) {
dimstate[i] = true;
up[i] = true;
print("cycle");
Shelly.call(
"http.get", {
url: 'http://' + dimmer[i] + '/rpc/Light.DimUp?id=1&fade_rate=4'
},
function (rs, ec, em) { },
null
);
}
else {
return true;
}
}
} else {
return true;
}
},
);
Step 5a: Configure script (1 Channel)
Find and change IP address
When the script is pasted, navigate to lines 12-15.
There are four lines containing IP addresses. Each line/IP address corresponds to an input on the Shelly I4.
If you want the first input (0) on the I4 to control a Dimmer 2 with the IP address 192.168.1.34, you need to modify the IP in the first line to match.
If you also want input 2 (1) to operate another Dimmer 2, remove the double slashes // and update that line with the IP address of the corresponding Dimmer 2. Repeat this process for the remaining inputs.
Before
let dimmer = [
'192.168.61.240', // dimmer controlled with button 0
// '192.168.61.241', // dimmer controlled with button 1
// '192.168.61.242', // dimmer controlled with button 2
// '192.168.61.243', // dimmer controlled with button 3
After
let dimmer = [
'192.168.1.34', // dimmer controlled with button 0
'192.168.1.57', // dimmer controlled with button 1
// '192.168.61.242', // dimmer controlled with button 2
// '192.168.61.243', // dimmer controlled with button 3
Step 5b: Configure script (2 channel Pro Dimmer)
Example when we want to control both Ch.1 and Ch.2 from input 0 and 1 on the same device
Enter a fictional IP address on the first line; otherwise, the script won’t recognize input from input 1.
Script for controlling Ch.1
let dimmer = [
'192.168.61.240', // dimmer controlled with button 0
// '192.168.61.241', // dimmer controlled with button 1
// '192.168.61.242', // dimmer controlled with button 2
// '192.168.61.243', // dimmer controlled with button 3
Script for controlling Ch.2
let dimmer = [
'0.0.0.0', // dimmer controlled with button 0
'192.168.61.240', // dimmer controlled with button 1
// '192.168.61.242', // dimmer controlled with button 2
// '192.168.61.243', // dimmer controlled with button 3