String Variable re-assign

Here is an example of one RM rule where I need to assign one string variable with another:

For the numeric/decimal variables there is simple variable assignment function from
another variable. This does not exist for the string variables.
My work around is to set a string variable to something (XYZ in the above case) and
than use a replace string function. This is not a big deal but a bit annoying.
I wonder why simple "assign variable from another variable" does not exist?
Is it simply missing or for whatever reason is impossible?

1 Like

I agree with your request a direct string to string would be easier, and I have thought about, but just never got around to asking for the same feature

You can assign a string to another string with set string. Then for the text you put the sting you want to assign in side of % percent signs.

Set OldString to %NewString%. This is prone to error as you have to type the variable name correctly, including case. It would be nice to just be able select the new string name from a drop down list.

1 Like

For string variables you do it like this, using %var-name% reference. There was not a separate command really needed, since that is available for setting any variation of one string variable into another.

The resulting action, showing the two variables as well:

2 Likes

Thank you very much for the tip, Bruce.
This could be described somewhere in the docs (who reads docs these days?)
but was not obvious.
It does the job and RM code looks much cleaner.

1 Like

I still think this is a valid feature request. Today for instance I renamed a string hub variable. I have a rule where I set a local string to the renamed hub variable. If I could do as with a integer or decimal and set the value of one string variable to the value of another sting variable, the rule would not be effected.

Using the method above I need to remember to go to any rule that uses that variable and manually update the name.

1 Like

No, rename Hub Variable catches these variables in %variable-name% uses in a rule.

I just tested it and you're right it does. However, it did not on the rule I had the issue with. I think it was because it was a shared hub variable. I had never done that before and just assumed that it would be that way for all hub variables.. After making the change I thought of this thread and I thought it another reason to justify the feature request.

I still think it would make things easier to be able to select the variable name rather than having to type it out. Even in this simple test case I had to go back and look to make sure what I had named the test hub variable. I couldn't remember if I had capitalized the first letter or not.

1 Like

It is...from Rule 5.1 - Hubitat Documentation:

1 Like

In an upcoming release:

4 Likes