SmartThings Community

WebCoRE piston help Setting Variable


#1

How do I capture volume level then restore that level?


(Robin) #2

Click on the x2 button at the top of the scrip edditor page. You will then see the ‘define’ section appear at the top of the script.

Within the define section you can define a variable. Make it an integer variable, give it a name and leave the value blank.

Then within the main part of the piston, create the action ‘set variable’ and choose the variable you just created. For the value, choose ‘expression’ and type [device name : volume]. When this part of the piston runs the volume value will be stored in the variable.

To restore the value, create an action to set the volume, and choose ‘expression’ for the value section. Then type the variable name.


#3

Thanks for the response. I have been poking around to try and figure a few things out. I changed the variable to an integer and made it local. as you suggested I’m setting the variable to {volume} = speakers Level;
Setting level gets me nothing but I found that the Samsung R1’s prefer tileset which works to set levels. I seem to have it working but it’s resetting the volume to 15. I don’t have an initial value set. Any idea where it is pulling that level from?


(Keaton Hoskins) #4

I am so sorry to dredge up this old thread, but I still am not understanding how to get this variable stuff configured. I have a “device” variable set in the define section. See what I have here, I don’t believe I am using the functions correctly.

I have tried clicking on the “if” in the “then” section and set it like this:

I am just not sure how to get this x^2 set variable string, as mine doesn’t look like that. If you want the whole script I can export it with the snapshot I think, right?


(Robin) #5

To get the x2 line, that would be an action. Pick ‘set variable’ in the same way as you would pick ‘turn on’

But if your piston is setting / changing the device variable, don’t set the starting device at the top as it will reset to that device on every run, instead choose ‘not selected’ when defining the variable at the top.