
Styr Shelly Dimmer med eksternt tryk (Danish)
- Home
- Styr Shelly Dimmer med eksternt tryk (Danish)
Trådløs lysdæmpning mellem Shelly Plus I4 og Shelly Dimmer 2, Gen3 og Pro
Her beskrives, hvordan man kan få inputtet fra en Shelly Plus/Pro enhed til at styre en Shelly Dimmer 2.
I dette eksempel bruger vi en Shelly Plus I4 hvorpå der er tilsluttet en 1-polet afbryder med fjeder til at styre en Shelly Dimmer 2.
Der tages også udgangspunkt i at der arbejdes fra enhedens webinterface.
Når scriptet er sat op får du følgende funktionalitet:
- Kort tryk: tænd/sluk
- Dobbelt kort tryk: 100 % lysstyrke
- Langt tryk: lysstyrke op/ned
Trin 1: Tilgå enhedens webinterface
Find enhedens IP-adresse i din router, via Shelly Smart Control Appen eller control.shelly.cloud
Tilgå enhedens webinterface ved at skrive dens IP-adresse i en browser.
Trin 2: Opdater firmware
Trin 3: Sæt input mode til "button"
Trin 4: Indsæt og klargør script
Slå Websocket debug til
Indsæt script
Nu kopieres hele det nedenstående kode ind i det nye script.
(Tryk på Copy oppe i højre hjørne af scriptet)
Script til at styre Dimmer 2 (Gen1)
/**
* @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 connected button.
* short_press = on/off toggle, double_press = on with 100% brightness, long_press cycle between dimming and brightening.
*/
// Array of dimmers to be controlled
let dimmer = [
'192.168.2.201', // 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 eventHandler for button type input and various push events
Shelly.addEventHandler(function (event) {
try {
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;
}
} catch (e) {
print("Fejl i event handler: " + e.message);
}
});
Script til at styre Dimmer Gen3 og Pro Dimmer 1/2PM
Til Pro-dimmeren er der to scripts. Et til at styre Kanal 1 og et andet til at styre Kanal 2
Nu kopieres hele det nedenstående kode ind i det nye script.
(Tryk på Copy oppe i højre hjørne af scriptet)
/**
* @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 connected button.
* short_press = on/off toggle, double_press = on with 100% brightness, long_press cycle between dimming and brightening.
*/
// Array of dimmers to be controlled
let dimmer = [
'192.168.2.169', // dimmer controlled with button 0
'0.0.0.0', // dimmer controlled with button 1
'0.0.0.0', // dimmer controlled with button 2
'0.0.0.0', // dimmer controlled with button 3
];
// CONFIG END
let dimstate = [
false,
false,
false,
false,
];
let up = [
false,
false,
false,
false,
];
// Add an eventHandler for button type input and various push events
Shelly.addEventHandler(function (event) {
try {
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;
}
} catch (e) {
print("Fejl i event handler: " + e.message);
}
});
/**
* @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 connected button.
* short_press = on/off toggle, double_press = on with 100% brightness, long_press cycle between dimming and brightening.
*/
// Array of dimmers to be controlled
let dimmer = [
'0.0.0.0', // dimmer controlled with button 0
'192.168.2.169', // dimmer controlled with button 1
'0.0.0.0', // dimmer controlled with button 2
'0.0.0.0', // dimmer controlled with button 3
];
// CONFIG END
let dimstate = [
false,
false,
false,
false,
];
let up = [
false,
false,
false,
false,
];
// Add an eventHandler for button type input and various push events
Shelly.addEventHandler(function (event) {
try {
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;
}
} catch (e) {
print("Fejl i event handler: " + e.message);
}
});
Trin 5a: Konfigurer script
Find og ændre IP-adresse
Når scriptet er indsat, naviger til linjer 12-15.
Der er fire linjer med IP-adresser. Hver linje/IP-adresse svarer til en indgang på Shelly I4.
Hvis du ønsker, at den første indgang (0) på I4 skal styre en Dimmer 2 med IP-adressen 192.168.1.34, skal du ændre IP’en i den første linje for at matche.
Hvis du også ønsker, at indgang 2 (1) skal betjene en anden Dimmer 2, fjern de dobbelte skråstreger // og opdater den linje med IP-adressen på den tilsvarende Dimmer 2. Gentag denne proces for de resterende indgange.
Før
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
Efter
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
Trin 5b: Konfigurer script (2 kanals Pro Dimmer)
Eksempel når du vil styre både Ch.1 og Ch.2 fra input 0 og 1 på samme enhed
Indtast en fiktiv IP-adresse på den første linje; ellers vil scriptet ikke genkende input fra input 1
Script til at kontrollere 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 til at kontrollere 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