Turn on shelly with authentication via script

604 Views Asked by At

Shelly Plus 1 PM should turn on Shelly 1 that is protected with username and password.

I have a Shelly Plus 1 PM running a script. At some point another Shelly 1 should be turned on for 10 seconds. As long as the Shelly 1 is not protected with username and password this works as expected:

function turnOn() {
  Shelly.call("http.get", {url: 'http://' + 
          Config.ip + 
          '/relay/0?turn=on&timer=' + 
           JSON.stringify(Config.duration * 60)});
}

However i am struggling while including authentication as well. I tried the following:

function turnOn() {
  Shelly.call("http.get", {url: 'http://' + 
            Config.username + ':' + 
            Config.password + '@' + 
            Config.ip + '/relay/0?turn=on&timer=' +
            JSON.stringify(Config.duration * 60)});
}

If this is executed nothing happens, the Shelly 1 stays turned off. If i send the exact same request (http://USERNAME:PASSWORD@IP/relay/0?turn=on&timer=10) via Postman it works as expected.

Any suggestions?

0

There are 0 best solutions below