Sorry for a noob question, I’m only a day into ST and learning as I go!
I’m looking to use my Raspberry Pi to turn on an LED based on the status of a Z-Wave tilt switch. Actually, probably more like 3 tilt switches.
I see I can get the Raspberry Pi added to the ST Hub as a device, but is something possible for the Hub to send status messages to the Pi? That way based on a certain status message I can light an LED (or 2, or 3).
You could run a web service on the RPi then create a SmartApp that subscribes to events and posts them to your desired web service endpoint on the RPi.
Something like the Web Hook SmartApp by @harper might be helpful:
This worked great. Thanks for the Web Hook SmartApp. I then used my Raspberry Pi and a quick PHP POST handler to filter the JSON POSTs and send me a push notification for the events I care about.
Certainly much more to play with, but this is a pretty neat start.
Yes, you can create an HTTP Endpoint SmartApp and poll the endpoint. With Hub v1, all of the SmartApp processing is in the cloud so this will actually poll the SmartThings servers. Even with Hub v2, the feedback has been that even though the hub will have support for running SmartApps locally, it will not ship with the capability to run HTTP SmartApps locally although they hope to add that feature at a later point.
Is there a particular reason you want to poll SmartThings instead of receive the push event?
I’ll look into this. My thought is to use this for garage door tilt sensor. Based on the position of the door, it’ll turn on an LED light for a quick physical status without having to check the app and/or door itself.
If the Raspberry Pi reboots or loses its connection, then the LED status could become stale. So by polling ST hub for a status, it’ll keep the light in an accurate state.
Wow, I’m not sure how I missed this at first, then continued to miss it for 6 months! @Casper if you’re still around and looking for this, here’s what I’m using.
The webhooks posts to a PHP file on my server (it was my Pi, but I moved it to a VPS).
Basically PHP grabs the JSON POST by using php://input, I trim any newlines and tabs from the input, then send it off to a Python script as the 1st argument, and Python will handle the rest.
My Python script is running a few libraries that PHP doesn’t have (or at least Python makes it easier), such as US Holidays and business days. That way I can filter certain alerts during certain times (such as a door opening while I’m at work, or my thermostat running while I’m at work (so 9-5 on a business day)). Then if I get an alert from IFTTT on my phone within this granular timescale, I can log into ST and turn off the tstat to help save energy.
I started doing this over a year ago before ST’s notifications were a thing, and it’s something I use to this day since I can have fine tuned alerts. Maybe it’s overkill? It works for me.
You could take this same logic and apply it to a Python script running the GPIO library to turn on a light or something on your Raspberry Pi as well. Or even turn the light on a blink(1) USB RGB. They have a great API to control the 2 LEDs in the device and make them any color you want. I love those things. Multiple LEDs and multiple colors that can be used for multiple meanings. With the ease of use of a USB.