Hallo liebe Community.
Mein Vorhaben sieht wie folgt auf:
Ein Shelly Plus 1 in meinem lokalen Netzwerk schaltet ein Magnetventil der Bewässerungsanlage. (Shelly A)
Gleichzeitig soll ein zweiter Shelly Plus 1 beim Nachbarn die Wasserpumpe schalten. (Shelly B)
Shelly A und Shelly B sollen also synchron schalten, wobei Shelly A der Master und Shelly B der Slave ist.
Alle Device IDs, API Keys und auch die Cloud Server liegen mir vor.
Alle Shellies in der Cloud registriert.
ich habe folgende Ansätze probiert, bisher aber ohne Erfolg.
1) einen HTTP Post Befehl in Postman habe ich konfiguriert, funktioniert, aber weiß nicht, wie ich diesen in Shelly A hinterlegen kann.
2) HTTP Befehl
https://shelly-140-eu.shelly.cloud/device/relay/control?id=7c87ceXXXXXX&channel=0&turn=on&auth_key=OTgxMjZ1aWQF037A4BCAB352F4E1409762D40CB09AA2E7E7374EE0A451954DC89B71648D7ED9XXXXXXXXXXX
im Browser getestet. Fehlermeldung: Could Not Control this relay Channel
3) Script
let apiKey = "OTgxMjZ1aWQF037A4BCAB352F4E1409762D40CB09AA2E7E7374EE0A451954DC89B716XXXXXXXXXXXXX";
let deviceId = "7c87cXXXXXXXX";
let cloudUrl = "https://shelly-140-eu.shelly.cloud/device/relay/control";
function controlShellyB(state) {
Shelly.call(
"http.request",
{
method: "POST",
url: cloudUrl,
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
auth_key: apiKey,
id: deviceId,
turn: state ? "on" : "off"
})
},
function (res, err_code, err_msg) {
if (err_code !== 0) {
print("Error sending request:", err_code, err_msg);
} else {
print("Shelly B response:", res.body);
}
}
);
}
// Listener auf Relais-Änderung von A
Shelly.addEventHandler(function (event) {
if (event.component === "switch:0") {
let newState = event.delta.output; // true = ON, false = OFF
controlShellyB(newState);
}
});
Alles anzeigen
Skript kann gespeichert und gestartet werden, es passiert aber nichts.
Wer kann mir mit einer praktikablen Lösung helfen??
Danke euch im Voraus.
P.S. Device ID und API Key habe ich mit XXXx verfremdet.
Viele Grüße
mleit1210