Jump to content

Variable comments


MolsonB

Recommended Posts

Is there a way to attach verbiage to variables? I'm starting to collect a lot, and would be nice to be able to write a brief description about what they do.
I waste a variable for a comment in the title for groups of common purpose variables.


------------------------------------------------- WEATHER STUFF -----------------------
another variable

Sent using Tapatalk

Link to comment
  • 2 weeks later...

As I have commented before, I have a mental block with the concept of Variables. Intuitively I understand that the concept may be easy but I just don't get it ?. Somehow I believe (probably mistakenly) that anything a Variable can do, can also be done with a Program.

Could someone give me an easy example of how (from A to Z) I can use a Variable ?  If useful, I use the following Nodeservers : AVRemote, Harmony Hub, Holidays, Holidays Google, Dark Sky, Time-Date. I have wake-up programs that  use AVRemote and Harmony Hub, and that depend on conditions in Holidays Google. I have also other programs that control lights based on motion sensors or on time of the day, etc.  I also actively use Google Home and Alexa.

Link to comment

Consider a program that runs every day at 10 minutes past sunrise.  There's a value there that the ISY must compute, no?  Somewhere in the logic, each day it computes the time that the sun will rise, so that it can run that program at the correct time.  In that example, "sunrise" is a variable -- its value changes (although in this case, the ISY changes it for you, you can't change that value).  I can also run a program at 10:21AM every day -- in that case, we'd commonly say that the value "10:21AM" is a constant.

So, when we speak of variables in the context of ISY programming, we're usually referring to variables that YOU can change, rather than the ones that the ISY changes for you (such as sunrise, sunset, last time a program ran, the brightness of a light, etc, etc).

As for using variables -- you note that there are ways to write programs that eliminate the need for variables.  This is true -- the programming language for the ISY makes it pretty easy to write programs that eliminate the need for variables.  You can do this with other programming languages as well, where (for example) the state of the program determines some intermediate value -- sometimes this is a good thing, but often overuse of this technique results in obfuscated and inscrutable logic that's impossible to debug and fix, not to mention impractical to re-use.  (Sound like some of the programs posted on this forum from time to time?  Yeah, I am sometimes both impressed and horrified at the incredible over-complexity some folks go to in order to, apparently, avoid the use of multiple programs and/or variables...)

So, here's a simple example.  I want to train the dog not to wake me up at 5AM in the morning, so I've rigged up a gizmo that unlocks the dog's crate door automatically.  The approach I'm taking is to unlock the door at 5:05AM, then shift that 5 minutes later each day, up to 7AM.  Because I don't like complicated programs, I'm keeping it simple -- one program runs at 5AM, waits for a variable amount of time, then unlocks the door.  Another program runs at midnight, and adds 5 minutes to that amount of wait time, saves that away in case of an ISY reboot, and of course I want to make sure that I never let that value get longer than 120 minutes (poor dog needs to go outside at SOME point in the morning!).

Main program: runs at 5:00 AM every day
  wait $variable1 minutes
  turn Dog-Crate-Door-Lock on

Support program: runs at midnight every day and if ($variable1 < 120)
  $variable1 = $variable1 + 5
  init $variable to $variable (save the value over powerfails and reboots)

Can you do that with just a program?  Possibly.  But I'm not sure it'd be simpler to do so, or more obvious to maintain.  Plus, you'd still be using variables, they'd just be ones that the ISY itself manages for you.

Link to comment
1 hour ago, asbril said:

Somehow I believe (probably mistakenly) that anything a Variable can do, can also be done with a Program.

You can't replicate everything in programs without variables (such as doing simple math as @mwester explains above).  I would simply say that variables allow me to write fewer, more capable programs.

EDIT: a simple way to look at a variable is to imagine your checking account balance as a variable: you write a check, the variable (balance) changes, you make a deposit, the variable (balance) changes.  It's really just about that simple.

Link to comment

Variables allow some flexibility in your programs.

For example, say you have 4 bath exhaust fans that you want to run for 10 minutes whenever the bath light is turned on. You could write 4 separate programs that state something like if light is switched on set bath exhaust timer for 10 minutes. If you want to change that 10 minutes to say 20 you would have to go in and change each of the 4 programs to 20.

