[NEEDS UPDATING] Raspberry Pi Relay Controller (WebIOPi)

This looks great! I have been struggling the past couple days trying to get my Raspberry Pi hooked up with ST using some older projects (referenced below). But can’t get either of these up and running. Excited to try your code! Also glad yours is built around Webiopi as I have been using that for a couple years now Pi’s.

Quick question on your plans for updating. I am using my Pi in my Utility Room for the following purposes:

  1. Monitor an input from my legacy home alarm system that signals an alarm.
  2. Control a relay output that will activate the siren on my legacy home alarm system.
  3. Monitor a temperature sensor that I have hooked up to my hot water heater (to determine when it is heating, a.k.a. flame on)
  4. Control a relay output that will open/close a fresh air intake damper based on when the hot water heater is running.

With your setup I think I can handle the relay outputs no problem now. Any plans to include RPi GPIO inputs as ST open/close sensors? Any plans to include Webiopi temperature devices readings as an ST temperature sensor?

Thanks and keep up the good work! So surprised there aren’t more Raspberry Pi & ST projects out there.

Doug

1 Like

Tried the relay control just now and it is working great. Now I can control my electronic damper via ST. Thanks again for sharing this!

Doug

1 Like

Hi @iBeech I inadvertently added two GPIOs when initially configuring the SmartApp from my mobile device. I’m trying to delete it now to start over, and no matter what I try when I go to clear out device name and GPIO numbers, I get the error “Failed to save page: defaultPage”. Can you offer any advise for removing the devices so I can remove the SmartApp?

Thanks!

Edit: I figured out that if even with receiving the error, it would save some values. Once I changed the IP address to something other than my Raspberry Pi, and saved it, I was finally able to remove all the GPIOs and name to uninstall it.

@douglaseucken I’ve already coded support in for temperature sensors, however i’m trying to iron out an issue caused by WebOIPi… well, more SmartThings… When i sent my request to query the temperature, the response is simply the temperature; it does not include any details about which temperature sensor you requested. Due to the way SmartThings works, this causes issues as I don’t know which device to update.

It’s possible I could limit to 1 temperature sensor per Pi…?

I do not personally have any experience with any other inputs, however, I would like to help out- which REST services did you want to use?

@iBeech Thanks for the reply. I follow you on the limitation of multiple temp sensors to one Pi. For my personal application limiting it to one temp sensor per Pi wouldn’t be an issue. So I would love to see that.

In terms of the inputs side of things, all I was thinking about trying to implement was using the “get GPIO value” REST service.

Get GPIO value
HTTP GET /GPIO/(gpioNumber)/value
Returns 0 or 1
Example :
To get GPIO 0 value : HTTP GET /GPIO/0/value

Basically map that to a GPIO input pin and then to a Smart Things open/close sensor. This way the output from my old style home alarm system goes through the Pi and looks just like another door or window sensor to ST. Then I can use the ST security routine to notify me of alarms and turn on the alarm siren, lights, etc.

I would also echo the sentiments of @MAINEIAC on the refreshing of the ST relay state. I have a couple scenarios where I will use a python script with Webiopi to do things in the background on the Pi (turn on GPIO when the temperature is above a threshold, etc). But it would be nice to be able to see current status of the relay on ST, and not have to rely only on having ST change its state.

Thanks again for the reply and a super big thanks if you are willing to make some of these updates. This type of Pi and ST integration is sooooooo useful to the DIY crowd!

Thats what it already does, in the form of a switch. I will be updating it shortly so that if an external entity changes the GPIO state, SmartThings will become aware of that fact within a short period of time (10-20 seconds).

Does that solve your issue?

I have issues with the ST documentation. Can someone boil down the syntax of the ST/webiopi REST requests for me? I understand the adress has to be in hex, but I still cannot get a successful GET or POST under my own code.

Keep up the good work Tom!

@iBeech I think that should work just fine. I think I can install a “switch” using the Pi Relay Manager and then go into it’s device settings (on the ST IDE page) and change it to a open/close sensor. Hopefully the Webiopi mapping still works and then I am in business.

Can’t wait to try it out.

I can add an open close sensor for you :slight_smile:

