[RELEASE] Raspberry Pi Relay Controller (WebIOPi)

smartapp_misc
requires_server

(Tom Beech) #1

Hey all,

UPDATE: I have added functionality to ensure that changes made to WebIOPi outside of SmartThings are picked up. Please uninstall your current version by removing all references to your relays, then deleting the relays. Upgrade, and re-add them. It’s a much better experience this time

I wanted a device type to control raspberry Pi relays from SmartThings. I couldn’t find anything out there already, so this project was born.

Basically, we are going to set up our Pi with a HTTP REST service which is capable of turning on and off relays which can be connected to just about anything. Then we’ll add a device type which acts as a switch which is able to turn the relay on and off in SmartThings. You can then use this device in any SmartApp which uses switches.

This is a very ‘happy path’ guide. If you have any queries, feel free to leave a comment. I hope you find this useful.

Disclaimer: Do not mess with mains electricity, it could kill you!

Pre-Reqs

  1. Raspberry Pi - http://goo.gl/p7nCkZ
  2. Power cable for Pi - http://goo.gl/me82lz
  3. MicroSD card for Pi - http://goo.gl/sIhwh0
  4. MicroSD Card Reader - http://goo.gl/Mw9GN7
  5. Dupont Jumper Wire Ribbon (Female-Female) - http://goo.gl/iOiE6r
  6. Relay board for Raspberry Pi - http://goo.gl/7LBRe6
  7. Optional - WiFi Dongle for Pi - http://goo.gl/3QKbmM
  8. Optional - Case for Pi - http://goo.gl/zW7cDo
  9. Obvious - SmartThings Hub

That’s all the hardware, now you need now onto the configuration:

Prepare the MicroSD card for Pi

  1. Put the MicroSD card into the card reader and plug it into your PC
  2. Download the latest version of Raspbian from: https://downloads.raspberrypi.org/raspbian_latest
  3. Extract the .img file from the zip file you just downloaded
  4. Download and install Win32DiskImager from: http://sourceforge.net/projects/win32diskimager/
  5. Open Win32DiskImager, pick the .img file you just extracted
  6. Pick the MicroSD card from the device drop down
  7. Hit ‘Write’- This bit may take a while depending on how fast your card / reader is.
  8. Once complete, insert the sd card into your Pi

Prepare Pi

  1. Plugin your WiFi dongle or ethernet cable and a keyboard / mouse / HDMI into your pi and power it on
  2. If using WiFi: After you have been booted to the desktop, click the network icon at the top right and connect to your WiFi network
  3. Open terminal and type ‘ifconfig’ and take note of your IP address
  4. You can now unplug your keyboard / mouse / HDMI

Connect to Pi via SSH on your computer

  1. Download Putty from http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe
  2. Open Putty and enter the IP address of your Pi which you previously noted down
  3. Click ‘Open’ you should get a prompt saying that the servers host key is not cached, click ‘Yes’ to cache it and proceed
  4. Log into Pi with username ‘pi’ and password ‘raspberry’
  5. You should now have a prompt

Install WebIOPi (This provides us with a REST interface to the GPIO)

  1. Type the following commands at the Pi prompt:

wget http://sourceforge.net/projects/webiopi/files/WebIOPi-0.7.1.tar.gz
tar -zxvf WebIOPi-0.7.1.tar.gz
cd WebIOPi-0-7.1
sudo ./setup.sh

  1. As your Pi is not exposed to the internet (i.e. Pi can see the internet, but the internet cannot see Pi), our next step is to remove the password for easier communication. Enter the following at the prompt:

sudo nano /etc/webiopi/passwd

  1. Delete the content of the file and press: Ctrl+O then Enter then Ctrl+X to return to the prompt
  2. Start WebIOPi as a service so that it runs every time your Pi is turned on. Enter the following at the prompt:

sudo /etc/init.d/webiopi start

  1. Verify that WebIOPi is set up correctly, navigate your browser to http://{IPADDRESS}:8000. You should see the WebIOPi Main Menu
    http://i.imgur.com/6QMNV7m.png

