Jump to content
NOTICE / HINWEIS: iOS 18 Update and Today Widgets ×

Controlling Shelly Pro 2 relay using Curl


Recommended Posts

Hi,

I'm trying to control the Shelly Pro 2 relay using a Curl command as I want to prepare a .bat file to turn on and off the relay. I've used the command given in the Switch.set example down in the page. The command is:
curl -X POST -d '{"id":1,"method":"Switch.Set","params":{"id":0,"on":true}}' http://${SHELLY}/rpc
But I kept getting:
curl: (3) URL rejected: Bad hostname

I assume I need to add the IP address of the device somewhere, but since I have zero experience with Curl, everything I tried returned an error. I've tried to put the ip address after POST, and I got:
curl: (7) Failed to connect to 192.168.1.51 port 443 after 2045 ms: Couldn't connect to server
I googled the error and it mostly related to firewall, so I disabled the firewall and also made sure port 443 is enabled in & out, but still getting the same error.

I've posted this on Reddit, and I was advised to replace ${SHELLY} with my ip. I did that and got 'invalid request'

note that I'm able to control the relay using HTTP GET command from the browser, but I just need it to run from CMD.


Any thoughts?

Link to comment
Share on other sites

well for curl the command should be 
 

curl http://<SHELLY_IP>/relay/0?turn=on

if you want it off then 
 

curl http://<SHELLY_IP>/relay/0?turn=off

Toggle 

 

curl http://<SHELLY_IP>/relay/0?turn=toggle


where the <SHELLY_IP> is that is what you should replace with the IP address of the device 


for a .bat file I made and tested this and worked 

 

@echo off
curl http://<SHELLY_IP> /relay/0?turn=toggle
pause

Have a try and let me know if that helped

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.

×
×
  • Create New...