Raspberry Pi with PHP (or Arduino/ESP8266/NodeMCU) to GPIO to Relay to Gate/Garage Trigger

Hi @TheTick077 I’m glad you’re appreciating my pet project. Of course you had to ask questions that I can totally ramble on about :slight_smile: so here’s the most concise version not to bore everyone…

  1. Zero reasons… honestly, just space concerns in a little project box where the rigid cable had to have a hole drilled for it while direct 5V connection did not. For my IR Remote project & box I actually did use the built in port. Just an FYI, on 1-2 of my many D1 Mini & NodeMCU modules, the port kinda broke with power but still worked with data/programming — so I had to have both plugged in, micro USB and VCC/GND in order to program those slightly broken modules.

  2. Unlikely that I’ll take this on. The project is really meant to be relay only. Out of my own needs/desires I grew the project. While I totally want myself what you’re asking for (motion detector) it’s just way more than I want this to be. Personally I love Z-wave motion detectors and with the price on sale at $15-25 for a WAY MORE sophisticated motion sensor, I’d rather buy a pre-made component like I’ve done. My hallway and office all turn on with motion (advanced rules using CoRE project — awesome rule engine!), so I’m a fan of the feature just don’t want to duplicate something that’s way better than I’ll be able to offer. Lastly, because my situation doesn’t even know whether the light is on or off, doing motion and not knowing the state of my button has no point. I’m more interested in adding a light sensor to my project :slight_smile: It’d certainly make it more complete for my needs and now makes your suggestion very realistic for the scope & abilities of the project. However, that’s not where it is at the moment.

  3. Originally I had a very similar Z-wave relay in my gate until I realized one super-important thing — I was using 110V hot line in order to short my (thankfully DC circuit) gate for opening. Way too stupid and I ripped it out when I realized that. So the lesson about those switches/relays (I have about 3 dual channel ones in the house) is the fact that it’s NOT just a short/contact relay functions. It’s made specifically for home wiring and the wire that’s enabled when the relay turns on is the hot wire not a separate circuit like relays typically use/have. Just keep that in mind before doing something like this given my point. I now exclusively use these behind light switches once I realized the errors of my ways.

  4. Depends on your unit. My LiftMaster simply didn’t have a few wires that I can short for opening/closing so I had to opt for ANYTHING that would. It could have been a wireless controller or my wall button like you see but I had to find something to trigger and landed on splicing behind my button as the most reasonable option. If your motor has 2 contacts for you to short then you’re way better off using it rather than my hack/soldering method. Having said that, it’s a relay that causes a short so you just need to find something to short and give you expected results :slight_smile: believe me I’d rather have dedicated circuit for my garage (like my gate has) but I don’t — so gotta do what I gotta do. It’s been working for 2 years (RPi 3 in garage & NodeMCU in garage) and I’m very happy with the consistency and flexibility of the solution.

Lastly, and another reason why I used 5V lines rather than the micro USB cable is the other project that I have. See the first post and search of IR or remote… My TV is controlled by ST as well (mostly for volume, on/off & input control) and using 3 high output IR LED’s was the motivation for using the 5V direct line. Definitely have a look at that project as well for the learning aspect that you mentioned. Enjoy and feel free to post your final project/box. I’m the only one sharing pictures so far, others are obviously shy :slight_smile: but I’d love to see them and get ideas.

Thanks for the prompt response! On #2 with the motion detector, I wasn’t asking if you would do it for me, I was asking if it was technically possible. I am a software developer by trade, so can probably figure it out once I get accustomed to the platform, but just wanted to make sure I wouldn’t be wasting my time digging through things.

Right now I just have a simple motion detector turn on the lights in the garage when we walk out there, but if I could use the same small device mounted up on my motor and pointed toward the door, it would free up my “quality” motion detector to be used other places. If not, no big deal at all, just thought it would be a good simple way to dip my toe in the SmartThings development.