Connect your Relay up to your Pi

  1. Connect the ground (-) terminal of your relay to one of the ground pins (6, 9, 14, 20, 25, 30, 34 or 39)
  2. Connect the positive (+) terminal of your relay to one of the 5V (2 or 4) pins
  3. Connect the switch terminal of your relay to one of the GPIO pins (7, 11, 12, 13, 15, 16, 18, 22, 29, 31, 32, 33, 35, 36, 37, 38 or 50). Take note that the pin number does not match the GPIO number. Use the image below as a reference to lookup the GPIO number of the pin you select (i.e. pin 7 is GPIO 4)
    http://www.raspberrypi-spy.co.uk/wp-content/uploads/2014/07/Raspberry-Pi-GPIO-Layout-Model-B-Plus.png

Verify your Relay is working

  1. Navigate your browser to http://{IPADDRESS}:8000/app/gpio-list
  2. You should see a list of GPIO numbers, with ‘IN’ next to each of them
  3. Locate the GPIO you are using, and click the ‘IN’ button. It will change to ‘OUT’. The reason for this is that we are sending a signal to the relay, rather than the relay sending a signal back to Pi. (The SmartThings device type deals with this for us, we are just testing your relay at this point)
  4. Click the GPIO number you are using, it should change to orange, and you should hear a click from your relay, as well as an ‘on’ LED, if your relay has one
  5. If that worked, congratulations! You are ready to configure the SmartThings device type

Install the Device Type and SmartApp to SmartThings
Goto and follow the instructions:


Install the Pi Relay Manager SmartApp

  1. Goto your mobile device and open SmartThings
  2. Got the Marketplace tab at the bottom
  3. Tap SmartApps’
  4. Scroll to the bottom and tap My Apps’
  5. Tap ‘Pi Relay Manager’
  6. Fill in the details that have been requested (The default port is 8000) and click ‘Done’
  7. If you connected a relay to GPIO 17, give device 1 a name, pick the relay switch type and enter ‘17’ in ‘GPIO# or Device Name’

Your switches have now been added to your list of SmartThings. You can use them in other SmartApps just like regular switches


Raspberry Pi 3 and smartthings
Raspberry Pi As switchable device
Smart Sprinkler System
N00b question regarding Raspberry PI as a LAN Connected Device
FS: Want my smart-Pi system?
DSC -> EVL-3(4) -> Alarmserver -> Smartthings
Raspberry Pi Garage Door Opener With Current State
N00b Help: Raspberry Pi Garage door opener with current state
Lack of UK ....errr... well everything really!
Toggle only works in simulator
(Jdmcgee) #2

Thanks much for releasing this!!! I had gotten a Robogaia 4-Relay Pi Plate for a song just a few days ago. I thought I could figure out how to integrate it with ST pulling double duty as 1) a custom sprinkler relay unit & 2) a front door camera. The camera part seems to be somewhat simple since there are already device handlers floating around for cameras but the GPIO control for sprinkler relays through SmartThings was new ground for me. I was going to have to figure out how to write a device type handler and smart app in Groovy… and I have absolutely no coding experience. You might’ve just made things a lot easier for me!

The plate is premade to use GPIO numbers 4, 17, 27, & 22 to flip on the attached relays. None of those GPIO pins are mentioned as usable options in your above instructions. Any hints on where I should start, if possible, to alter things to use the pins I need for the Robogaia Pi Plate???

Thanks Again, JD


(Tom Beech) #3

You can create as many devices as you want with the device type I wrote, each one has a preference for the Pi IP address / port number and GPIO you want to use, this is configured in the SmartThings app :smile:

Glad you are finding it useful!


(Jdmcgee) #4

Working like a charm!!! I’ve essentially got my custom sprinkler/front door cam now.

Thanks Again! I sincerely appreciate it.

JD


(Jdmcgee) #5

