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

I think I’ve done basically everything on your list –

  1. Flashed as is except for SSID and Password
  2. Definitely on same subnet - both devices on same router — one wired and one wireless
  3. Added the DTH with no issues
  4. Created the new device, added thing, changed to get and assigned IP
  5. Changed to GET
  6. This is a sample of what shows up in logs of IDE:

a85caa4c-7699-4b72-807a-cdcc4f995a31 10:11:39 AM: debug GET /CustomTrigger= HTTP/1.1
Accept: /
User-Agent: Linux UPnP/1.0 SmartThings
HOST: 192.168.0.106:80
Content-Type: application/x-www-form-urlencoded

a85caa4c-7699-4b72-807a-cdcc4f995a31 10:11:39 AM: debug The method is GET
a85caa4c-7699-4b72-807a-cdcc4f995a31 10:11:39 AM: debug GET path is: /CustomTrigger=
a85caa4c-7699-4b72-807a-cdcc4f995a31 10:11:39 AM: debug Uses which method: GET
a85caa4c-7699-4b72-807a-cdcc4f995a31 10:11:39 AM: debug The Header is [HOST:192.168.0.106:80, Content-Type:application/x-www-form-urlencoded]
a85caa4c-7699-4b72-807a-cdcc4f995a31 10:11:39 AM: debug The device id configured is: C0A8006A:0050
a85caa4c-7699-4b72-807a-cdcc4f995a31 10:11:30 AM: debug GET /MainTrigger= HTTP/1.1
Accept: /
User-Agent: Linux UPnP/1.0 SmartThings
HOST: 192.168.0.106:80
Content-Type: application/x-www-form-urlencoded

a85caa4c-7699-4b72-807a-cdcc4f995a31 10:11:30 AM: debug The method is GET
a85caa4c-7699-4b72-807a-cdcc4f995a31 10:11:30 AM: debug GET path is: /MainTrigger=
a85caa4c-7699-4b72-807a-cdcc4f995a31 10:11:30 AM: debug Uses which method: GET
a85caa4c-7699-4b72-807a-cdcc4f995a31 10:11:30 AM: debug The Header is [HOST:192.168.0.106:80, Content-Type:application/x-www-form-urlencoded]
a85caa4c-7699-4b72-807a-cdcc4f995a31 10:11:30 AM: debug The device id configured is: C0A8006A:0050
a85caa4c-7699-4b72-807a-cdcc4f995a31 10:11:27 AM: debug Resetting tiles.
a85caa4c-7699-4b72-807a-cdcc4f995a31 10:11:06 AM: debug GET /MainTrigger= HTTP/1.1

Unless you see something glaring there, I can only assume it’s my actual device - though I can get to it from my browser and click buttons and the relay works. So it took the code with no problem

Extremely strange… nothing is standing out by any means. You’re using port 80 on your 106 address. The top of the log suggests that the call was attempted to the ESP8266 but it never returned anything. Let’s see a screenshot of the same IP via browser. Lastly, reboot the ST hub :slight_smile: we’ve all been there…

Hey @flyize it’s a bit impossible because it’s done in the metadata section of the device type handler where you can’t do too much dynamic/programmatic logic. Here is the line in case you want to change it to the DHT sensor:

Just change the main/top line to use the “temperature” tile instead and that will be your main button on the complete/room device list.

I like what you’re asking for but I believe it’s impossible AFAIK… hopefully somebody can prove me wrong :slight_smile:

1 Like

It used to be very possible… In the old ST v1.x series phone apps, you could select which tile you wanted to be the default/main tile. When ST “upgraded” the phone apps to v2.x, they lost this feature and never restored it.

the old code used to look like:

main([“DeviceTrigger”, “displayName”])

this would permit you to pick either of of those tiles as your main tile. I never understood why they lost that capability.

1 Like

How ridiculous and thanks for the history!

Sounds like everyone here should open up support case asking why this feature went away and give it a vote for coming back. I’m doing it… makes perfect sense in many use cases let alone sheer flexibility.

I’ve no idea where to do that, but I’d vote it up for sure.

Just open a support case by email asking for exactly what you want. The more cases that get opened for the same feature the more likely they are to implement it.

1 Like

JZst - can you give me the link of the actual board you are using? I can only assume there is an issue with this one. I will send a screenshot of the browser view and I will try rebooting the hub. Didn’t have a chance this weekend.
Thanks much!!

Well that’s one of the ones that gets thoroughly tested. The device is proper and I constantly flash the entire sample with zero changes other than the wifi info.

Turns out this actually doesn’t work because the first line of the tile is ‘Temp’, so that’s all it shows. Any other ideas for displaying temp in the Things list? Does it have to be a tile? Can I just use a variable, like device.temperature?

edit: I tried that, and as Im sure you already knew, it didn’t work.

At this point uncomment this line around 339:

//log.debug "BODY---" + bodyReturned

The goal is to see the output that the ESP returns. Paste the results from the ST logs.

Finally got it working! Turned out I had it plugged into an 8 port switch off my router, not the router itself. Changed the ethernet cable to the router and voila! All this time I thought a switch off the router was the same as the router itself. Learn something new everyday!!

