Hubitat deletes global variables

I have 2 rules in Rule Machine, one that turns my lights red when one of the doors stays open for 30 secs and one to switch them back when all doors are closed again. I use global variables to save light colors and levels before I switch them to red in the first rule so I know what to switch them back to in the second rule. Problem is, for some strange reason the first rule runs fine, but it deletes the global variables for color, so once the second rule runs, I get a Null pointer exception because the variable doesn't exist anymore. Both rules seem to keep running, but the second one obv doesn't work because the color variables do not exist anymore.

Any idea as to why this is happening?

Edit: all variables are Number btw and I use the device attribute light.color

The only way to delete a Global Variable is from the UI.

Is this behavior of a GV being deleted repeatable?

I know that Rule string variables set to "null" don't show up on the normal variable listing in the Rule, although they're still there, and can be set or deleted normally.

Ah, that's interesting. That should be fixed.

This is not true. A Global Variable with an empty string still is displayed:

And, setting it to "null" is also displayed:

exactly, but they definitely get deleted within rule execution, not the UI. I have both rules paused now and the variables stay. As soon as the first one executes, the variables, only the ones for color, are gone and I get NullPointerExceptions when the second one executes and tries to read them. If I were to manually create and set the variables in between rules it would work, but that's obviously no solution.

Edit: this is repeatable and not a freak coincidence. I also recreated the rules and even removed the whole Rule Machine, but to no avail.

Not an RM GV, but a Local Variable in a Rule. I was setting the LV to a value that wasn't being passed in a HubConnect device, and the LV didn't show up. [shrug]

Please show the rule. Also, please show the logs where it throws the error.

Please show the rule.

Please show exactly what you are talking about, and I am not able to reproduce this behavior.

Rule has been erased, and I'm out the door to an Xmas party, but I'll try to reproduce it tomorrow.

How do you create an empty string variable? The documentation states you have to initialize it and the UI requires a value. I have tried various things but can't seem to figure it out. If I put in null does that represent a null value or the string 'null'?

How do you set a value to null or empty string within a rule? I have been creating the variable with a space in the name and then removing the space within the rule.

I'm sure the answer is obvious but it alludes me.

You cannot have a null variable in RM. It won't like it. Why do you have to set a variable to empty? You won't be able to compare it to anything or use it in any way until it is set to something. You can't compare null to anything, you'll get an exception error.

Because I was building a list and want to be able to set it to null or an empty string. I can get around it but it would be easier if I could set an empty string. The following works:

Edit: vTest was initialized with a space. It can be whatever you want.

Remove ' ' from vTest
IF (Variable vTest() *is empty*  (T) [TRUE]) THEN
	Toggle: Cabinet Light

This also works

IF (Variable vTest() is empty (T) [TRUE]) THEN
Toggle: Cabinet Light
Set vTest to 'Remove me'
Remove '%vTest%' from vTest

Well, have you tried just not putting a string in for set the variable to a string? I'm still not clear on why you would do that. Showing me part of a rule doesn't show me what you're trying to do from a bigger picture. It shows me how you're trying to do it. Rather than asking "Make this work for me" why not try asking "How can I accomplish this". You might get a lot more answers.

The question is how can I set an empty string, that is the question. I don't need help with the rule

Yep. I've tried setting it to "", '', just a space, %null%, null, etc

You can check a string to see if it's empty.

The rule I was working on would check if some contacts are open if TRUE then add them to a variable. If nothing gets added, empty string, then do 1 thing if the string isn't empty then do something else. I'm actually doing this now I just have to make the variable empty after I create it.

Remove a string from itself.



1 Like

Thanks. This is what I've been doing

Remove '%vTest%' from vTest

I didn't know if there was another way