How to get smartthings to trigger a routine (shell script) on a raspberry PI

What I need to do the Raspberry PI be aware of a change in state in a ST virtually switch and perform an activity.

Specifically what I am trying to do is press a button on smartthings, and have the PI set all the AV amps my home to ON, and switch to a specific input. The amp control side is already there, but how do I get the PI to respond to smartthings then initiate a shell script routine?

I do something similar to this by installing and configuring a Flask-Restful server on the Raspberry Pi. The Raspberry Pi is setup to wait for a HTTP command (e.g. Ping server, Check local status, etc) from the ST hub via a SmartTings SmartAPP or a WebCore with a trigger for that virtual device and optionally return a response to the SmartApp/WebCore to update a device’s status tile.

When the RaspberryPi receives a valid HTTP command from the ST Hub, it gleefully performs whatever Python/Script command I choose in the Flask Python script.

The other {less desirable} option is to have one’s Raspberry Pi periodically poll a custom SmartApp via an HTTP request to determine if the virtual switch has changed state.

I also recommend looking into purchasing a Logitech Harmony Hub/remote. I have one that connects to ST and performs many of my media center/entertainment system commands. The advantage with a Harmony Hub is that one can also have SmartThings and Amazon Alexa voice control my media center/entertainment systems as well as set status back to ST of their state.

1 Like

What SmartApp will do that? Can you provide any example webCoRE pistons?

My Raspberry PI server accepts a HTTP command at port 5000 from my custom DTH which sends a get command for a ping test.

The RPi performs the ping test and displays the result in a json format for the DTH to decode and open/close a contact device status. This allows me to know if the server or HotTub in this case is either Online or Offline.

@kurtsanders can you do the communication the other way around with that setup - SmartThings to Pi? I’ve been struggling with a way to have SmartThings trigger running terminal commands like shutdown, reboot, etc. without knowing how to do all sorts of programming.

Yes, the communications is initiated by the SmartThings Device Handler (DTH) on a recurring 5 minute polling schedule.

The DTH sends a HTTP command to Rpi, then waits patiently for a response code of 200 and json text from the RPi. For now, when the Rpi receives a command like, “ping {system}” the Rpi performs that task and updates the web response page for the DTH to decode and process.

I suppose I could also have the RPi accept other commands as you suggested and carry them out.

There is some coding involved in creating the DTH and webserver

@kurtsanders Think I’d be more interested in just the web server part - then use the make web request command in webCoRE. Just not sure how to do the web server part. It’s always the Raspberry Pi side of things holding me back.

Just for reference I’d found this in a Facebook group