Next to install it in the garage and try my presence rules.

Thank you so much for all your help and for this great utility!!

Now I realize you’re working with ethernet/wired — so guessing RPi rather than ESP. I really need to ask folks to clarify to alleviate confusion for all, specifically me :slight_smile:

Enjoy and glad to hear about the partial success. When you achieve full success, take a picture and let’s see who has the cleanest set up…

I’d love for folks to respond with their rig. I want to see if my little project box is the cleanest way or if there are better alternatives. For now, I like that rig (NodeMCU as shown in a pic on the 1st post) way better than my RPi 3 rig that lives in the gate box. Just due to size…

I should have clarified - I’m definitely using an ESP, but the ST hub was off the switch. The ESP is off the wireless router. I moved the hub to an ethernet port on the router itself rather than the switch and that’s what did it.

Thanks again for the assistance.

I have this set up and I can trigger it from the DTH from the ST app. I want to setup in CoRE to open door when presence is detected but I don’t see the individual switches as devices to control. I would think I need to assign a virtual switch to it but I can’t figure out how to do that.

This is what I see in the log when I trigger it:

a85caa4c-7699-4b72-807a-cdcc4f995a31 11:28:36 AM: debug whichTile: mainoff
a85caa4c-7699-4b72-807a-cdcc4f995a31 11:28:36 AM: debug [Date:2017-05-08 11:28:34 AM, MainTrigger:Success, UpTime:4 Days 07:41:42, Free Mem:35KB of 80KB, SensorPinStatus:Closed, Sensor2PinStatus:Closed, MainPinStatus:0, CustomPinStatus:0]
a85caa4c-7699-4b72-807a-cdcc4f995a31 11:28:32 AM: debug GET /MainTrigger= HTTP/1.1
Accept: /
User-Agent: Linux UPnP/1.0 SmartThings
HOST: 192.168.0.106:80
Content-Type: application/x-www-form-urlencoded

a85caa4c-7699-4b72-807a-cdcc4f995a31 11:28:32 AM: debug The method is GET
a85caa4c-7699-4b72-807a-cdcc4f995a31 11:28:32 AM: debug GET path is: /MainTrigger=
a85caa4c-7699-4b72-807a-cdcc4f995a31 11:28:32 AM: debug Uses which method: GET
a85caa4c-7699-4b72-807a-cdcc4f995a31 11:28:32 AM: debug The Header is [HOST:192.168.0.106:80, Content-Type:application/x-www-form-urlencoded]
a85caa4c-7699-4b72-807a-cdcc4f995a31 11:28:32 AM: debug The device id configured is: C0A8006A:0050

Any reason you can think of why this doesn’t seem to be reporting back to WebCoRE when the contact switch is closed?

edit: Actually it doesn’t seem to be reporting either state in a timely manner. Could I have done something wrong?

No you haven’t — remember my device & functionality is a PULL approach where you must query/refresh/poll the device every so often in order to get the CURRENT status.

So, this is one of the reasons why I added the REFRESH capability to my SmartApp logic. Which I’ll elaborate in the next response — and it’s time to add it to the OP.

@ctdodge the SmartApp is what you need along with one/both of the device handlers to achieve what you’re looking for. I should also update the original post with this info.

On GitHub you will find the main Groovy for the Generic HTTP Device Handler. Which this project was based on until multiple switches and sensors were added. However, SmartThings allows for a “primary” switch to exist for any/all automation. That means Custom/2nd switch and the 2nd Contact Sensor CANNOT be automated. In order to achieve automation you must create a VIRTUAL switch which sync’s up with the secondary functions/switches/sensors of the Generic HTTP Handler.

I’ll likely use the below in my original post. Please let me know if it’s easy & accurate enough…

For automation of secondary switch & sensor for Smart Lighting or CoRE.

  1. In the SmartThings IDE site, create a Device Type in the SmartThings API website. Use the one or both of the VIRTUAL devices from GitHub depending on your need.
  2. Create a new SmartApp using the code from GitHub. It’s called VirtualCustomSwitchSyncApp.groovy and after creating the SmartApp
  3. Add the new SmartApp via the ST mobile app with the correct Generic HTTP Device (parent) and optionally pick either the 2nd switch or the 2nd contact sensor which was set up in step #1. Those newly linked virtual devices will now be updated as soon as the parent HTTP device is updated and can trigger the 2nd switch as well.
  4. The SmartApp has 3 features. Sync the 2nd/Custom switch from the Generic HTTP Device. Sync the 2nd Contact Sensor from the parent HTTP device. Lastly, refreshes/polls the device every X minutes because this device will only be updated on a PULL basis hence the need to refresh for CURRENT status. Don’t overly often refresh please for your own sanity. Do it every few minutes, try to stay away from every 1 minute unless you really have to.

Ahhh, I can create a piston to refresh it then, unless you have any better ideas.

Yes you can definitely use CoRE. However, in my SmartApp all 3 fields are optional. So you can use/install it just for refreshing purposes and not link 2nd switch nor the 2nd contact sensor.

My recommendation would be to have one SmartApp per Generic HTTP Device installed especially if/when 2nd switch or sensor is used. Let alone the important refresh reason.