Harry Posted January 9 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 Translate Revert translation? English (American) Finnish French German Italian Portuguese (European) Spanish
xnd Posted March 5 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 Translate Revert translation? English (American) Finnish French German Italian Portuguese (European) Spanish
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.