Harry Posted January 9 Share Posted January 9 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); Quote Link to comment Share on other sites More sharing options...
xnd Posted March 5 Share Posted March 5 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 Quote 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.