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

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.

@Casper, you’re missing out then… check out the following 3 links. Which IP Cam do you use?

And yes it’s obviously possible to add an image tile but it’s a huge tile and I gotta keep in mind that installing php-gd library is required. That means I have to run the install/check-if-installed command every time as validation, etc. Something to consider but I’m not sure if I’m 100% there simply because that image may already be outdated by the time you get it in ST. In my case, I flip it on then off within 1 second so what’s the point of seeing it’s CURRENT position. Lastly, I may create a NEW device that only asks for this image. The limitation is that the DeviceID in ST has to be unique so I can’t point to the same IP for multiple devices. However, I can put some fake/random name as the DeviceID once my logic stops. This will invariably allow ST to have TWO devices pointing to the same IP. I need to play with that concept a bit more. Hope that all makes sense.

Here are your camera links, mine is the first one for PTZ Panasonic cameras:

Thanks for the links @JZst, I’m using an amateur RPi camera, it has its own mechanism of capturing videos and such. What I really want is to see the most recent snapshot and display it as a big tile in your HTTP device type.

Thanks for doing that - I was bored that day and hacked together a refresh button using the test option also. Switched back to your code and all looks good.

Now I need to change the main page icon from Gate to an On/Off switch so I can quickly take a look at the PI.

Great work so far!

Releasing new version. Notes below. Also created a related project which spits out the GPIO statuses into a SmartThings Device image tile. See the related project link below. One HUGE improvement that I have not seen much in these forums is the fact that I change the DEVICEID to some random number after execution. This allows you to point more than one ST device to an internal IP:

v1.0.20160410 - Changing device ID to random number at end of execution so multiple devices can point to one IP. Amazon Echo can run both ON/main and OFF/custom functions. Added ability to output GPIO status in PHP. Releasing another ST device that will pull the image and control the installation of required packages hence the reset of device ID.

1 Like

v1.0.20160410 - Changing device ID to random number at end of execution so multiple devices can point to one

This is excellent.

Yeah the deviceid hack was a moment of glory :slight_smile: I haven’t seen this discussed before and just decided to try. What a thing of beauty!

In case I haven’t thanked the couple of people who have no idea who I am, I want to do so now. @pstuart and his code changed the game with the internal IP. The combination of his code and @blebson writing the D-Link camera devices, I could not have done this w/o them. In fact the combination of @pstuart’s generic camera driver and @blebson’s D-link examples is how Panasonic PTZ Camera device was created. Only after that, I was daring enough to do something full on my own (borrowing their code of course :slight_smile:) Thanking them both!

Here’s the Panasonic PTZ Camera driver that I’m referring to:

1 Like

My PI is closed up in a wiring box so I haven’t taken the time to test this but what happens if the pi is off or locks up? I assume it will “test” forever and won’t really get an error?

I was hoping to use this to alert if the pi is off for some reason but I am not sure the current code can do that. Any thoughts here? I would almost like it as an on/off switch based on it it’s running so I can get alerted but I don’t think we have a sense of “off” here.

I see what you’re asking for but unfortunately the ST implementation requires the HTTP device to come back with something in order to hit the parse() function which does all of the tile painting logic. There is no generic “ping” type of activity that I know of. However, I have mine set up with Pollster for every 15 minutes so my Test Triggered tile is expected to be within 15 minutes of the current time. This is one easy way for me to know that my Pi answered within the last 15 minutes.

figured so - too bad there is no timeout on that which could be used to detect off.
I was using berryio earlier but after my re-image this seemed nice and light and gave me what I needed.

I appreciate all the work - working great!

Yeah it’s kinda lame not to have some timeout that allows me to launch some other function rather than the auto-launched parse() but Pollster is my workaround and it’s been perfect for what you’re referring to — at least for my minuscule needs :slight_smile:

BTW, the light-weight and easy portability (like when re-imaging/starting from scratch) as it’s only a single PHP to drop in and NOTHING ELSE other than the ST devices that you want to point to that PHP output. This was the main motivation otherwise I may be using berryio :slight_smile:

Hello, i am very new to smartthings and have almost none coding knowledge.

What are the requisites for this on the Raspberry Pi?

I have to install apache and php right?

what else should i need?

Thank you very much!

I tried with my Raspberry but i was unsuccessfull unfortunately.

I am receiving this error, i am guessing it is an error on how i set up the device.

The web interface was working from another computer.

But the smartthings wont even pick the raspberry pi up.

This is the error i am getting:
grails.validation.ValidationException: Validation Error(s) occurred during save():

Field error in object ‘physicalgraph.device.Device’ on field
’deviceNetworkId’: rejected value [C0A81132:0050]; codes
[physicalgraph.device.Device.deviceNetworkId.unique.error.physicalgraph.device.Device.deviceNetworkId,physicalgraph.device.Device.deviceNetworkId.unique.error.deviceNetworkId,physicalgraph.device.Device.deviceNetworkId.unique.error.java.lang.String,physicalgraph.device.Device.deviceNetworkId.unique.error,device.deviceNetworkId.unique.error.physicalgraph.device.Device.deviceNetworkId,device.deviceNetworkId.unique.error.deviceNetworkId,device.deviceNetworkId.unique.error.java.lang.String,device.deviceNetworkId.unique.error,physicalgraph.device.Device.deviceNetworkId.unique.physicalgraph.device.Device.deviceNetworkId,physicalgraph.device.Device.deviceNetworkId.unique.deviceNetworkId,physicalgraph.device.Device.deviceNetworkId.unique.java.lang.String,physicalgraph.device.Device.deviceNetworkId.unique,device.deviceNetworkId.unique.physicalgraph.device.Device.deviceNetworkId,device.deviceNetworkId.unique.deviceNetworkId,device.deviceNetworkId.unique.java.lang.String,device.deviceNetworkId.unique,unique.physicalgraph.device.Device.deviceNetworkId,unique.deviceNetworkId,unique.java.lang.String,unique];
arguments [deviceNetworkId,class
physicalgraph.device.Device,C0A81132:0050]; default message [{0} must be
unique]

[quote=“Detezmorena, post:53, topic:43335, full:true”]
grails.validation.ValidationException: Validation Error(s) occurred during save():
Field error in object ‘physicalgraph.device.Device’ on field
’deviceNetworkId’: rejected value [C0A81132:0050]; codes
[physicalgraph.device.Device.deviceNetworkId.unique.error.physicalgraph.device.Device.deviceNetworkId,physicalgraph.device.Device.deviceNetworkId.unique.error.deviceNetworkId,physicalgraph.device.Device.deviceNetworkId.unique.error.java[/quote]

Highlighting the pieces above you need to pay attention to. You obviously have another device with the same ID. Change that device’s ID and then ST should be able to save that local IP in hex.

1 Like

Updated minor things mostly because I got a new Raspberry Pi 3 and it has more pins and lines returned from the command “gpio readall” than my old Model B.

v1.0.20160423 - Small changes: using second line of df -h for space used. Scaling GPIO image better for RPi 3 with more lines on gpio readall command.