[OBSOLETE] Raspberry Pi Device Type

Update: See the Raspberry Pi Device Type & BerryIO post.

I’ve created a device type for the Raspberry Pi that utilizes WebIOPi as a REST endpoint for SmartThings to communicate with. As of right now, I’ve only gathered the Raspberry Pi internal sensor readings but the GPIO can easily be added later! Please take a look and let me know if you have any suggestions or feedback.

Installation instructions can be found on GitHub

20 Likes

Very cool! I have been tinkering with panels for my home computers that all run linux.

@NickW
This is great!!! I can’t wait to try this at home.
Many houses have existing pre-wired door and window magnetic sensors, and I believe your implementation will allow a Rapsberry Pi to monitor these sensors. Looking forward to your progress.

Any idea why Python3 is using 100% cpu after doing this?

No, it is just what WebIOPi uses.

This worked perfectly!! Thanks so much.

Not to analyze the code and change it!! :smile:

edit1: I now have a recipe working on IFTTT from changes on my Pi through SmartThings. Fun!!!

If you changed the code, would you mind sharing it so that other people might use it? Thanks!

I sure will but I didn’t change anything yet. I noticed in the Groovy code you defined a “switch” capability. I also noticed that when I hit refresh on the SmartThings iPhone app I get an off/on sequence. So I went to my IFTTT/SmartThings channel and the Pi was there. I activated it in the channel, created a recipe that notified me on my iPhone whenever the Pi was turned on, did a refresh and I got my notification. It all worked great!!

In the next day or so I will be getting into this a little more.

The reason I have the on/off sequence is that I have no way of knowing that STs never received a response from the RPi after sending the POST request, so I assume that it is off until a response is parsed.

Very nice! I am very interested in your progress in this area, as a) I have been watching SmartThings for a while now to monitor product maturity and b) I built an RPi-enabled garage door controller in June that specifically uses WebIOPi to communicate with the GPIO pins. I current have it wired to a magnetic overhead door sensor so that I can query open/closed status, and of course I can toggle the opener. Really interested to know when you add support for the GPIO pins so I can get serious about bringing SmartThings into my home. :slight_smile: What kinds of activities are you considering adding as part of this device type? Thanks!

I’m debating on how I want to approach this. The problem being that the pins can be both inputs and outputs. I’m thinking of having a preference that allows you to choose only one input or output and then show/control it in the dashboard. I’m open to ideas.

WebIOPi using 100% CPU can be easily fixed as it is using all the CPU calling your loop() function. I put a 1/10th of second sleep in the loop() and my CPU usage went down to 6%. I can’t think that this will induce any latency. Specifically in raspberrypi.py:
def loop():
# do nothing
# Sleep for 1/10th second. Otherwise WebIOPi uses 100% of the CPU
sleep(0.1)

I believe that I saw this done in one of the WebIOPi tutorials.

1 Like

@Garnet, that worked. Mine is now running at 5%. Thanks for the fix. I’ve also updated the GitHub repository.

Thanks for this! I have a few Pi ideas for voice control using the google voice API through the pi (already working to turn on/off through the GPIO), but am still new to the device type smartthing structure. This got me unstuck. Plan is to use the pi for the voice processing heavy lifting with google, then just set a string to have a smart app perform the desired actions.

@Mihos, that sounds like a great project :smile: Please be sure to share your work with the community once it is finished.

Thanks for this! I just installed it on one pi and it works great – now I can cheaply add some GPIO sensors to my SmartThings. First project will be a vibration sensor to tell me when someone rings my doorbell.

Your instructions were really easy to follow, BTW. Thank you for being detailed and thorough.

Thanks for the great instructions. Unfortunately, it doesn’t quite work for me.

The device shows up in in the app, the RPi side seems to be working, but I don’t see any packets coming out of the hub.

I uncommented the extra debug lines – so in the ‘live logging’ screen, I can see that the ‘refresh’ button triggers the device to create a valid POST request to send, but the packet never makes it out of the hub. The IP and port appear to be correct in both ascii and hex, and credentials are correct.

There is a packet sniffer + wireshark watching the link between the hub and my switch. The only traffic is https between the hub and the SmartThings cloud at AWS. Nothing to any local IPs.

Does this still work?
I’m wondering if something changed with the hubAction call.

BTW, I can take the POST request from the live logging screen and send it via telnet to webiopi on the Raspberry Pi, and get a sensible response – so that should work if the request ever got sent from the SmartThings hub.

Thanks, any help would be appreciated…

