Switch to execute HTTPPost

I’m looking to have a switch in my house execute an HTTP Post command when the switch is turned on or off. I have searched through a lot of threads and not found what i was hoping for.

Basically i have the backend automation done. The HTTP server handles what it needs to, but i’m looking to have smartthings be the Physical to Virtual interface.

So if i need to send a post to http://localhost:8080/toggle -on ’ ’ when the switch turns on and http://localhost:8080/toggle -off ’ ’ how would i do this? Ideally these would be CURL but i think JSON or regular POST would work.

My SmartApp Send Events to EventGhost does almost that - events in ST (switches, buttons, or several other things) are turned into HTTP GETs sent to a local web server via HTTP. The target server is a configuration item, but the format of the actual URL isn’t. If you need to customize the actual command issued you may need to modify the code. Still, it should be a useful starting point for you.

edit: to clarify a bit, when you deploy the SmartApp it will ask for a host, a port, a prefix, and then allows you to select one or more ST devices. If the host is “”, port is “8080”, prefix is “ST”, and you’ve selected a device called “TestSwitchDevice”, the SmartApp will issue the following HTTP GET request when TestSwitchDevice is turned On:


Why not just make a custom device handler for this and add HTTP Get statements for on and off. I did something similar for the Particle Photon blinds.

You can look out on github. The original branch is the one to look at. The device handler should point you in the right direction.

1 Like

Here is the link to the httpPost documentation: http://docs.smartthings.com/en/latest/ref-docs/device-handler-ref.html?highlight=httppost

jjhtpc project is a good example. I used it as my starting point for my particle photon project. The following was called within a function to execute a post.

httpPost( uri: "https://api.spark.io/v1/devices/${deviceId}/setCmd", body: [access_token: token, command: msg], ) {response -> log.debug (response.data)}