Raspberry Pi with PHP (or Arduino/ESP8266/NodeMCU) to GPIO to Relay to Gate/Garage Trigger

@Synthesis Sounds like you want to control Smartthings from Pi, no this http device won’t do that. Unless there’s way to access the hub’s root, you can only use IFTTT to do it. This works by sending a POST request to Maker channel from your Pi, and then IF will switch Smartthings’ things on/off.

@JZst Thanks to you, I can turn on/off my TV (using infrared transmitter on Pi) from Echo without launching a skill. I also have a Pi surveillance cam and is able to switch the motion detector on/off as well, very neat. BTW I’m the guy from Github :slight_smile:

I modified it a little bit to fit my needs, and I’m planning to redesign the layout as well (hope you don’t mind :wink:)

@Casper, Thanks for the clarification.
Would it be possible to have a SmartApp that interfaces with this device type and has OAuth enabled to allow things that happen on the Pi to control SmartThings?

Again, I’m not a developer, so if my questions are stupid, please let me know.

@Synthesis Well that’s exactly how IFTTT did it, it’s a SmartApp, so you might be able to develop your own.

Also just for clarification, if your devices are connectable to Smartthings (Zigbee, zwave, …), you don’t need this http device handler, it’s for the things that aren’t connectable (like garage door or infrared control electronics)

@Casper, I understand that this isn’t needed for existing connectable devices…

What I’ve been desperately waiting for is for someone to develop a Pi device type/SmartApp that allows two way communication with SmartThings. I want to build a fully tactile control center for certain functions within the house…

I want a control panel sitting on my end table with various high quality push buttons and status lights so that anyone from my wife/kids to guests can use them to perform certain functions. Can I use a tablet for this? Sure… But I already have a glut of very high quality control panel style push buttons with the appropriate LED backlights, all of the necessary hardware, and I’m sitting on 10 or 12 Raspberry Pi 2 units that I’ve acquired… I even have wireless dongles for each of them…

Having two-way ability to use a Pi as the core of a tactile control panel would be amazing for my particular use case.

Is is possible to add another tile for the Custom Trigger? I have a 2 relays set up, one triggers the door, the other the light. I set the php script so the gate is triggering the relay for the door, and the custom trigger is triggering the light.

Thanks. great scripts.

Very nice to see @Byron_Poland! You’re using it just as intended.

Probably later tonight I’ll release a newer version that gives you a TILE for the CustomTrigger at the bottom of the App. I test the damn thing so much, I simply use CustomTrigger= in my BODY and I made the assumption that folks should have no issues adding their own tile. Considering the Groovy+ST learning curve, I will definitely add the tile in an release it so you don’t have to change Preferences>Body like I usually do. I’ll give CustomTrigger a dedicated tile/button and PHP will also see a sample of my second GPIO pin being set to ON then OFF. You can simply change the pin number in the PHP.

All the best!

@Casper, I definitely don’t mind the code altering and it’s nice to see more than gate/garage implementations. Thanks for the GitHub bug BTW. Easy fix and I should’ve done it right the first time :slight_smile: oh well, live & learn.

You have an interesting concept but it’s well out of this scope, not impossible, just out of scope for Device Handlers. SmartApp with OAuth like you were saying that talks to the ST API is the solution. I like the idea of using IFTTT considering the ease and their fully implemented solution. IFTTT plugs some of those holes for us but your requirement is a bit more advanced.

All the best!

New version now available on GitHub. Here are the changes:

v1.0.20160406 - Added the CustomTrigger button. Made buttons smaller. CPU Temp now accurately converts C to F. Added color to some tiles. Defaulting in port & body if left empty in prefs.

1 Like

Nice work, looks like big update, I won’t be able to merge everything immediately. I wonder why you only created a “trigger” instead of a switch. In my case I added an OFF functionality so I could tell if the device is currently on or off.

Thanks for the update. seems to be working well. I don’t have my door currently connected to my relay on the pi, but do have the light, and that is triggering on and off fine from ST. I can also see the door relay trigger if I watch webiopi. I had previously used a webiopi implementation to get web access to the door an light, I like this better as now I don’t need to hop on VPN to access the page, and get get to it straight from ST. Thanks again!

I like that idea. I am abusing this to just monitor my Pi. Also I would like to be able to refresh status to know its on and available with pollster for example and use rule machine to send an alert if it’s off.

