Jump to content
🌟 NOTIFICATION/Benachrichtigung: Welcome to our New Store! - shelly.com 🌟 ×

Script access from local Shelly device to a remote Shelly device via WLAN


Recommended Posts

Since some days I tried to figure out the type and syntax of script commands to access a remote shelly device. 

I have several http text lines which work very well if they are sent via a browser to the remote device (PlusPlugS).

e.g.  http://192.168.2.139/relay/0?turn=off   or 

http://192.168.2.139/rpc/PLUGS_UI.SetConfig?config={"leds":{"mode":"switch", "colors":{"switch:0":{"on":{"rgb":[100,0,0],"brightness":100},"off":{"rgb":[0,0,100],"brightness":100}}}}}

But finally these commands should reside in the script of a shelly device PlusPlugS (e.g. 192.168.2.140) and shall be sent to the other PlusPlugS (e.g. 192.168.2.139).

There were several examples on the Internet telling it might work with Shelly.call("http.get", ....) and there are hundreds of examples showing "http://...." strings for the shellys, but since days I was not able to find any variant of command which works in the script the same way it works directly from the browser. Does anyone have an example that really works in a script?

Maybe its also a problem to find the correct syntax for the Shelly-command.

Many thanks in advance for your help. 

Link to comment
Share on other sites

Not a scripting expert, but have you tried using POST instead of GET to do the changes?

https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/HTTP/#httprequest-example

http://192.168.33.1/rpc/HTTP.Request?method="POST"&url="http://10.33.53.21/rpc/Sys.SetConfig"&body="{\"config\":{\"location\":{\"tz\":\"UTC\"}}}"

 

Link to comment
Share on other sites

Hi Pluto. Thanks for your suggestion, but unfortunately the syntax of the example does not really solve my problem. 

My initial instruction string like "http://192.168.2.139/relay/0?turn=off" is working very well if sent via the browser.
It is the correct syntax for the browser.

I am looking for a solution/instruction within a script which is doing the same function (=switch on/off the remote switch).

A part of the script in device 192.168.2.140 could look like:

.....
if (apower >= 12) {
     //turn off the remote switch at 192.168.2.139

     ??? "http://192.168.2.139/relay/0?turn=off" ???     //this should do the same from within the script as it does in the browser
}
else {

     //turn on the remote switch at 192.168.2.139
     ??? "http://192.168.2.139/relay/0?turn=on" ???     //this should do the same from within the script as it does in the browser
}
....

I know that the red text above is wrong as a script instruction, but what would be the right instruction to fullfill this function in the script (=switch on/off the remote switch in a Shelly PlusPlugS)?

 

Link to comment
Share on other sites

  • 1 month later...

let ip = "192.168.0.19"; // IP-Adresse des externen Geräts

let on_string = "http://" + ip + "/relay/0/on";  // on string Ein-Schalten 
let off_string = "http://" + ip + "/relay/0/off"; // off string Aus-Schalten

  if (shouldTurnOn && fuellstand.voltage > 4) { //Bedingung
            print("Nachfüllen ist on");
            Shelly.call("HTTP.GET", { url: on_string }, function (res, error_code, error_msg, ud) {});
          } else {
            print("Nachfüllen ist off");
            Shelly.call("HTTP.GET", { url: off_string }, function (res, error_code, error_msg, ud) {});
          }

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Erstelle neue...