even if I'm not new to HE, I've still a lot to learn. One thing I never really got my head around was variables. The biggest reason right now is, that I have no real idea, what they are and how to use them. Could someone please explain them to me. I've used the search function and tried to find something in the documentation, but I just got more confused. Please make it for dumdums. Examples for better understanding are appreciated.
Local Variable = variable that only the one rule can use (the one where it was created) Global Variable = variable that all Rule Machine Legacy rules can use (now retired I think) Connector Variable = variable that could be created in Rule Machine Legacy that created a device. The device had the same state as the variable. (Ex.: yes; present; open; etc. Vs no; absent; closed, etc.) (Also retired for Rule Machine 5.0 and up) Hub Variable = variable that (I think) all apps on the hub can use
Are you asking what these specific variables are for? Or are you asking about the difference between variable types? Or are you asking more generally what might one use a variable for?
All of it. I would love not to bother one of you guys, but as I've written, nothing right now to find at the documentation, giving me any clue and going through all the threads made me more confused...
Iām not sure if this is what you are asking, but a variable is basically a place holder that holds whatever value your assign to it.
There are different variable types based on the kind of data the variable holds, such as string, number, boolean (true or false), decimal, date/time. When you first create the variable, you decide what type based on what type of data it will be holding.
Besides type, there is also the concept of scope, which determines where the variable will be available. Examples of scope with Hubitat is local and global.
To elaborate on what @didymus wrote, variables are a concept that that come to us from algebra by way of traditional computer programming. Here's a quick video on the basic concept:
In your example a string is a type of variable that generally holds alphanumeric or text information - letters, numbers, and symbols. "Today is Sunday" or "123XYZ" or "Jane Doe" are all strings. A number is an integer value, and a decimal is a value with a decimal point. A boolean variable can be only two values, true or false. And last but not least a datetime variable contains a specific date and time.
You can use variables in rules and other applications to replace specific values. For instance, I use the following variables;
I have a rule which repeatedly pings my phone but I want to be able to easily change the number of times it retries the ping and the delay between pings. So I have created variables called "ping_retries" and "ping_retry_delay" to represent these two numbers. In my rule I use the variable instead of the actual number: