So I think this adjustment to the script works on the 2PM shelly
Note that I change the mode for when Home assistant is unavailable from flip to follow
function testHA() { Shelly.call("HTTP.GET", {url: 'http://homeassistant.local:8123', body:{}}, function(resp) {
let mode = (resp && resp.code === 200)? "detached" : "follow";
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 });
}
});
Shelly.call("Switch.GetConfig", {id: 1}, function(oldConfig) {
if (oldConfig.in_mode !== mode) {
Shelly.call("Switch.SetConfig", { id: 1, config: { in_mode: mode } });
if (mode === "detached") Shelly.call("Switch.Set", { id: 1, on: true });
}
});
})
}
Timer.set((30 * 1000), true, testHA);