@jjslegacy that sounds like an awesome idea. I will have something later tonight. Both Poll and Refresh will simply execute the same thing at TEST does. That way your Test Triggered should be updated as often as you set Pollster to check it. Thanks for recommending it… super-easy to implement. It was one of those “I’ll do it when I can as it may be difficult” — totally isn’t hard turns out :slight_smile:

Works like a charm… I see the Log entries as expected every 15 minutes and I can manually trigger Pollster to run, it also reflects in the Log.

1 Like

@Casper the reason why I went with a trigger was obviously for my selfish needs and a momentary requirement that my gate has. I’m sure you’ll be changing that :slight_smile: but now we have TWO buttons, one runs GateTrigger= and the other runs CustomTrigger= ---- which means it’s up to you which GPIO on/off sequences you want to set for those GateTrigger= could be your ON and CustomTrigger= can be your OFF. Just change the shell_exec in the PHP to be what you want.

I hesitate to make the shell_exec command “configurable” via SmartThings due to security reasons. That makes the Pi SUPER vulnerable as folks can easily run any command directly on the Pi and given that we’re all Cloud dependent with ST, I wanted to steer clear of that hole — unless you all strongly disagree with that security assessment.

@Byron_Poland you made me look at at webiopi, pretty nice project! Here’s a useful command when in the Pi shell that allows the same monitoring ability and refreshes every half second: watch -n0.5 gpio readall

I’ll be updating the first post with that command and these notions: the project was successfully tested via a public IP and a custom port. It was also tested with Amazon Echo/Alexa and Pollster.

All the best!

Some more updates explained below.

v1.0.20160407 - Added Poll & Refresh to execute the TEST function. Now able to add the switch to Pollster and should see the time update in Test Triggered. Validated external IP with custom port and Amazon Echo/Alexa.

For those of you who have not see what this command does on the Pi, you should. It will show you status of all GPIO pins and refresh every half second: watch -n0.5 gpio readall
I’m repeating myself with that but wanted to accentuate that command and whether I can use that somehow in the project or not.

All the best!

1 Like

For the nerds out there, try the following few commands. The first part is to install a package which contains the “convert” command. This allows conversion of text to image. The last command is the one that does that conversion. I’d like to hear feedback if this is useful and if so how. FYI, I did try to convert in PHP and Python but could not do so w/o extra libraries being installed.

sudo apt-get update
sudo apt-get -y install imagemagick --fix-missing
sudo gpio readall | convert -background black -fill white -font fixed -pointsize 14 -border 10 -bordercolor black label:@- image.png

I’m still going to look for alternatives like this link which will allow me to simply do what I need in PHP.

Thanks!

Interesting, does that mean I’m able to send picture to ST as a tile?

I only use the master button because I use Amazon Echo to trigger those switches (I made one for TV and one for IP Camera) and I’m not sure if Echo can trigger the second switch, it’s also faster to press the button from the list of “Things” :smiley:

@Casper I will try something this weekend which is to give the CustomTrigger function the name of off() and see if it triggers the second function. Good idea.

Yes the output of the gpio readall can indeed be a tile. By installing the php-gd library, the following code was able to give me the image below. Just like my cameras, this can indeed be a tile. Or I can allow the user to configure two pins to watch and those become tiles. Something like that…

<?php
header("Content-type: image/png");
$im = @imagecreate(500, 250)
    or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 255, 255, 255);
$array = explode("\n", shell_exec("gpio readall"));
imagestring($im, 2, 10, 0, " ", $text_color);
$counter=12;
foreach ($array as $v) {
    imagestring($im, 2, 10, $counter, $v, $text_color);
    $counter = $counter + 12;
}
imagepng($im);
imagedestroy($im);
?>

I just updated GitHub. Looks like I broke the Test tile.

@Casper I also modified the CustomTrigger function to be called off() and guess what, Amazon Echo works like a charm :slight_smile: so instead of Turn ON The Gate Switch, I now can say Turn OFF The Gate Switch and it runs the custom trigger. Pretty damn cool. I’ll update the release notes later tonight but GitHub already has the new code. Enjoy!

Wow awesome news on that CustomTrigger :slight_smile:

For the tile with image, is it possible to send that image to a tile? Currently I have my IP camera sending snapshots to email, it’d be great I can see those snapshots from a tile.