Or, you can define a variable, say, as 10 and replace the hard coded 10's in your 4 bath exhaust fan programs to the variable name. If you want to change it to 20 later you would only need to change that time variable to 20 and it would automatically be replaced in your programs wherever is it used.

You could also change that time variable by another program if you wanted and it would be in effect for your bath fan timers.

Link to comment
43 minutes ago, asbril said:

So, how do I create the $Variable for ISY to know that it is 5 minutes ?

Those were mostly hypothetical programming lines that ISY cannot do yet, only for examples.

You already use  variables in devices, called fields or parameters. Some you can only read, and some you can only write and some you can read and write the values.

When you set your lamp to 50% you are writing to a dedicated variable, and after is sets and reads back the light the variable will show you the result, which you can now use. 
These may be called fields or nodes or parameters for each device but work almost exactly the same as variables. You have already been using them! Only thing is, with variables they don't do anything in the background, they are for YOUR usage exclusively.

Try this.
Create a State variable under the State variable tab.  Hit "Add" at the bottom, click on the new name that pops up, and edit it to read "testVar", click Save at the bottom.
Create a simple program called 'Variable Test' like this.

'Variable test'
If
    $testVar = 1 <------- ISY adds the "$" to indicate it is a variable
Then
    set some test lamp On
Else
   set same test lamp Off
Click save

Now go back to the State variable tab page. Click on the value at the right beside the name you entered. Type "1",
     hit enter a few times, or click on another spot to "seal the deal".

Try entering "0".

Check back when you see what that does for you and we can advance your brain some more. Best of luck! :)

 

 

Link to comment
48 minutes ago, asbril said:

So, how do I create the $Variable for ISY to know that it is 5 minutes ?

In the admin console, go to the variables page, and define new variable.  I used the name $variable1 -- that's dreadful, so use a better more-descriptive name everywhere it's used and defined.  When you define that variable name, you can optionally set the initial value.  The programs I sketched out above are fine if the variable starts out with the value "0", so I'd just leave it at the defaults.  It's that simple.

Link to comment
2 minutes ago, mwester said:

In the admin console, go to the variables page, and define new variable.  I used the name $variable1 -- that's dreadful, so use a better more-descriptive name everywhere it's used and defined.  When you define that variable name, you can optionally set the initial value.  The programs I sketched out above are fine if the variable starts out with the value "0", so I'd just leave it at the defaults.  It's that simple.

ISY cannot use the example of
    Wait $variable1 minutes
or any other variable, regardless of name. That may be very confusing to a person starting out.

 

 

Link to comment
10 minutes ago, larryllix said:

Those were mostly hypothetical programming lines that ISY cannot do yet, only for examples.

You already use  variables in devices, called fields or parameters. Some you can only read, and some you can only write and some you can read and write the values.

When you set your lamp to 50% you are writing to a dedicated variable, and after is sets and reads back the light the variable will show you the result, which you can now use. 
These may be called fields or nodes or parameters for each device but work almost exactly the same as variables. You have already been using them! Only thing is, with variables they don't do anything in the background, they are for YOUR usage exclusively.

Try this.
Create a State variable under the State variable tab.  Hit "Add" at the bottom, click on the new name that pops up, and edit it to read "testVar", click Save at the bottom.
Create a simple program called 'Variable Test' like this.

'Variable test'
If
    $testVar = 1 <------- ISY adds the "$" to indicate it is a variable
Then
    set some test lamp On
Else
   set same test lamp Off
Click save

Now go back to the State variable tab page. Click on the value at the right beside the name you entered. Type "1",
     hit enter a few times, or click on another spot to "seal the deal".

Try entering "0".

Check back when you see what that does for you and we can advance your brain some more. Best of luck! :)

 

 

Thank Larry. I created the Variable and the Program, and then the selected device turned on.  I am not sure that I understood "Try entering '0' " . When I did the device went OFF, which is probably what you suggested that it would do. Now that i created the variable and the test program,  what would be a practical use of the variable in for instance one of my wake-up programs ?

Link to comment