I might’ve spoken too soon. It works but only 1 Relay a time. I installed 4 Pi Relays through the IDE. I’m pretty confident I entered all info correctly on all 4 instances of them. Pi Relay 1 works great but 2, 3, & 4 won’t function & give errors in the live log yet all 4 still work if done on the webpage of WebIOPi. Attached are some samples of the logs.
logo
All
Pi Relay 1
Pi Relay 2
Pi Relay 3
Pi Relay 4
LogsClear
99ee7740-d9fe-442d-b4f8-dc1bc79f07f2 3:49:45 AM: error grails.validation.ValidationException: Validation Error(s) occurred during save():

  • Field error in object ‘physicalgraph.device.Device’ on field ‘deviceNetworkId’: rejected value [C0A80D81:1f40]; 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,C0A80D81:1f40]; default message [{0} must be unique]
    99ee7740-d9fe-442d-b4f8-dc1bc79f07f2 3:49:45 AM: debug Delaying by: 100
    99ee7740-d9fe-442d-b4f8-dc1bc79f07f2 3:49:45 AM: debug The POST path is: /GPIO/22/value/1
    99ee7740-d9fe-442d-b4f8-dc1bc79f07f2 3:49:45 AM: debug Executing 'setDeviceState’
    99ee7740-d9fe-442d-b4f8-dc1bc79f07f2 3:49:45 AM: debug Executing 'on’
    99ee7740-d9fe-442d-b4f8-dc1bc79f07f2 3:49:44 AM: error grails.validation.ValidationException: Validation Error(s) occurred during save():
  • Field error in object ‘physicalgraph.device.Device’ on field ‘deviceNetworkId’: rejected value [C0A80D81:1f40]; 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,C0A80D81:1f40]; default message [{0} must be unique]
    99ee7740-d9fe-442d-b4f8-dc1bc79f07f2 3:49:44 AM: debug Delaying by: 100
    99ee7740-d9fe-442d-b4f8-dc1bc79f07f2 3:49:44 AM: debug The POST path is: /GPIO/22/value/0
    99ee7740-d9fe-442d-b4f8-dc1bc79f07f2 3:49:44 AM: debug Executing 'setDeviceState’
    99ee7740-d9fe-442d-b4f8-dc1bc79f07f2 3:49:44 AM: debug Executing 'off’
    8a176767-6b4b-4e66-8f8d-aa58ea05af53 3:49:31 AM: error grails.validation.ValidationException: Validation Error(s) occurred during save():
  • Field error in object ‘physicalgraph.device.Device’ on field ‘deviceNetworkId’: rejected value [C0A80D81:1f40]; 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,C0A80D81:1f40]; default message [{0} must be unique]
    8a176767-6b4b-4e66-8f8d-aa58ea05af53 3:49:31 AM: debug Delaying by: 100
    8a176767-6b4b-4e66-8f8d-aa58ea05af53 3:49:31 AM: debug The POST path is: /GPIO/27/value/1
    8a176767-6b4b-4e66-8f8d-aa58ea05af53 3:49:31 AM: debug Executing 'setDeviceState’
    8a176767-6b4b-4e66-8f8d-aa58ea05af53 3:49:31 AM: debug Executing 'on’
    8a176767-6b4b-4e66-8f8d-aa58ea05af53 3:49:30 AM: error grails.validation.ValidationException: Validation Error(s) occurred during save():
  • Field error in object ‘physicalgraph.device.Device’ on field ‘deviceNetworkId’: rejected value [C0A80D81:1f40]; 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,C0A80D81:1f40]; default message [{0} must be unique]
    8a176767-6b4b-4e66-8f8d-aa58ea05af53 3:49:30 AM: debug Delaying by: 100
    8a176767-6b4b-4e66-8f8d-aa58ea05af53 3:49:30 AM: debug The POST path is: /GPIO/27/value/0
    8a176767-6b4b-4e66-8f8d-aa58ea05af53 3:49:30 AM: debug Executing 'setDeviceState’
    8a176767-6b4b-4e66-8f8d-aa58ea05af53 3:49:30 AM: debug Executing 'off’
    99ee7740-d9fe-442d-b4f8-dc1bc79f07f2 3:48:56 AM: error grails.validation.ValidationException: Validation Error(s) occurred during save():
  • Field error in object ‘physicalgraph.device.Device’ on field ‘deviceNetworkId’: rejected value [C0A80D81:1f40]; 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,C0A80D81:1f40]; default message [{0} must be unique]
    99ee7740-d9fe-442d-b4f8-dc1bc79f07f2 3:48:56 AM: debug Delaying by: 100
    99ee7740-d9fe-442d-b4f8-dc1bc79f07f2 3:48:56 AM: debug The POST path is: /GPIO/22/value/0
    99ee7740-d9fe-442d-b4f8-dc1bc79f07f2 3:48:56 AM: debug Executing 'setDeviceState’
    99ee7740-d9fe-442d-b4f8-dc1bc79f07f2 3:48:56 AM: debug Executing 'off’
    8a176767-6b4b-4e66-8f8d-aa58ea05af53 3:48:55 AM: error grails.validation.ValidationException: Validation Error(s) occurred during save():
  • Field error in object ‘physicalgraph.device.Device’ on field ‘deviceNetworkId’: rejected value [C0A80D77:1f40]; 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,C0A80D77:1f40]; default message [{0} must be unique]
    8a176767-6b4b-4e66-8f8d-aa58ea05af53 3:48:55 AM: debug Delaying by: 100
    8a176767-6b4b-4e66-8f8d-aa58ea05af53 3:48:55 AM: debug The POST path is: /GPIO/27/value/0
    8a176767-6b4b-4e66-8f8d-aa58ea05af53 3:48:55 AM: debug Executing 'setDeviceState’
    8a176767-6b4b-4e66-8f8d-aa58ea05af53 3:48:55 AM: debug Executing 'off’
    7c24b641-2f15-424e-883e-7df2e54e0a29 3:48:55 AM: debug New state is: off
    7c24b641-2f15-424e-883e-7df2e54e0a29 3:48:55 AM: debug Relay current state: 0
    7c24b641-2f15-424e-883e-7df2e54e0a29 3:48:55 AM: debug GPIO state response
    7c24b641-2f15-424e-883e-7df2e54e0a29 3:48:55 AM: info Return data: HTTP/1.0 200 OK
    Server: WebIOPi/0.7.1/Python3.4
    Date: Sat, 23 Jan 2016 11:48:54 GMT
    Cache-Control: no-cache
    Content-Type: text/plain
    Content-Length: 1
    7c24b641-2f15-424e-883e-7df2e54e0a29 3:48:54 AM: debug GPIO 4 direction is OUT
    7c24b641-2f15-424e-883e-7df2e54e0a29 3:48:54 AM: debug GPIO position response
    7c24b641-2f15-424e-883e-7df2e54e0a29 3:48:54 AM: info Return data: HTTP/1.0 200 OK
    Server: WebIOPi/0.7.1/Python3.4
    Date: Sat, 23 Jan 2016 11:48:54 GMT
    Cache-Control: no-cache
    Content-Type: None
    Content-Length: 3