I see… Then the answer is an absolute yes. You simply want to use the Motion Sensor “capability”. IMO the shortest way to get there is to alter my contact sensor logic and simply change to motion. Reason why I say that is because the tile and its changing states are there and ready for slight alteration.

Perfect answer! Thanks! Now to order my supplies, and wait on the boat from China :slight_smile: .

Get a few from different vendors. Trust me, they’re not the toughest of builds and you’ll just kick yourself for having to wait again for a month :slight_smile: don’t forget to look at WeMos D1 Mini clones. They’re even smaller than the NodeMCU.

Does anybody use Node Red for their set up? I’ve been playing/learning for the last 2 days and I’m extremely impressed. For folks that care, I can share some samples of how to parse my HTTP/JSON in order to consume the info via Node Red. My next enhancement is likely going to be MQTT thus allowing me to take Node Red to the next level.

New version on GitHub. Here are some of the much needed enhancements because ST state changes are getting slower and slower. Therefore I had to change my virtual app sync and DH code to work with EPOCH time better. My garage light (custom/secondary switch which is momentary) at times would turn the light on then 5 seconds later back off, or vice versa. This prompted me to fix the underlying issue. I also added ability to PHP to accept a GET with ?UseJSON= in the URL and it will indeed return JSON for Node RED or any other JSON parser consumption. I have not yet implemented any MQTT on the Arduino/ESP8266 platforms.

v1.0.20170826 - Updated PHP, Generic HTTP Device & Virtual Sync App code. PHP was for better ability to interface with Node RED. Groovy code was updated for better synchronization between secondary switch & virtual switch.

Hello all,
Great thread i am reading it thoroughly and i am on post 154 of 327 so almost half way :slight_smile:
but i couldn’t resist to ask my question and explain what i am trying to do.
I have a raspberry pi 3 connected to a 8 relay board and i am trying to use exactly 5 relays out of it.
2 are to be connected as momentary on / off for the 2 garage doors 2 others are also monetary on / off connected to a remote control key fob that locks and unlocks my door and the fifth will be to the remote start of a car :slight_smile: (for future use).
I have no need for any temperature sensors etc, Although i have the garage wired with floor contact sensor for door status that i can use with this GPIO pins if i know how, i can also use two spare contact sensors that came with my SmartThings kit.
I have no experience when it comes to coding however i can try, i am tech savy and i am a great step by step follower.
My question is how can i achieve what i am trying to do (turn on and off 5 relays connected to my Rpi3 GPIO) using your code??
I am going to continue reading the thread further but any input from @JZst and all of you guys will be greatly appreciated.
thank you
Denis

Make your life easier and settle on 2 or 3 NodeMCU boards or D1 Mini. While I like RPi, my code simply does not have support for 5 switches/buttons. I only support 2… You can definitely extend but there are no instructions on doing so.

If you wanted to enable all 5 at the same time, that might be possible but actually embedding 5 different switches and states are out of scope unless I was doing a sprinkler system :slight_smile:

You can always mess with adding 2-3 devices in SmartThings that point to the same IP and simply mess with the pin number on each device inside of the ST App. This is another clever workaround for your desires. However, SmartThings will trip out if/when it detects a device ID that’s the same ---- which in your case it would be the same IP. Having said that, after each execution I do set the ID to a random number to prevent this collision but sometimes when stuff crashes, etc. that override wont happen. The fix is simple though just go to My Devices and change the ID to garbage.

Good luck!

Hopefully somebody can answer the below…

For the past week, I’ve been running a hacked Eco Plug/WiOn switch and a hacked Sonoff with my ESP8266/NodeMCU firmware. All lights and buttons work well, etc. and happy with results. This is done with SmartThings MQTT Bridge. Before I settle on defaults, would love the below answered.

  1. Should I enable MQTT by default or leave disabled for user to configure?
  2. That’s important because MQTT retries every 5 seconds which means device heat and power consumption, etc. Should I stop the MQTT retry after X failure?

