Piston example for http trigger for ST switch on/off


#1

1) Give a description of the problem
Is there an example of a piston that uses an http get/post request to trigger a switch On or Off

2) What is the expected behavior?
I’m trying to setup some external triggers on my home network via Node-Red and hoping there’s a simple setup I can use to fire off an http request with a param to turn on or off a switch or other similar device.

3) What is happening/not happening?

Been looking thru the wiki but not found an example that would lay out what I’m trying to achieve.

Thanks in advance.


#2

A new piston can simply toggle the light when it runs. Make sure there are no triggers in that piston, so you will see this once it is saved:

You can then copy the URL at the top of the page:

temp

and call that URL any way you want. (http GET, web browser, text click etc)


#3

An advanced version of this can actually send arguments (such as light=on) added to the end of the URL like this:

https://api.smartthings.com/api/token/123abc/smartapps/installations/456def/execute/:789ghi:?light=on

but if you only want a toggle, that simplifies the code greatly


#4

Here is a snippet of the pertinent code I use in one of my pistons that reacts differently based on which argument comes in at the time:

Untitled-1

That top line basically disables that block UNLESS there is an argument attached.
(meaning the Test button will not work)


#5

Many thanks. I’ll give that advanced one a try as the params for light=on etc is exactly what I’m after. I think I have the basic one now working but I could only get it going with a URL/piston for on and one for off.

Much more efficient to have one piston accepting params for on or off :slight_smile:

Cheers.


#6

Glad to help.

Just for clarification, even the advanced method above is based on my first post.
(Make sure there are no triggers in that piston, and you see this once it is saved)