(Tom Beech) #6

You are welcome. Any feedback is welcome.


(Tom Beech) #7

ah, interesting! I had not considered that the network device id must be unique… I shall work on this tomorrow, and hopefully get a fix to you soon!


(Tom Beech) #8

OK, so this looks like a limitation of SmartThings… I’m still investigating though.

The only way I can think to get around this is to expose your Pi to the Internet so that we do not need to use the hub to send local actions. We would need to:

  1. Secure the Pi user by changing the default password
  2. Secure WebIOPi by enabling basic authentication and changing the default password
  3. Forward port 8000 from your router to your Pis IP address
  4. Change the devices IP address in SmartThings from the Pis address to your WAN IP.
  5. Update the Pi relay device type code with a new version (which I haven’t written yet) which uses cloud based commands httpGet and httpPost instead of hubAction commands, including adding support for basic authentication with WebIOPi

The network device id is only needed for sending local hub actions. Doing it this way would mean the command is sent from the SmartThings cloud to your Pi over the Internet.

If only this API wasn’t so limiting :frowning: there seems to be hurdle after hurdle!! I will look into forking the code and implementing this asap. I may code it so that the user has the option to use local commands or remote commands.


(Jdmcgee) #9

Thanks for looking into this. I sincerely appreciate it. Also,I don’t have a problem exposing my Pi to the web. I have a few things I can do to ensure it’s as secure as possible.

