hi! nice thing… just what i need since i allready bought a raspberry pi 3 but many things are new to me here.
i have managed to install and test the rpi part but the ST part gives me errors and head pain… can you specify what should i copy and where to put it smartthings ide in order to work
if i create a new smartapp and paste the code brings me this error:
No signature of method: script14666906869141709109660.metadata() is applicable for argument types: (script14666906869141709109660$_run_closure1) values: [script14666906869141709109660$_run_closure1@78d8f0a4] Possible solutions: getMetadata(), getState(), setState(java.lang.Object), metaClass(groovy.lang.Closure)
my goal is to use raspberry pi’s cheap sensors(reed switch for doors and windows and 4 or 5 relays for lights) on STapp
actually i figure it out and works:)
my coding does not help… i need only i tile as the main switch can you point me to extract it from your code please?
This is a bit different as it’s truly a trigger rather than constant feedback from a sensor back to ST. That would be very different.
Ultimately, create a new Device Handler from code and paste in my code, save/pubish. Then go under My Devices, create a new one with same name/desc then use some unique garbage device ID as I change it anyway in code. The key is to choose the NEW Device Handler. That will be at the BOTTOM of the list. Then in ST app on your SmartPhone, give it the proper IP in settings and it’s set to go and will trigger the pin defined in settings (for RPI, does not work for ESP8266) and now it will send a LOW which in output mode for GPIO means send the positive signal while HIGH means negative/ground.
Beyond that it’s really hacking my code to fit your needs.
New code on GitHub. Details below… I obviously have stability issues with the NodeMCU so I’m forcing a reboot every 8 hours and have tested that for quite a while now with consistent success. I will update the wiring diagrams to include the DHT11/DHT22 temperature & humidity sensor but for now the code support it.
v1.0.20160719 - NodeMCU enhancements: forcing reboot every 8 hours to guarantee device being up. Also added simple variable to control whether using 5v or 3.3v relays & whether logic sends a HIGH or a LOW depending on that variable. Added temperature & humidity support for DHT11, DHT22 & DHT21.
Added sample code for Arduino Nano v3 where it uses the ENC28J60 Ethernet Shield to do the relay-only functionality considering that the Arduino Nano has so little memory when comparing to a NodeMCU. Reason for choosing wired connection was for reliability especially when couple with Ethernet over Powerline adapter. New wiring/Fritzing diagrams also uploaded:
I’m trying this out and so far so good, but I have one issue on an RPI2. I get {java.lang.NullPointerException @ line 314 } in the live logging and no data appears on the android app.
any ideas on what or where I went wrong, the web app works ok?
Few things that can go wrong… try changing the POST/GET methods, etc. Lastly, make sure that you don’t have a duplicate IP (device address) for some other device.
When I look at line 314 is where I take the date variable and store it in the JSON array. Try putting some lame string in line 314 or just comment it out… very weird as this works great on RPI 1st gen and RPI3 for me.
I did comment out line 314 and the previous jsonlist.put statement and it all worked - especially if I set to use JSON instead of HTML - using the latter it fails, but it working so I’m happy
Agree it was odd but being as JSON had the date I didn’t see that as an issue.
Thanks for the response on this - I was going crazy till I went thru the debugging and commented it out and your confirmation helps out!
Sadly it doesn’t matter that the RPI/PHP code shows you the time/date and even the JSON because I don’t use it I cheat and just use Groovy/SmartThings to give me time & date just so I don’t have to parse what RPI/Arduino returns… easier to let ST do its job. Here’s the line you commented out. Notice that I just use the built-in Java function Date() but I do try to offset the time based on location/timezone:
jsonlist.put ("Date", new Date().format("yyyy-MM-dd h:mm:ss a", location.timeZone))
Pretty strange that I haven’t heard from anyone else about this failing and it certainly works for me make sure that your time/date and timezone are properly set on the ST hub. Try something simpler like “new Date()” rather than the offset/formatted value I use.
Finally got around to getting this setup and it works great! Question I have (pardon my ignorance of if this has already been answered) how can I tie this switch into a open/close sensor. For example, how can I have the switch turn on/off momentarily as part of a routine only if the sensor is open.
The simplest one is the one offered by Samsung/ST — called Smart Lighting… go to your SmartApps and just install it.
The old favorite was Rule Machine but the developer of it killed the project and now we have CoRE — comminity’s own rule engine. It’s SUPER-NICE for advanced rules — but for your miniscule requirement of sensor then switch — Smart Lighting should do the trick and I’d highly recommend it given that Samsung fully supports it.
Totally agree that what I’m trying to do isn’t advanced by any means and you would think there would be a way to do this built into ‘routines’. I think I accomplished what I wanted with smart lighting and using routines to switch to custom modes based on open/close sensor. Still needs some tuning and testing
Can we use this to run a python script on a Pi? I have a cat feeder that has 2 servos connected to the pins on the Pi, with a python script that runs to operate the servos and feed the cats. the problem, though, is its not a simple high/low signal from the pin, we have to use PWM to control the servo. The other HTTP interfaces ive found just turn the pin to high or low, which works awesome for my relays, but not for the servos. Can i use it to run a script? For example, its here:
/var/www/html/scripts/feeder.py
the feeder.py is the script that runs the servos, but i cant figure out how to run that script via smartthings. I have a small webpage built with some PHP code, and from that you can click on/touch a button that runs the code (so i can do it from my phone), but i would love to be able to run the same script from a virtual button in smartthings.
Yes, in fact, initially the sample that I was working with for the Pi used python. However, I replaced it with GPIO commands just to MANAGE less code files. So if you were to grab the GitHub index.php and simply search for where I run gpio shell commands and replace it with your python command but the FULL COMMAND not just python file name /var/www/html/scripts/some.py — I believe full would be “python /var/www/html/scripts/some.py” You can replace that with ANY linux command supported on that Pi OS. Enjoy!
thats awesome. ill work on that in a little bit. follow up question, can i create a virtual button that presses that button so i can schedule it through smartthings?
Of course, extend as you please. Keep in mind that you have the POLL and REFRESH functions where you leave their name alone but change the logic to do whatever you want. Then use a SmartApp called Pollster to run that Poll or Refresh every X.
Hey Folks. I’m attempting to use this setup with the 8266. I have the 8266 all setup correctly and can function the IO ports on that module without any issue using the webpage. I seem to be having problems with the device handler. The requests are coming into the webpage as I see them in the serial monitor but it doesnt seem to be posting the correct relay1=on / relay1=off in the request. If I hardcode the RELAY1=ON in the additional URL info, it will turn that pin on but will not turn it off (obviously).
My expertise in device handlers is probably pretty evident. Anyone able to give me any insight on what I’m missing or some direction?
Monitor SmartThings IDE > Logs and filter for your HTTP device. You can see full URL of what is being attempted via the HTTP device handler.
Verify that you try a different HTTP method GET vs. POST… my default is POST for RaspberryPi/PHP while the Arduino/ESP8266 implementation is coded for a GET.