Set global by its name in args

Hi,
I don’t know if I m at the right place but I would like to propose a feature in webcore. I use url features with args to update some variable, global or local… and if you have multiple variable to manage that way, you need a block of code for each one like:
If args.temp is not empty then set @temp = args.temp
But it would be nice to be able to match args with the variable name…so with one block we could update any variable with 2 args (one for variable name and other for value)
If args.name is not empty then set @args.name = args.value

It could be a function in the drop down menu when editing the piston or something… so it could check for matching variable name and if no match do nothing or just built the block with some checkup…

At least a variable list to compare or something?

Thanks!

1 Like

Just to specify that by propose I meant request.. :blush: but pretty sure it would be not to complicated to add in the webcore code… if someone know who manage the webcore update in Hubitat it would be nice to make him know about it or redirect me to the right place to ask…
I think andy is not on it anymore so not sure if it’s still updated…

I need to test it more, but I have prototyped a function

setVariable(name, value)

This operates within a piston (ie it only sees variables that piston can see - local, global or hub)

Will post a note when a user install of webCoRE can get it (HPM repair).

Wow! Sounds good!
I ll wait for it!
Thanks!

Thought there was already a setVarible prototype to set the variable’s value…

Yes but you cannot select the variable you want to set by comparing with the value of another one…

I would like to use variable value (args) as the name of the variable I want to update.

Just saying that setVariable may already be used, may need to be setVariableName

if you have a user install you can try this out

hpm repair on webCoRE

I have the built in install… I could reinstall it but not sure what to do to install your things… do you have any information on that? The function should be added to code somewhere…? Thanks!

I would wait for it to push to the built-in version

1 Like

and to be sur it does the right thing, as in your print screen, could I make it like that:
variable (btest = aint) so
set variable {btest.value} = any value
would set the variable aint to the desired value ? Or if I could do an expression like: {setVariable(btest.value,10)} so the expression itself would set aint =10 ?
Thanks again, and how long it could take for the changes to be on the built in version?

you have to use the function to change a value.

there is no indirection of using btest it is its own variable in my example.

You can use a variable as the function argument for the name

thanks! and how long it could take for the changes to reach the built in version?

Likely few days, depends on firmware general release.

thanks, I have a last question, when I select the 'set variable' option, I m forced to select the variable to update so with your function, how would it works ? Is there a new menu or something to be able to use expression in the variable menu section?


Thanks again!

where you see value, there is the option to choose expression (which is what my test program does)

yes, I corect it I meant Variable (the menu where the check mark is) but if as you said your program allow to use expression in this menu...its exactly what I need I think! :slight_smile: Cant wait to see if it ll works as expected!
Thanks again for your work, I think a lot of users was waiting for it!

Hi, The update is done and it seems to work, I only have a question on how to use it. I mean, would it be more simple if the "variable" menu get the expression to choose and set the variable with your formula? Because we are forced to choose a variable to update and then in the other menu with the expression we use the formula... As I said it works well but its hard to follow visually (it said update variable X and actually with the formula it gonna be any others...)

Thanks for your works again! It works well and will save me a lot of code line!

You have to use some form where you can have an expression...as that is how functions are called in webcore

Yes, that works well as the variable specified in the first step still unchanged and the one called in the expression in the next step is updated! I not a dev so not aware of those restriction in code...Well its a little workaround but working so thanks again! That was one of the things that was needed in webcore to be efficient! :slight_smile: