Execute a piston with arguments - Solved


#1

I am attempting to execute a piston and pass to it a local variable from within a parent piston. The idea is to set up an alert piston that I can call on and send commands without writing out the same commands multiple times in multiple places. Pretty standard practice is normal programming languages. My problem however is that I cannot find a way to actually use this passed information from within the second piston. There is no documentation or other forums that I can find which explain this in detail. I have tried several things and my code just spits out errors about .js issues. Any help on this would be appreciated.


#2

Apparently I can only post a single image as a new user so the above is the piston I am trying to execute. The parent piston simply calls to execute this piston with a string variable as an argument. Pretty basic.


#3

RunTime Analysis CS > 29ms > PS > 75ms > PE > 92ms > CE
+205ms ║Runtime (35398 bytes) successfully initialized in 75ms (v0.2.0e7.20170906) (203ms)
+206ms ║╔Execution stage started
+216ms ║║Cancelling statement #1’s schedules…
+279ms ║║Executed physical command [Family Room].playTrackAndResume([http://www.freesfx.co.uk/rx2/mp3s/5/16913_1461333028.mp3, 50]) (52ms)
+280ms ║║Executed [Family Room].playTrackAndResume (54ms)
+286ms ║║Executed virtual command [Family Room].wait (1ms)
+286ms ║║Waiting for 3000ms
+3298ms ║║An error occurred while executing the event: groovy.lang.MissingMethodException: No signature of method: script15048043279881338264056.getJsonData() is applicable for argument types: (java.util.LinkedHashMap, java.util.HashMap, java.lang.String) values: [[enabled:true, attributes:[acceleration:[…], …], …], …] Possible solutions: getMetadata()
+3312ms ║╚Execution stage complete. (3105ms)


#4

This is one of my pistons that accepts textMessage from another piston.

Edit: This is a clip of what it looks like on the other piston… (it’s not calling the one in the example but it works the same way)
Capture


#5

Arguments can more easily be used by selecting Argument from the dropdown rather than Expression:

13 PM

It looks like you are using {$args.message} as an expression. This should work if you remove the {} braces which are generally used in the Value input rather than Expression. The expression $args.message would be equivalent to selecting the Argument and typing message.

You can learn more about expressions and values here on the wiki


#6

I was attempting to use the expression as a possible fix. Acts the same with the argument. Thanks though.


#7

Ohhh, did you happen to install or update webCoRE on the SmartThings developer site yesterday? There was a brief period of time where getJsonData() was broken. You should be able to fix this by updating webCoRE to the latest version at developer.smartthings.com


#8

:man_facepalming:


#9

Yeah… sorry about that, I lost a few hours yesterday trying to figure out why my pistons were erroring out trying to save updates (another place where the bug manifested). Did everything work for you after the update?


#10

Updating and testing now.


#11

Working like a charm now. I should really have thought to check that. Unfortunately, my first time taking advantage of the functionality, so I figured i must have had it wrong somewhere. Thanks for the help guys.


#12

I’m trying to do the same thing. But I want the child piston being called to then spit out a return value back to the parent piston. Much like how functions work in Python and other languages.

Anyone if this is possible?


#13

Return values are not possible yet but I badly want to implement them! Here is a workaround, certainly not as convenient but does allow for reusable logic with results pumped back to the caller.