Possible RM bug (or I'm doing something wrong)

I ran into a bug (or else I'm not correct in what I want an action to do). I had a rule to control some lights and it used a rule function to generate a variable interval (an integer value) and then needed to decrement that variable as it looped. I used the set variable action to "add number", specifying -1 to decrement. This would generate an invalid number. Here is a very simplified rule (just what is needed to demonstrate the issue):

image

and here is the Rule Function it calls:

image

If I run the actions for the initial rule, it will put the result of the Rule Function call into the variable (say "1"), then when it attempts to add -1 to it, it becomes "1-1" (not 0 as would be expected when adding -1 to 1) which is not a valid number (the variable is defined as type "Number" and the Rule Function is set up to return an integer result). This leads to the error:

image

and the Log is:

At this point, I am unable to open the original rule as it always gives the "Unexpected Error" message. All I can do is remove that rule and recreate it.

I'm reporting this as it does not seem like it is the intended behavior. I have found that if, instead of setting my variable using "add number", I use "variable math" and subtract 1, all works as expected.

It looks like the return value for the TestRandom rule is a string instead of a number.

You might try creating a global (hub) variable, and just have the Random number generated stored in that instead of trying to return the value from the rule. (Same number of steps), then you can do math with that variable.

Yes, it looks like a string is being returned. The rule function result is defined as integer, so that shouldn't be happening. However, if I change the set variable action from using add number to variable math, all works fine:

image