Rule machine logic help - How to compare Variables Values

Can someone show me a screen shot on how to do the following

I need to compare 2 variables (numbers),

example:
if [variable1] is great to [variable2] then add 1 to [variable3]

I know how to do this in a PLC, but struggling with rule machine

A screen shot would be helpful

Thanks in advance

Does this help?

Can you show me what you use the create this action?

The reason I ask, I do not get the same choices to select the two variables

Did you use conditional Action?

I have a family event I need to go to shortly. I will get back to this later tonight

We can chat later, thanks

1 Like

Yea, this is the condition details:

OK im back, my screen does not have the same options as yours, hum?

Hum, why my options are different from your?

Maybe we try step by step, to see what Im missing. Can you send me a screenshots of each step of creating the action? Something is strange

Show us your variable list at the bottom of the rule. The variables must first exist, type number, in order to have them appear as a choice when creating the condition.

1 Like

I created my variables first and see all my variables in the "Hub Variables" and I created the connectors

You really don't need Hub Variables (formerly, Global Variables). You don't need connectors.

Ok, you haven't created the local variables.
Step 0: click Actions to Run (and Create ... Local Variables)
Step 1: click the + for Create new variable.
Step 2: give it a name
Step 3: give it a type Number
Step 4: give it an initial value.

Here are screenshots after the first variable has been created, while creating the second variable.


Oh, i thought my "Hub Variables" were "local variables" to my hub.

No. Hub Variables are global across all rules. Local variables are only for this rule, local scope.

so I understand, what is difference between global and local variables?

I just told you in my previous reply. Do you want me to explain scoping? I'm glad to do so if you want, it's a standard computer language concept.

sorry, I think it was the timing of both of replying. I understand now. Thanks

1 Like

If you have any more questions, please don't hesitate to ask. The Hubitat users are glad to help. Rule Machine can be confusing the first time you encounter it. We were all starting out, once upon a time.

Rule Machine docs are here:

1 Like

Ok, so after making changes and testing, now I understate the local variables. I did review the rule 5.1 document

I want to start off by saying thank you for your support and that the rule machine is awesome. However, I'm just struggling to understand the Hub Variables and Local variable restriction/uses.

I'm an old PLC ladder logic programmer, in ladder the PLC registers can be use unlimited interchangeable in many logic routes, and without the restriction in most cases.

Which now brings up my next question.

How can create a new RM, and only compare (existing) "Hub Variables" (and not create local variables) I need to compare my existing Hub Variables.

And sorry if im not understanding this, but once I get pass this, it might all come together for me.

I think the problem is that the variable(s) you are trying to compare are not defined as number or decimal. Create new Hub or Rule variables and set them up as either of those and it should work.

1 Like

It should work the same way with Hub Variables, they just aren't as lightweight as Local Variables.

Please post a screenshot from your Settings > Hub Variables page where you created the Hub Variables so that we can see how they are defined.

Here's an example of my global variables. These variables had to be global in nature (Hub Variables) because they are used across multiple rules.

1 Like