@JamesH this appears to still work. I actually have a beta version of a Raspberry Pi Garage Door controller based on the @NickW code, and it appears to still work. I have found a few issues with ST that you may want to check.

  • Many times the ST debugger dies and just stops receiving messages. Sometime logging out and back in work. (Actually ST logs you out sometimes, but doesn’t notify you.) Restarting the web browser is the last resort.
  • Old messages get ignored. Any message from Raspberry PI that take more the 5 seconds get ignored/lost. (This is probably a feature.)
  • WebIOPi has an Error or crashed. Test WebIOPi: “tail -20 /var/log/webiopi” and http://yourRasperryPI_IPAddress:8000 which should show you the WebIOPi main page. (Double check UserID and Password this way.)

@JamesH, I would first check to make sure that in your Device List, your Rasperry Pi has a Hub and Device Network Id listed. The Device Network Id should be hex encoded IP address and port.

Thanks – the hub is ‘home’ like the rest, and the device network ID is shown.
I added it manually, trying both upper and lowercase.
– do you expect it to be set by the device code?

In the ‘My Devices’ list, the RPi shows as ‘INACTIVE’ – but so does a working power outlet, so that’s confusing.

In the ST logger, I see:

7:45:40 AM PST: debug POST /macros/getData HTTP/1.1
Accept: /
User-Agent: Linux UPnP/1.0 SmartThings
HOST: 10.0.1.225:8000
Authorization: Basic d2ViaW9waTp3ZWJpb3Bp

7:45:40 AM PST: debug Executing hubAction on 10.0.1.225:8000
7:45:40 AM PST: debug Headers are [HOST:10.0.1.225:8000, Authorization:Basic d2ViaW9waTp3ZWJpb3Bp]
7:45:40 AM PST: debug Getting headers
7:45:40 AM PST: debug Credentials are Basic d2ViaW9waTp3ZWJpb3Bp
7:45:40 AM PST: debug ASCII credentials are webiopi:webiopi
7:45:40 AM PST: debug Encoding credentials
7:45:40 AM PST: debug Device Network Id set to 0a0001e1:1f40
7:45:40 AM PST: debug Executing ‘refresh’

… but no packets going out from the hub, only the encrypted traffic between the hub and AWS …

$ tshark -r app2.pcap | grep "10.0.1.10"
8 2014-11-12 15:45:30.533784000 10.0.1.10 -> 50.19.244.133 SSL 60 Continuation Data
9 2014-11-12 15:45:30.548402000 10.0.1.10 -> 50.19.244.133 TCP 60 [TCP segment of a reassembled PDU]
10 2014-11-12 15:45:30.548443000 10.0.1.10 -> 50.19.244.133 SSLv3 123 Application Data
11 2014-11-12 15:45:30.619410000 50.19.244.133 -> 10.0.1.10 TCP 60 https > ies-lm [ACK] Seq=1 Ack=2 Win=15360 Len=0
12 2014-11-12 15:45:30.635657000 50.19.244.133 -> 10.0.1.10 TCP 60 https > ies-lm [ACK] Seq=1 Ack=7 Win=15360 Len=0
13 2014-11-12 15:45:30.641160000 50.19.244.133 -> 10.0.1.10 TCP 60 https > ies-lm [ACK] Seq=1 Ack=76 Win=15360 Len=0
14 2014-11-12 15:45:30.642404000 50.19.244.133 -> 10.0.1.10 SSLv3 110 Application Data
15 2014-11-12 15:45:30.643028000 10.0.1.10 -> 50.19.244.133 TCP 60 ies-lm > https [ACK] Seq=76 Ack=57 Win=768 Len=0
19 2014-11-12 15:45:40.608500000 10.0.1.10 -> 50.19.244.133 TCP 60 [TCP Keep-Alive] ies-lm > https [ACK] Seq=75 Ack=57 Win=768 Len=1
20 2014-11-12 15:45:40.692996000 50.19.244.133 -> 10.0.1.10 TCP 60 [TCP Keep-Alive ACK] https > ies-lm [ACK] Seq=57 Ack=76 Win=15360 Len=0

… the RPi responds to the POST request over the network (via telnet from a mac) so that’s working …

$ telnet 10.0.1.225 8000
Trying 10.0.1.225…
Connected to 10.0.1.225.
Escape character is ‘^]’.
POST /macros/getData HTTP/1.1
Accept: /
User-Agent: Linux UPnP/1.0 SmartThings
HOST: 10.0.1.225:8000
Authorization: Basic d2ViaW9waTp3ZWJpb3Bp

HTTP/1.0 200 OK
Server: WebIOPi/0.7.0/Python3.2
Date: Wed, 12 Nov 2014 15:51:10 GMT
Cache-Control: no-cache
Content-Type: text/plain
Content-Length: 93

{
“disk_usage”: 18.9,
“mem_avail”: 101.9,
“cpu_temp”: 47.6,
“cpu_perc”: 0.9
}Connection closed by foreign host.

Last night I tried adding a SmartApp to set up the static IP, and to register a child device – but no success with that so far.