:-) That's the problem with pseudo-code -- it exists to make things simpler, but then folks try it literally and get confused when it doesn't work.

Yes, you can't type in ANY of my examples and expect them to work as typed into the forum.  You'll have to update them so they are valid ISY code, that's on the user to do.

Link to comment
2 minutes ago, asbril said:

Thank Larry. I created the Variable and the Program, and then the selected device turned on.  I am not sure that I understood "Try entering '0' " . When I did the device went OFF, which is probably what you suggested that it would do. Now that i created the variable and the test program,  what would be a practical use of the variable in for instance one of my wake-up programs ?

Now a second stage.

Add this program
 

'Time Test'
If
Then
    set $testVar = 1
    Wait 30 seconds
    set $testVar = 0
Else
    ----

Try right clicking on the new program, run Then.

Link to comment
1 minute ago, asbril said:

... Now that i created the variable and the test program,  what would be a practical use of the variable in for instance one of my wake-up programs ?

Ah, now THAT might be the real issue.  If you're more wondering about the WHY of variables rather than the HOW, well, then you probably haven't yet encountered a need for variables.  And if your automation doesn't need variables, then don't use them - and don't worry about them!  You're not missing anything!  (By analogy -- variables are kinda like a spark-plug wrench -- if you're not sure when you'd ever need to use one, then clearly you don't need one in your toolbox!  Conversely, when you encounter a situation where you need a spark-plug wrench, you'll know it, and you'll know that nothing except a spark-plug wrench will do the job.)

Link to comment
4 minutes ago, mwester said:

:-) That's the problem with pseudo-code -- it exists to make things simpler, but then folks try it literally and get confused when it doesn't work.

Yes, you can't type in ANY of my examples and expect them to work as typed into the forum.  You'll have to update them so they are valid ISY code, that's on the user to do.

Years ago on TV there was a series called Soap (with Billy Cristal). Every week it ended with a comment like "If you were not confused before, then you will be now", or something similar. That is how I feel now ?

Link to comment
19 minutes ago, larryllix said:

Now a second stage.

Add this program
 

'Time Test'
If
Then
    set $testVar = 1
    Wait 30 seconds
    set $testVar = 0
Else
    ----

Try right clicking on the new program, run Then.

That worked !!!!!!! Now another of my probably dumb questions... I could use this variable logic for instance with a motion sensor, but I already achieve the same in a program IF sensor is ON THEN Light X is ON WAIT 30 Seconds Light X OFF..............................

Link to comment

Now I want you to go to the Integer variable tab and create another new variable, called $Lamp.level.saved.asbril. Click save.
Now create a new program like this.

Flash lamp.abril - [ID 0003][Parent 0001][Not Enabled]

If
   - No Conditions - (To add one, press 'Schedule' or 'Condition')
 
Then
        $Lamp.level.saved.asbril  = 'MyTestLamp' Status 
        Repeat 2 times
           Set 'MyTestLamp' Fast On
           Set 'MyTestLamp' Fast Off
           Wait  1 second
        Repeat 1 times
           Wait  1 second
           Set 'MyTestLamp' On '$Lamp.level.saved.asbril %'
 
Else
   - No Actions - (To add one, press 'Action')
 


Now set MyTestLamp to some level of brightness, full on or Off is not dimmable.
Click on the new program and run 'Then'
See how the lamp gets borrowed for flashing and then returns to what it was at before?

This is a program you can keep for testing your other programs. To determine your program has advanced to a certain line, you can insert a call to this program to verify it actually got there.
   my lines of code
   Run Program 'Flash Lamp.asbril' (if)
   my lines of code

Use it elsewhere to indicate a household alarm...borrowing the lamp and then "putting it back" to where it started.
This is a practical usage of a variable, remembering the status of a light, for temporary usage with another purpose.
I use this to flash lights at midnight as a bedtime reminder. The lights return to On, Off, or dimmed level, wherever they were before.

Link to comment

This is one thing you cannot d with only programs. I saved a bank of space so they don't end up strewn throughout my 4-500 variables.
Please note my variable grouping title as the top variable? (OP @MolsonB). I also can save colours (eh?) of coloured bulbs and strips. I don't think that will work south of the border. :) 

