How to use Variables for dummies

I ran into a situation in my rule machine recently that I still haven't been able to solve, someone tried to help me by telling me to use variables. I started to read the documentation on it but I'm lost more than ever.

I want to know if someone can explain the How, When, and why to use variables in layman's terms because some of you guys are programmers and engineers, some of us just do this as a hobby, So sometimes there's a communication block on my end to fully understand.

Better yet if anyone has put up a video on youtube or here about the Variables that would be great, I checked HE youtube vids but nothing there about variables.

Let me see if I can help...

Variables are containers for information. In Hubitat, they can be setup to contain:

  • Whole Numbers (Ex.: 1; 200; 543) (Numbers)
  • Decimal Numbers (Ex.: 1.34; 200.34; 543.345) (Decimal)
  • Strings of Text (Ex.: Name; 123; This or that or whatever else) (String)
  • True / False (Boolean)
  • Time (Time)

There are 3 types of variables in Hubitat Rule Machine:

  • Global Variables that can be used and modified by every rules
  • Local Variables that you create in each rule
  • Connector Variables that are created as Local Variables, but then made into devices and therefore can be used by other rules, etc.

There can be multiple reasons to use Variables. Here are a few:
Variables can be used to temporarily store information in your rules, in case you want to re-use this information later on.
Variables can be used to share information between rules.

Variables can be used by typing %variableName% in a text box. That text will be replaced by the variable value when the rule is run.

Does that help? Any follow-up questions?

1 Like

Hi,

Do those definitions apply to variable types used in apps and drivers as well?

for instance in an input statement:

 input name: "logEnable", type: "bool", title: "Enable debug logging", defaultValue: true

Good question, but one I cannot answer... I suppose it does, but someone with Groovy experience would need to chime in.

1 Like

Thank you Sebastien,

I'm trying to do something like this, would you be able to help?

To explain what's happening I have Alfred's door lock. I want the light to come on once the code is entered at a certain time and I tried creating something simple like this but it's not working, so someone posted their RM but I can't figure out why this should work vs what I've created, it seems complicated just to get a light to come on once the door is open.

My lock codes are going through the lock code manager

My RM


I also tried
image

Since this guy who's also using the Alfred door lock is working, though complex, I would like to give it a shot, I just don't understand why it should be this complex.

Clearly, you are well versed with variables, so do you think it's needed for something as simple as when unlock code for x is entered and the door sensor is open to turn on the lights?

I think what is happening is that when the lock is entered and the rule is run, the door is still closed. What I would do instead is the following:

Some explanations:

  • When the code is entered and the door unlocked, both conditions will be true, assuming that the unlock event occurs at the same time as the code entered event, which is not guaranteed... See 2nd example for a solution to this.
  • Off: VirtualSwitch —> delayed... I assume you will wan the switch to turn off
  • Cancel Delayed Actions: Delayed actions will run no matter what unless cancelled. This means that if something happens and the door gets closed and unlocked/opened again after 3 minutes, this will cancel it turning off after the “original” 5 minutes. It will only turn off after the “new” 5 minutes. You will not need this line if you remove the delayed Off.

One thing I don’t know is if your lock will report unlocked at the same time as it reports the code entered. If it doesn’t, you will need to add a short delay before the If condition, which would give you this:

Notice two additions:

  1. Wait for event —> elapsed time: 0:00:01 —-This will wait 1 second before evaluating the if condition.
  2. Wait for condition instead of wait for event on Front Door open —- I changed this because after 1 second, the door may already have been opened, and the event: “Door opened” may have already gone through. With this change, it will instead wait for the “door is open” condition. It would work in both examples.

Let me know if one of those work, or if you need more help!

Thank you this is some good info. I'm thinking the issue is the Lock code manager, but i'm not 100% sure. I created both RM like you have listed


and

but it didn't work, the lights didn't come on even though everything showed the rules was met.

When I go into Lock code manager events, I can see where the door was locked and unlocked and once I clicked on save preference I see it's recognizing my codes are there via the events, anything I have set up for the codes isn't working, for example even my notification which worked 100% using my Kwikset lock.

Event from Alfred lock

Lock code manager shows everyone is enabled, yet there's no report logs or log settings even though I have Moderate and I tried Verbose, over the last several days of having it enabled and using the lock code, you would think there should be some reports.

The reason why I'm thinking it's the lock code manager is because even a simple notification isn't working


The notifications work if I had it set to open the front door. This worked also with my previous lock but I also wasn't using the lock code manager, I figured this was the better way to go since I have 3 locks now and I want it to know who's coming in so the greeting for that person code would trigger.

Interesting... Could you go to your lock device(s) and click on the “Events” button on top? See if there are “Lock code entered” events. If not, that would be the problem...

I suspect that those events are not getting triggered. See what is triggered when you unlock and use that event instead.

As a last resort, you could use the “Front Door Lock unlocked” event as your trigger. The only problem there is that the light would probably turn on when you manually unlock your door when going out.

In my door lock device, you can see, locking and unlocking but nothing in the events says lock code entered. I suspected there should have been some type of lock code entered log or event, I just couldn't confirm it..

As for your last resort, that's what I tried before posting anything and confirmed the lights are coming on as I'm going out also because the lock is unlocked from the inside, unlike the old kwikset that didn't require me to unlock it from the inside

I’m trying to follow all of this as I’m thinking of getting the Alfred lock. Could the fact that you have notifications for only once per day turned on have anything to do with it?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.