Notifications
Clear all

Using Shelly Relay as a Remote Switch


codecage
(@codecage)
Member Admin
Joined: 2 years ago
Posts: 1088
Topic starter  

It seems I've seen some other forum members mention Shelly devices on here, so I thought I'd take a shot at seeing if what I want to do is possible with one of these wireless devices.

I want to be able to turn on, or off, my 3D printer, from where I usually work on my desktop.  They are in different rooms, so it requires a trip to and from to accomplish this task at the moment.

I purchased, maybe a little prematurely, a Shelly 1 and have it now as a part of my home wireless network.  So now you ask, what's the issue?  How can I activate the "switch" to control power to my printer?  The "app" that they want you to down load is useless to me as it requires a version of the phone's OS that my older phone does not support.  And besides if I am on my desktop or laptop already how can I control the Shelly from there and not have to pickup my phone even if it supported the app.

Is there a way to send the proper on or off command to the Shelly from my desktop/laptop?

SteveG


Quote
byron
(@byron)
Honorable Member
Joined: 2 years ago
Posts: 678
 
Posted by: @codecage

Is there a way to send the proper on or off command to the Shelly from my desktop/laptop?

Yes, if you have a local mqtt broker running then you can use mqtt messages (or a remote mqtt broker can also be used).

But I suspect you dont, so you can just send http messages.

In my case my shelly has an ip address of 10.0.1.68.  So to switch the relay on or off I can type the following into the address line of my browser

http://10.0.1.63/relay/0?turn=on

http://10.0.1.63/relay/0?turn=off

http://10.0.1.63/relay/0?turn=toggle

And I daresay you could wrap these command up in a nice little program you create on your computer.  Good practice for a nice little python program 😎 


ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 2 years ago
Posts: 1088
Topic starter  

@byron

Many thanks!  Just what I needed!!  I actually have a MQTT broker running on a RasPi that I'm using to monitor messages from a temp and humid sensor and then graphing that with Grafana.  Just need to learn how to add functionality to that setup.

But to begin with I can try the commands from the browser address line!

And I can see a nice little Python program with a window that contains a ON, OFF, and TOGGLE button in my future.

Thanks again for setting me back on the right path.  I knew it had to be possible somehow.

SteveG


ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 2 years ago
Posts: 1088
Topic starter  

@byron

What response do you see in your browser when you try the commands you presented?

I get a "Not Found" in my browser window using my Shelly's IP address.

And I'm guess that was a typo on your commands as the 4th octet was 68 in your first part of the post, but 63 in the commands.

SteveG


ReplyQuote
byron
(@byron)
Honorable Member
Joined: 2 years ago
Posts: 678
 

@codecage

Woops that 68 was a typo.

but I just tried the commands on a test shelly1 I have in my office connected to a lamp.  Well the lamp switches on and off 😀  (from my mac computer - safari browser)

And just for completeness, I just remembered I can just put the ip address of the shelly1 without any additions to the command line into a browser and up pops a web page very similar to the shelly app I have on my ipad.  I can then click an on-screen button to turn the shelly1 on and off. So no need for even a python program.

The mqtt command on my shelly1 set-up takes the form of:

client1.publish('shellies/shelly1-FH1/relay/0/command', 'on')
 
and I suspect I had to configure something in the shelly for this to work.

But back to your lack of success with the ip commands, have you set up the wifi credentials in your shelly1 and what did you do to confirm your shelly1's ip address?

 

 

This post was modified 6 months ago by byron

ReplyQuote
byron
(@byron)
Honorable Member
Joined: 2 years ago
Posts: 678
 

@codecage

and if I mistype the ip address, after a long wait, I get the message 'failed to open page' - so it does look at if you may have put in an incorrect ip address


ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 2 years ago
Posts: 1088
Topic starter  

@byron

Figured it out!!  I read the "0?turn=on" as an O(oh) not a 0(zero)!  Once I corrected that everything was fine.  Thanks for sticking with me.

SteveG


ReplyQuote