I’ll be anxiously awaiting the new Smartapp and/or device handler…

JD


(Tom Beech) #10

You are welcome. I think i’m going to do two things.

  1. A device type which communicates over WAN, which will get you up and running more quickly
  2. Re-write the whole thing as a SmartApp with virtual switches (This is currently in progress Subscribing to virtual devices)

(Tom Beech) #11

@jdmcgee I have now re-engineered the solution as a SmartApp- it now works with up to 8 relays (i can add more if requested). Please let me know how you get on!

You will need to delete the old devices which use the original device type. For tidiness, also delete the device type from your SmartThings IDE :smiley:


(Jdmcgee) #12

Tom,

I’m trying it tonight. I haven’t been able to do a status check with you due to being in the middle of a nearly full remodel of my house. It’s kept me busy to say the least.

I’m excited to get my custom, night-vision door cam (Pi Noir)/sprinkler controller up & going and incorporated into SmartThings. I’ll let you know how it goes later tonight or tomorrow.

Again, much thanks for your very speedy work on this device/app. If I can ever return the favor (of course, after my “groovy gets a little groovier”), don’t hesitate to ask!

jd


#13

Hi IBeech, i was very excited to test this but i stuck on couple issues, Hard to remove ST IDE or from IOS app, get error “There was an error uninstalling your smart app” specially Pi relay Manager. (I Have try several ways) And second, unclear what i should put on GPIO text relay name? actual GPIO port or just name?

And one nice feature what i miss here is use GPIO ports even as input signal to smartthings, Anything your can add in to future?


(Tom Beech) #14

Hi @Texit. You need clear the device name and GPIO number the SmartApp, and save changed to remove the devices. The SmartApp is subscribed to events from the devices it creates, and as such you will be unable to delete them manually.

Using the latest SmartApp code, say you have a relay plugged into GPIO 11. Just scroll to ‘Relay 11 Name’ and give it a meaningful name. If the relay controls your living room lights, name it ‘Living Room Lights’ then hit ‘done’. The new device will be created for you.

Hope this helps.


#15

This is awesome! Thanks for creating this!


(Tom Beech) #16

You are welcome. I hope you find it useful! Any feedback is much appreciated.


(Ash) #17

Thanks for this code! I spent all weekend trying to get the “HubAction” request correct and was just about to give up.

One comment, if I change the status (HIGH/LOW) of one of the pins using other means, the device tile does not update. When I refresh, I can see under the logs (pasted below) that smartthings is receiving the correct pin status.

“debug result: [SPI:0, ONEWIRE:0, GPIO:[35:[value:1, function:IN],… 3:[value:1, function:OUT]”

Any ideas why the tile isn’t updated during refresh or poll?


(Tom Beech) #18

No problem. It is because I have not implemented the functionality to update the UI based on external changes to the pin out. I’ve put the boilerplate code in place, but not had time to finish it off. I’ll see if I can get around to it this week :slight_smile:


(James Guistwite) #19

I’ve been working on a parallel effort connecting my Raspberry Pi to the smart things hub and struggled with the same issues. Lack of adequate documentation, hidden restrictions - the deviceNetworkId unique requirement. I’m so glad I found your post having just hit the exception about the deviceNetworkId. I’m controlling relays with my Pi for garage door monitoring and sprinklers. I have a legacy smart home with a bunch of X10 devices so I’ve also connected the Pi to a CM11a X10 controller.

I’ve decided rather than rewriting my device controller, I added multiple (virtual) interfaces to the raspberry pi. My Pi now has 3 static IP addresses and I can use unique device network ids. The downside is that I need to add a new virtual interface for each device I want to control. I also thought I could have my web server listen on multiple ports - one for each device.

I don’t see the restriction going away any time soon. It seems that deviceNetworkId is used in order to route incoming HTTP traffic to the unique device handler.

Thanks again for your post - saved me a lot of time.


(Tom Beech) #20

I can certainly fix the update issue. I plan to do this in the smart app. Parsing all the relay states and passing them back to the appropriate virtual device via a custom command on the virtual device :slight_smile:

I plan to do this over the next couple of days.

Glad I could assist.