Can I use SmartThings to run bash scripts on my Raspberry PI


(Jerry ) #1

I did a search but really did not find anything. I apologize in advance if I missed it somewhere. I am new to SmartThings but am a heavy Linux user and use various bash scripts on a Raspberry PI to control my sprinkler system.

Is there any way I can run such scripts with SamrtThings?

Thanks


#2

I have been trying to figure out how to do this for the longest time. The only way that I have found to be able to do this is very, VERY complicated. So, I’m just going to run through it at the Reader’s Digest level.
Hardware: You have to have an Android device that will stay at home and connected to your network at all times.

  1. You need SharpTools to integrate with ST (yes, you will need the paid version)
  2. You need Tasker for your Android device.
  3. You need the SharpTools plugin for Tasker and one of the SSH plugins for tasker.

You then set it up so that when one of your ST devices changes to whatever you want, the SSH plugin in tasker executes the command on your Pi. This is WAAAAY too much trouble IMHO, so I haven’t really done anything with it beyond testing. There are just so many failure points that it is going to be very error-prone. If you anre controlling your sprinklers with your Raspberry Pi, You might want to look at something like WebIOPi to integrate with ST. You could have a GPIO’s state set by WebIOPi and have whatever is controlling your sprinkler’s respond to the state of the pin. That way you wouldn’t have to wire anything differently. It would mean you’d have to modify whatever was controlling the sprinklers to trigger of GPIO state. if you find an easier way to execute the scripts, please post back cause I’m very interested to hear.


(Dan) #3

Give OmniThing a try. I know it is capable of running scripts on a RPi, as the author of OmniThing, @leinax, is doing exactly that already.

[RELEASE] OmniThing v0.5.0 - ESP8266/ESP32/RaspberryPi/Linux/Windows - A cross-platform successor to ST_Anything - Web-based Configuration Tool


(HONGTAT TAN) #4

You can create HTTP endpoints in RPi and ST can HTTP POST to the RPi’s HTTP API to execute your scripts.


#5

I guess I’m not clear on how you would set Omni thing to run a script not native to it. Is there an example somewhere?


(Dan) #6

I am sure @leinax can explain how he does it. I don’t think it is too hard. He uses it to run various scripts on his linux server and workstation via a momentary button/switch within ST.


#7

Well, yeah, you can do anything if you know how to code it. I think the OP was asking for an implementation that would be a little more “packaged” than, “yeah, just do it.”


(Daniel) #8

OmniThing allows you to create a switch that runs a “CommandExecuter” output. In the web configuration tool that runs on your pi locally, it allows you to specify any bash command you want for both “on” and “off” states. You enter the commands directly in the web browser.

In the case of running an arbitrary script already on the pi, the command can just be “/path/to/script.sh”. If you want, you can also write simple scripts directly in the browser (i.e. ‘echo “Task one”; echo “Task two”’).

In the SmartThings app, you will see a switch, and toggling it will run the appropriate script for on/off.

Example of how I turn my windows vm on/off with SmartThings from my linux host:


#9

Sweet! Definitely going to give that a try. Thanks!


(Jerry ) #10

Thanks for the replies and the detailed how-to. I’ll give OmniThing a shot. My sprinkler system uses 5 Sonoff 4CH relays flashed with Espurna. It works over wifi and I can easily run a program or single zone via cron, a terminal in my phone, or whatever. I’d just like to tie it in with SmarThings, mostly just for fun. Thanks again.


#11

You could also flash your Sonoff with firmware that allows for direct control from ST.


(HousePanel Author) #12

You can easily do this using HousePanel with a one line update to the source code to invoke a PHP exec call when a tile is clicked… I had this in the code for calling a Python app to update my Arlo video hack but removed it when I found a more elegant solution. The only semi-hard part is getting HousePanel up and running if you are new to it. Otherwise making this work should be a walk in the park. I’ll post an example later this weekend.


#13

But that’s not issuing it from ST. That’s issuing it from HousePanel. That’s not really automating it.


(HousePanel Author) #14

Yup, you’re right. However, using the built-in HP API one could query the status of anything authenticated and then based on results invoke whatever SH script of interest. It would be a lot of work but definitely possible. Personally I would use Python to do this instead of SH but either should work.


(Chris Wilson) #15

Http switch to send a post or get to node red. Can execute any script you like on the pi. Fairly simple to setup as well with a http switch driver.


#16

may be simple if you’re a coder. but for those of us that are self-taught on this stuff it’s not all that easy.


(Chris Wilson) #17

Umm all the code exists. You just have to install the various programs. I’d you’d like some help pm me.

For the record I fall into this category. No coder. Self taught.


(HousePanel Author) #18

Yea… but now Chris you’re a coder dude!


(Chris Wilson) #19

High praise coming from you my friend. HP was my inspiration so you are to blame. :sunglasses:

Though I think I prefer the term tinkerer.


(HousePanel Author) #20

So @Ryan780 to make this work and appear to be happening from ST, start by making a few Virtual switches or virtual momentary buttons. Name them something appropriate like “Web Caller” or “HTTP Poster”

Next, get HousePanel installed and enable those virtual switches.

Third step is write a script on the rPI that loops and does a HP query API call and nothing else until the switch is on. Once on it should invoke the script you want. The tools Chris mentioned make this step relatively easy.

You won’t be able to poll the SmartThings cloud more than roughly twoce a minute so this technique will not give you instant reapomse. This means it is only useful for non time critical actions.