Multiple external URLs for one piston?


#1

Is it possible to have multiple external URLs as triggers for one piston?
Example: If ‘URL A’ is called then do ‘Action A’, else if ‘URL B’ is called then do ‘Action B’.

Or, is there a way to pass variables to a piston when calling the URL?
(api.smartthings.com/api/randomstuff?Trigger_A)

Or do I need a separate piston for each external trigger?


#2

One URL with arguments at the end should do it.

For example:
https://api.smartthings.com/api/token/123abc/smartapps/installations/456def/execute/:789abc:?PcLocked=false
and
https://api.smartthings.com/api/token/123abc/smartapps/installations/456def/execute/:789abc:?PcLocked=true
both trigger the same piston.

You can then add code something like this:

temp


Edit in 2020:

You could also work directly with the $args, such as:

Set variable {string} to $args.PcLocked
… or
Log to console = "PC Locked = "$args.PcLocked" at "$time

Note these two examples are using the Expression box, with $args and variables outside of quotes.


Pro Tip:

Do all your $arg stuff near the top, because if too much time passes, they vanish forever…


Populate variables using external data?
How to Read a Piston Variable From Piston URL
Finding entry in list or collection to select one of multiple devices to control
Trouble activating a piston on a different hub
Siri Shortcuts not POSTing variable to piston
#3

This is exactly what I need. Thank you for the help!


#4

In general, you want to make sure there are no triggers in that piston.
(the URL call will be the trigger)


#5

So, just working through this out loud to make sure I understand-
If I need a piston to be triggered from multiple sources (i.e. at Sunset, or on contact open, or on external URL call), then I should have a separate piston just as the external URL trigger that then changes a global variable or something similar that another piston can use as a trigger?


#6

Well, there are many ways to do things here in webCoRE.

The general rule of thumb that I follow is, any piston that I plan on calling from various other means, I usually keep triggers out entirely. When I save it, it shows this up top:

I may make that piston quite complex, but each IF block is used as conditions though, not triggers.

My logic is, if you have any triggers in your code, the entire piston will run top to bottom each time that device does something. So, if you decide to use triggers, just keep that in mind, because you will have to code accordingly.