1971984487_ISYlevelsavervariables.thumb.jpg.193756864da88d8768abd19affd3202c.jpg

Link to comment
49 minutes ago, asbril said:

Years ago on TV there was a series called Soap (with Billy Cristal). Every week it ended with a comment like "If you were not confused before, then you will be now", or something similar. That is how I feel now ?

There hasn't been a time where you have posed a question in which it hasn't enlighten ten other people in doing so. I very much enjoy watching Larry and others illustrate some of the hardest concepts such as Variable to the masses.

His Kung Fu is very powerful . . . 

Link to comment

I also believe there have been some basic concepts not fully explained and this is important. Another is proper house cleaning and coming up with a working schema. Doing so will insure over the long term *By Eye* you will know exactly what something is and this should automatically trigger a pause in a person when making a program(s).

Variable Schema: Many of us identify the two variables with a (s) vs (i) to denote what you're selecting from the programs tab. This ensures you don't pick the opposite variable that may have the same name which 99% of the time leads to unintended actions in the network.

Which leads to the next basics about variables a State variable will execute every time vs a integer variable will not. Using the two when required can offer you untold power and flexibility in crafting unique programs.

Integer Variable.PNG

State Variable.PNG

Link to comment

A few additional comments of example uses.....

1) I too use the I_ to denote integer variables, but to save time, I dont bother putting the S for state variables, that becomes my default if it doesn't have an I. (I have many many more state variables than Integer, so just saves time, effort)

2) I have many program folders that I "Enable" and "Disable". To do so, I simply have a variable condition for that parent folder that is either a 1 (enabled) or 0 (disabled).  Then I have a folder for all my enabling/disabling programs, which are simple: then $var=1, or else, $var=0, specific to each large folder of programs I am controlling. Then in MobilLInc on my cell phone, i have modified each program's screen via Advanced to show only Enabled or Disabled.(see attached screen shot) So with a quick glance I can easily override a set of programs, for example when guests are at the house etc. sprinklers, xmas lights, etc. 

3) I have set up an alarm using an 8 button keypad next to my bed. Each left row represents the hours of 5, 6, 7, 8, each right row represents minutes 0,15,30,45. By selecting one button from each side, variables are set (500., 600, 700, 800 and 0, 15, 30, 45), then are added make a third variable Alarm set time.. ie 700+45 = 745.. This variable is then tested such that If( $var =745 and time is 7:45am,) then start the alarm process.  

4) Garage door shut attempts. I use a variable to keep track of attempts to automatically shut a garage door, (twice) and then initiate a failure routine. 

etc. 

etc

etc.

 

As others have demonstrated, there is a lot of power of using variables in your programing logic. 

mobilinc.jpg

Link to comment
1 hour ago, larryllix said:

I use this to flash lights at midnight as a bedtime reminder. The lights return to On, Off, or dimmed level, wherever they were before.

I am trying to understand this because it would be very useful. I have two motion sensors that do the following :

(1) turn on the hallway lights for 5 minutes when someone enters our home

(2) flash a lamp in my master bedroom to let me know when someone enters our home (*)

However,  if the hallway lights (1) are already ON, then I don't want them to OFF after 5 minutes. If I understand your program above, I could resolve this with the Variable

(*) For fire brigade regulations, we are not allowed to put a lock on the door in our main elevator lobby of our condo, because theoretically someone could get stuck between the elevator and the door in case of a fire. We also have a camera with email alert, with a snap picture,  when someone enters our home.

Link to comment

Yes. It was the most useful, and simplest variable program I could think of to get you past your variaphobia.
Try a few other and useful application that fit your purpose. As @@mwester noted above, until you have a use for them it is just dry homework. OTOH Until you understand some of the uses, you will have no uses for them. It's a double edged sword and a vicious cycle and a.... :)

The first program example was an example of how variables can be triggers. The last one was how they can save things. For that application, think of variables as small boxes you can store things in, so you can het them out later, except they are like bottomless coffee, you take a copy out and it is still there.

I'll be back later tonight. I have to take my sweetie out to keep her satisfied happy. Dang spell correct!

Link to comment

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...