Control smart lights with Shelly with automated detached mode

Could you share your code?

This is my current code:

function testHA() { Shelly.call("HTTP.GET", {url: 'http://homeassistant.home:8123', body:{}, ssl_ca: '*'}, function(resp) {
    let mode = (resp && resp.code === 200)? "detached" : "flip";
    Shelly.call("Switch.GetConfig", {id: 0}, function(oldConfig) {
      if (oldConfig.in_mode !== mode) {
        Shelly.call("Switch.SetConfig", { id: 0, config: { in_mode: mode } });
        if (mode === "detached") Shelly.call("Switch.Set", { id: 0, on: true });
      }
    });
  })
}

Timer.set((30 * 1000), true, testHA);
2 Likes