Piet Santermans Posted August 13 Share Posted August 13 Can someone help me to write a script for my Shelly Plus Plug S? I have a rainwater pump that recently had a leak and it kept on pumping while I was on vacation. When I arrived back home, my house was underwater. I bought the Shelly Plus Plug S to to turn the socket off after the pump is pumping for longer than 10 minutes so this can't happen again in the future. I'm not an IT'er so I couldn't manage to write a script that works for my problem. Can someone help me please? Best regards and thanks in advance! Piet Santermans Quote Translate Revert translation? English (American) Finnish French German Italian Portuguese (European) Spanish Link to comment Share on other sites More sharing options...
Heinz Posted August 14 Share Posted August 14 have you tried this with a scene or a action ? Quote Translate Revert translation? English (American) Finnish French German Italian Portuguese (European) Spanish Link to comment Share on other sites More sharing options...
Kaco Posted August 28 Share Posted August 28 let thresholdPower = 700; // Power threshold in W let delayTime = 600000; // Delay time for turning off in milliseconds (10 minutes) let timer = null; // Timer for delay before turning off // Function to check power consumption function checkPower() {   // Call Shelly's local API to get the current power consumption   Shelly.call("meter.get", {}, function (result) {     let data = result;     // Verify existence of "total_act_power"     if (data && typeof data.total_act_power !== 'undefined') {       let totalPower = data.total_act_power; // Total active power       if (totalPower >= thresholdPower) {         // If power consumption exceeds 700 W, start the delay timer         if (timer === null) {           timer = Timer.set(delayTime, false, function () {             // Check again if power consumption is still above 700 W             Shelly.call("meter.get", {}, function (recheckResult) {               let recheckData = recheckResult;               if (recheckData && typeof recheckData.total_act_power !== 'undefined') {                 let recheckPower = recheckData.total_act_power;                 if (recheckPower >= thresholdPower) {                   // If power remains above 700 W, turn off the plug                   Shelly.call("switch.set", { id: 0, on: false });                   print("Power is above 700 W. Plug has been turned off.");                 }               }               // Reset the timer               timer = null;             });           });         }       } else {         // If power consumption drops below 700 W, cancel any pending timer         if (timer !== null) {           Timer.clear(timer);           timer = null;           print("Power is below 700 W. Pending timer has been canceled.");         }       }     } else {       print("Meter data is unavailable or incorrect.");     }   }); } // Run the check every 30 seconds continuously Timer.set(30000, true, function () {   checkPower(); }); Quote Translate Revert translation? English (American) Finnish French German Italian Portuguese (European) Spanish Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.