Jump to content
🌟 Shop Black Friday - up to 50% OFF 🌟 Black-Friday-Angebote - bis zu 50% Rabatt! 🌟 Offres Black Friday : jusqu’à -50%! 🌟 ×

Recommended Posts

Posted

Hi, I am using a Shelly Plus 1PM to turn an electric heater on and off.
I have an app that sets when a device is turned on depending on the price of electricity - using the octopus agile half hour time slots.
The app provides an api that says whether the device should be on or not.
Below is a Shelly script that queries the api every minute and turns the device on or off.
It all seems to work fine, but the script quits after a few hours.
Any ideas why it would stop running?

function httpResponse(result, error_code, error) {
  const j = JSON.parse(result.body);
  const s = j.sel;
  if (error_code === 0 && s === true) {  
   Shelly.call("Switch.set", {'id': 0, 'on': true});
    } else {
   Shelly.call("Switch.set", {'id': 0, 'on': false});
    }
}
function timerCode() {
 const url = "https://xxxxxx.uk/is_on?device=ors";
 Shelly.call("HTTP.GET", {url: url}, httpResponse);}

 Timer.set( 60000, true, timerCode);

 

  • 1 month later...
Posted

Hi @Harry, from code perspective you should handle errors at first thing in `httpResponse` function and then do parsing body.

Also you can use `try` / `catch` to handle errors for synchronous code.

Here are some existing script examples for Shelly, from Shelly: https://github.com/ALLTERCO/shelly-script-examples

- good for inspiration

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...