I’ve made a major update to the SmartApp.

  • Supports Temperature sensors (I’ll post a tutorial on how to set your temperature sensor up)
  • Your switch will update in SmartThings if it was changed from outside SmartThings, this takes up to 10 seconds

Please uninstall your current version by opening the SmartApp, remove all references to your relays and then save, next go and delete the relay devices from your ‘things’ page. Upgrade, and re-add them.

@iBeech Trying the updated code and having a couple issues. After devices are setup the ST app crashes. Everything seems to work fine after you relaunch it though. I am on a Android Nexus 5X.

I was able to setup a temperature device successfully, I even made a small code tweak to switch to report temps in Fahrenheit. What I am running into though is that after about 3-5 temperature refreshes the temperature device stops updating and so do any other relay devices. Nothing seems to kick it back into gear short of removing all the devices and reinstalling. But again after a few refreshes it stops. I tried just installing a relay device (no temp device) and that seems to have no problem auto-updating. Any ideas?

I do like the new setup page for the smart app and the removal process goes much smoother now too. Thanks again for sharing with everyone.

Smells like the runIn bug with SmartThings. Search the smart app for ‘runIn’ and change the number to something like 300 (this represents seconds) and see if things look better after that

Glad you have got things working (even if partially). And glad to help

I’ll see if I can update the app to pull which temperature measurement to use out of your location

@iBeech I have been trying this out and have not been able to keep one of the items active for very long. Even when I push the runin time up to 300 seconds it will eventually stop responding.

I did some Google-ing and it seems that most people say any runin time over 60 seconds should work.

Seems puzzling. Any ideas?

Unfortunately, it would seem that the SmartThings platform doesn’t do polling very well at all. It is inconsistent, even when it does work.

I also experience this issue regularly with my temperature sensors. I’m not actually sure if there is a solution… other than to write a custom service which can do the polling re-present the data via REST, and get the smartapp to subscribe…

I’ll have a think.

Hopefully this will change when the new scheduler gets rolled out…

New scheduler you say? I’ve not heard of it. Got a link?

They’ve stated that it’s in beta testing, i’ll try to drudge up the link in a few.

Edit:

If you click the link you will see the whole text but here it is for ease of effort:

I know it was mentioned more times, but this was the first one I could find. Please note that the Fairly soon comment was 28 days ago… i’m sure that it will be here … “in a few weeks” (via ST time of course) =P

New scheduler is currently being tested internally. Make sure you sign up to be a beta tester if you want to be informed when we start rolling it out.

http://developer.smartthings.com/developers/beta-tester

1 Like

New scheduler sounds promising.

In the mean time I found a different way to skin the cat. I am using Webiopi, IFTTT’s Maker channel, and simulated switches in Smart Things. I create a simulated Smart Things switch through the Smart Things IDE. Then I use IFTTT to create recipes like:

If: Smart Things simulated switch is set to ON
Then: Use the IFTTT Maker channel to send a REST POST command to the Pi that sets a GPIO output to 1.

If: Smart Things simulated switch is set to OFF
Then: IFTTT Maker channel sends REST POST command to the Pi that sets a GPIO output to 0.

You can also have python scripts on the Pi update the Smart Things simulated switch automatically/real time using IFTTT. No periodic polling required. Recipe on IFTTT is:

If: Maker Channel event trigger (switch_on as an example name) is activated
Then: Set the Smart Things simulated switch to ON.

If: Maker Channel event trigger (switch_off) is activated
Then: Set the Smart Things simulated switch to OFF.

Then I use a custom python script (run with Webiopi) that uses the following command when I want to turn the switch on:

system(‘curl -X POST https://maker.ifttt.com/trigger/switch_on/with/key/your_custom_Maker_channel_key_goes_here’)

Its seems to work pretty well. Check out the https://ifttt.com/maker and https://ifttt.com/smartthings for more information. Only draw back to this approach is that you are limited by the Smart Things IFTTT action choices. You can only control switches, sirens, and locks. I wanted to be able to create a simulated open/close sensor and map it to a Raspberry Pi GPIO Input but that doesn’t seem to be possible.

Hopefully improvements to the SmartThings IDE will eliminate the need for such a convoluted solution, but hey, it works for now.

Signed up. This was my biggest problem with SmartThings, which kinda took the shine off. If its being fixed, its happy days!

1 Like