When I have some suggestions and a bit of time this/next weekend, I’ll release the code.

My biggest motivation for MQTT is Home Assistant (amazing!) and unfortunately nice firmware like Tasmota for the Sonoff was too much to configure (and didn’t handle the nicer Eco Plug) for the SmartThings MQTT Bridge which expects MQTT messages to look very specifically. Also my firmware is simple and in a single script & I wanted more options available like awesomely built hackable devices.

Thanks!

It’s pretty quiet in here… I’ll leave the public version of the code alone for now as the interest seems to have diminished while keeping up with the project is pretty time consuming. MQTT works very well and integrates wonderfully with ST & Home Assistant using ST MQTT Bridge. If I see a comment or community desire, I may post the code.

I may start a new thread with a script/instructions of how to install all components like Mosquitto, ST MQTT Bridge and Home Assistant along with a few config samples.

Thanks a lot for your work, I have a very simple requirement which i’m unable to do,

I’d like to simply create a tile that wheni click it would run a bash command on my RBP, i was able to connect to my RBP via your ST smartapp but then how to assign the custom tile with running a command in bash?

Well have a look at the main trigger and the other tiles then search for that name throughout the code. The best example is the refresh button or the main trigger. All you have to do is copy that logic with a unique name. I would highly recommend just re-using one of my buttons/tiles to do what you’re trying to do instead of a new tile… unless you feel like learning how to program ST Groovy code and tile states, etc.

Im sorry but can you guide me a little bit more? Which file exactly to edit? I tried looking into the device handler code and i tried searching for a sample that uses a command that’s actually usable by the system such as uptime and all the uptime words in that code are written upTime <- no such command so i didnt know how its done…

Honestly that’s a limitless topic and out of scope for me offering a pre-made example. For customizing/coding there are separate areas on this and other forums for that level of assistance. Here’s the only item I can easily suggest… look for the exec() function in the PHP and change those shell commands to whatever you want.

I got some more for you…

Look at the REBOOT logic and tile. It’s the most perfect example of what you’re describing.

In the ST Groovy code, don’t forget to correctly name your tile and assign it to a proper “action” aka function down below. Make sure to list the new “command” aka “action” at the top of the Groovy file or it will not run.

Good luck!

Thank you so much!!! I got it all sorted out :))

New release:

  • v1.0.20171008 - Added MQTT & hosting JSON status page. New support Eco Plugs/WiOn switches (by KAB) & SonOff devices. Easy ability to integrate with Home Assistant. Cleaner UI after hiding settings.

Eco Plugs / WiOn wiring: http://thegreatgeekery.blogspot.com/2016/02/ecoplug-wifi-switch-hacking.html
Sonoff wiring: http://randomnerdtutorials.com/reprogram-sonoff-smart-switch-with-web-server/

Another update. Had more issues with DHT like some folks experienced (failed readings) and optimized my re-try logic as safe and reasonable as possible. No longer assuming that main switch momentary means the OFF voice command is for the secondary/custom switch. Had issues with MQTT and re-sending of last state, etc. Best thing to do for voice command of the second switch is to set up my SmartApp which sync’s to the virtual Device Handler.

Release notes:

  • v1.0.20171030 - Modified DHT retry logic in Arduino code. Modified main Groovy code & Virtual Sync SmartApp to stop assuming that momentary main means that Alexa should use the OFF command for custom/secondary trigger. This caused issues with SmartThings MQTT Bridge as the OFF command, sticking to explicit settings.

Hi, Massive delay but i’ve shorted gpio 24 pin to gnd and also altered the index.php to have true as follows:

$contact_sensor=true;
$contact_sensor_2=true;
$sensor_pin=24;
$sensor_pin_2=25;

but the sensor pin status doesnt change from showing open whether 24 is shorted to gnd or open

Any tips to try?

Also will this allow, or is it possible for me to say open and close to alexa rather than turn on or turn off garage door?

thanks again!!