So, bitte wie folgt vorgehen:
Die Firmware auf dem Shelly Plus1 PM updaten auf stable 1.0.7.
Ebenfalls auf dem Shelly Plus1 PM unter:
Settings --> Debug --> Enable Websocket debug
aktivieren und speichern.
Dann unter:
Scripts --> Add script --> Enter your script name here
einen Skriptnamen eingeben z.B. Motionswitch
Den gesamten Inhalt de u.g. Skriptes in das obere weiße Feld kopieren und Save klicken.
Die Config anpassen:
//######################### Config #########################
let Config = {
motion_ip : '172.16.0.101', //<-- in die Anführungszeichen die IP des Motion
dimmer_ip : '172.16.0.52', //<-- in die Anführungszeichen die IP des Dimmers
motion_time : 3, //<-- Die Zeit in Sekunden, die der Dimmer das Licht einschalten soll
motion_bright : 50, //<-- Die Helligkeit, mit der der Motion das Licht einschalten soll
switch_bright : 100 //<-- Die Helligkeit, mit der der Switch das Licht einschalten soll
}
//######################### Config end #####################
Nach dem Anpassen Save klicken.
Jetzt das Skript starten mit Start.
Unten im Feld Console erhältst du eine so ähnliche Ausgahe:
14:31:20 Url MOTION DETECTED:
14:31:20 http://172.16.0.80/script/5/motion_switch?motion
14:31:20 Url Button 1 switched ON url:
14:31:20 http://172.16.0.80/script/5/motion_switch?b1on
14:31:20 Url Button 1 switched OFF url:
14:31:20 http://172.16.0.80/script/5/motion_switch?b1off
14:31:20 Url Button 2 switched ON url:
14:31:20 http://172.16.0.80/script/5/motion_switch?b2on
14:31:20 Url Button 2 switched OFF url:
14:31:20 http://172.16.0.80/script/5/motion_switch?b2off
Das sind die URLs für die Action, die wir später brauchen.
Jetzt ALLE Actions beim Dimmer und beim Motion löschen!!!
Bei dem Motion trägst du jetzt mit Copy und Paste die URL aus der Console ein, die unter
Url MOTION DETECTED: steht. Kannst du z.B. bei MOTION DETECTED IN DARK
eintragen.
In meinem Beispiel:
http://172.16.0.80/script/5/motion_switch?motion
Bei dir ist natürlich die IP anders.
Ich gehe davon aus, das es sich bei dem Schalter am Dimmer um einen echten Schalter mit Wippe und einer Stellung für Ein und einer Stellung für Aus handelt.
Beim Dimmer Button Type auf detached!!!
Wenn du den Schalter an Button 1 angeschlossen hast, trägst du bei Button 1 switched ON url Mit Copy und Paste die URL aus der Console unter
Url Button 1 switched ON url: ein. In meinem Beispiel:
http://172.16.0.80/script/5/motion_switch?b1on
Jetzt noch mit Copy und Paste die URL aus der Console unter
Url Button 1 switched OFF url: eintragen. In meinem Beispiel:
http://172.16.0.80/script/5/motion_switch?b1off
Hier der Code:
(Wenn das Skript nach dem Booten automatisch starten soll, dann unter scripts den Schibeschalter neben dem Skriptnamen aktivieren)
// GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
// More information: https://www.gnu.org/licenses/gpl-3.0.txt
// ABSOLUTELY NO WARRANTY AT ALL!!!
// Made by ostfriese.
//######################### Config #########################
let Config = {
motion_ip : '172.16.0.101',
dimmer_ip : '172.16.0.52',
motion_time : 3,
motion_bright : 50,
switch_bright : 100
}
//######################### Config end #####################
function send_response(response, body) {
response.code = 200;
response.body = body;
response.send();
}
function watch(request,response) {
let query = request.query;
switch (query) {
case 'motion':
send_response(response, 'Motion detected');
print('Motion detected');
Shelly.call("http.get", {url:motion_reset_url,timeout:5});
if(switch1_on || switch2_on) {
print('Reaction: None');
return;
}
print('Reaction: ' + motion_on_url);
Shelly.call("http.get", {url:motion_on_url,timeout:5});
break;
case 'b1on':
switch1_on = true;
send_response(response, 'Button 1 on');
print('Button 1 on');
print('Reaction: ' + switch_on_url);
Shelly.call("http.get", {url:switch_on_url,timeout:5});
break;
case 'b1off':
switch1_on = false;
send_response(response, 'Button 1 off');
print('Button 1 off');
print('Reaction: ' + switch_off_url);
Shelly.call("http.get", {url:switch_off_url,timeout:5});
break;
case 'b2on':
switch2_on = true;
send_response(response, 'Button 2 on');
print('Button 2 on');
print('Reaction: ' + switch_on_url);
Shelly.call("http.get", {url:switch_on_url,timeout:5});
break;
case 'b2off':
switch2_on = false;
send_response(response, 'Button 2 off');
print('Button 2 off');
print('Reaction: ' + switch_off_url);
Shelly.call("http.get", {url:switch_off_url,timeout:5});
break;
}
}
function get_own_ip() {
Shelly.call("Shelly.GetConfig", "",
function(result, error_code, error_message) {
own_ip = result.wifi.sta.ip;
script_id = Shelly.getCurrentScriptId();
print('Url MOTION DETECTED:');
print('http://' + own_ip + '/script/' + script_id + '/motion_switch?motion');
print('Url Button 1 switched ON url:');
print('http://' + own_ip + '/script/' + script_id + '/motion_switch?b1on');
print('Url Button 1 switched OFF url:');
print('http://' + own_ip + '/script/' + script_id + '/motion_switch?b1off');
print('Url Button 2 switched ON url:');
print('http://' + own_ip + '/script/' + script_id + '/motion_switch?b2on');
print('Url Button 2 switched OFF url:');
print('http://' + own_ip + '/script/' + script_id + '/motion_switch?b2off');
}
);
}
let switch1_on = false;
let switch2_on = false;
let own_ip;
let motion_reset_url = 'http://' + Config.motion_ip;
motion_reset_url += '/settings/actions?index=0&enabled=true&name=motion_on';
let motion_on_url = 'http://' + Config.dimmer_ip;
motion_on_url += '/light/0?turn=on&timer=' + Config.motion_time;
motion_on_url += '&brightness=' + Config.motion_bright;
switch_on_url = 'http://' + Config.dimmer_ip;
switch_on_url += '/light/0?turn=on&brightness=' + Config.switch_bright;
switch_off_url = 'http://' + Config.dimmer_ip;
switch_off_url += '/light/0?turn=off';
get_own_ip();
HTTPServer.registerEndpoint('motion_switch',watch);
Alles anzeigen