For the German version please scroll down below the code.
I have a veranda where one front is covered by a roller blind which is controlled by a Shelly 2 Plus PM. This Shelly is also controlled in Home Assistant using automations. Unfortunately, the front door opens outwards, i.e. when the veranda door is open and the roller blind is operated, whether by Home Assistant or manually (2 buttons, one up, one down), the roller blind jumps out of the guide and it ends in a medium-sized disaster every time. So I had the following idea: Shelly 2 Plus PM with addon, on the addon a binary contact sensor with which the status of the door is checked.
Then a script should simply do the following:
If door= open
then shelly is completely deactivated or does not react to any input
Unfortunately I have no clue about shellyscripting, so I tried it with ChatGTP, but it doesn't work the way I want it to. What am I doing wrong?
Translated with DeepL.com (free version)
// Variable to store the door sensor state (1 = closed, 0 = open)
let doorSensorInput = 0;
// Function to check the state of the door sensor (connected to Shelly AddOn)
function checkDoorStatus() {
// Fetch the status of the input (input id 0 for Shelly AddOn sensor)
Shelly.call("Input.GetStatus", { id: 100 }, function (result) {
print("Door Sensor Status:", JSON.stringify(result)); // Print the full result for debugging
// Check if result contains valid data and handle it safely
if (result && result.hasOwnProperty("state")) {
doorSensorInput = result.state; // Get the input state (1 = closed, 0 = open)
if (doorSensorInput === 0) {
print("Door is OPEN. Shutter movement is disabled.");
} else {
print("Door is CLOSED. Shutter can be operated.");
}
} else {
print("Error: Unable to retrieve the door sensor state.");
}
});
}
// Function to block or allow shutter movement based on the door sensor state
function blockShutterMovement() {
if (doorSensorInput === 0) {
// Door is open (state 0), block shutter movement
print("Shutter movement blocked due to door being open.");
return false; // Return false to block the shutter command
}
return true; // Door is closed (state 1), allow shutter movement
}
// Listen for shutter commands
Shelly.addStatusHandler(function (event) {
if (event.component === "Shutter") {
// Check the current status of the door
checkDoorStatus();
// Block or allow based on the door status
if (!blockShutterMovement()) {
// If the door is open, prevent the command from going through
print("Shutter command blocked: Door is open.");
return;
} else {
print("Shutter command allowed: Door is closed.");
// Allow the shutter command to proceed normally
}
}
});
// Periodically poll the door sensor state
Timer.set(5000, true, function () {
checkDoorStatus(); // Check the door status every 5 seconds
});
Alles anzeigen
Ich habe einen Wintergarten bei dem eine Front von einem Rollo abgedeckt wird welches von einem Shelly 2 Plus PM gesteuert wird. Dieser Shelly wird auch in Home Assistant mittels Automationen gesteuert. Leider öffnet die Front nach Aussen, d.h. wenn die Wintergartentür offen ist und das Rollo betätigt wird, sei es durch Home Assistant oder händisch (2 Tasten, eine hoch, eine runter), dann springt das Rollo aus der Führung und es endet jedes Mal in einem mittlerem Desaster. Daher hatte ich folgende Idee: Shelly 2 Plus PM mit Addon, an dem Addon ein binär Kontaktsensor mit dem der Status der Tür geprüft wird.
Dann sollte ein script einfach folgendes tun:
If Tür= offen
then shelly komplett deaktiviert bzw reagiert auf keinerlei Eingaben
Ich hab leider keinen blassen Schimmer von Shellyscripting, daher hab ich es mit ChatGTP probiert, jedoch klappt das nicht so wie ich möchte. Was mache ich denn falsch?