DrLumen Posted February 17, 2020 Posted February 17, 2020 Depends on the initial value of $lamp.level1% from the 3rd line (1st of then). It could turn it back on if it was not 0%.
asbril Posted February 18, 2020 Posted February 18, 2020 1 hour ago, DrLumen said: Depends on the initial value of $lamp.level1% from the 3rd line (1st of then). It could turn it back on if it was not 0%. I may need some help understanding this. If the Hallway ceiling light WAS On before the motion detection, then I want the Hallway ceiling light to go on again.
Mustang65 Posted February 18, 2020 Posted February 18, 2020 @larryllix should asbril program his motion sensor only to send the "On", before he attempts to go with the motion sensors and variables?
DrLumen Posted February 18, 2020 Posted February 18, 2020 (edited) 26 minutes ago, asbril said: I may need some help understanding this. If the Hallway ceiling light WAS On before the motion detection, then I want the Hallway ceiling light to go on again. Ok. If it was on @ line 3 then it will return to that with the last line. In this instance, and that is the action you want, then the next to last line is redundant as it is immediately countermanded to whatever is stored in the variable. Unless you want it to flash off then back on? Edited February 18, 2020 by DrLumen 1
asbril Posted February 18, 2020 Posted February 18, 2020 13 minutes ago, DrLumen said: Ok. If it was on @ line 3 then it will return to that with the last line. In this instance, and that is the action you want, then the next to last line is redundant as it is immediately countermanded to whatever is stored in the variable. Unless you want it to flash off then back on? So you mean that. " Set ’16. Hallway/ 2. Hallway Ceiling’$[Var1.2}% " sets the light to its previous status and "Set Hallway Ceiling Off" is redundant ?
DrLumen Posted February 18, 2020 Posted February 18, 2020 (edited) It depends on what you are wanting it to do. Yes the last line will set the level back to the whatever value it found on the right side of the = in line 3. If all you want is to return it to whatever it was @ line 3 then the next to last line is not needed. But, personally, I flash the certain lights for various things throughout the day so I'm not sure if the next to last line was intentional. Line 4 is kinda questionable as well but maybe 'ON' will be at different levels. If it is on, why do you want to turn it on again in line 4? No damage, just overkill. Edited February 18, 2020 by DrLumen
asbril Posted February 18, 2020 Posted February 18, 2020 8 minutes ago, DrLumen said: It depends on what you are wanting it to do. Yes the last line will set the level back to the whatever value it found on the right side of the = in line 3. If all you want is to return it to whatever it was @ line 3 then the next to last line is not needed. Personally, I flash the certain lights for various things throughout the day so maybe that is what you want. I am very grateful to you all, but I still feel dumb. Tomorrow I am asking you some more questions.
DrLumen Posted February 18, 2020 Posted February 18, 2020 (edited) Maybe if you were exposed to different ways of using variables. ISY is very limited as it tries to make it simple and idiot proof so they have it locked down. In a way it keeps it safer but sometimes causes many more steps than are necessary in other languages. In the hopes this will make more sense. Other programming languages have some form of For loops (among many other things). they are like this (in basic) total=0 'reminder that the next line is the beginning of the loop For count=1 to 5 total=total+count Next count 'end of loop total will equal 15 This will go from For to Next 5 times. At each time through the loop (iteration) it adds the current count value to the total so the first time the count will be 1 and the total will be 1. 2nd time through the loop, count is 2 and the total is now 3 (1+2). 3rd time through and the count is 3 and the total is now 6 (1+2+3). 4th time the count is 4 and the total is 10. 5th time the count is 5 and the total is 15. Note that the total was set to 0 initially but could be any value. If total=10 at the start, at the end of the 5 cycles the total would be 25. Not sure if this helps or makes it more confusing... PS: Found a bug Edited February 18, 2020 by DrLumen
larryllix Posted February 18, 2020 Posted February 18, 2020 (edited) 17 hours ago, asbril said: Will this program turn ON my Hallway ceiling light for 5 minutes (if the light was not already ON, and then after 5 minutes go to the previous Status ON or OFF ? T H A N K S.... and good luck tonight You have the right idea but this will have problems! The first time an MS triggers it will go through the motions and work properly. As posted above @DrLumen the second last line should be eliminated otherwise flashes could occur with useless command sends. However, While the light is on and another motion is sensed, the Then will start again and, while it works for Wait timer to extend the time, it will overwrite the variable storing the lamp level and later restore the lamp to the latest overwritten value, which will be the one from the program, and the light will never return to the way it was found. This will likely take two programs where the second program disables the first program so it cannot get triggered repeatedly. That may not work either. There may be a way to put a conditional "If" line into your program to prevent all this. Let me think on that one....trouble maker! Edited February 18, 2020 by larryllix
asbril Posted February 18, 2020 Posted February 18, 2020 4 minutes ago, larryllix said: Let me think on that one....trouble maker! Maybe I should just stick to Programs
larryllix Posted February 18, 2020 Posted February 18, 2020 (edited) 22 minutes ago, asbril said: Maybe I should just stick to Programs No. You just picked a complex variable application...LOL I think this should work but it will seem complicated, since ISY does not have a proper inline "If" construct. This is being typed freestyle. If MS1 is switched On OR MS2 is switched ON Then Repeat while $lamp.level1 < 0 <---- use variable also as a flag (-1) to indicate it is already in use $lamp.level1 = light status <------ not in use, save the current light level in it Repeat 1 time <----close out the inline "If" condition, back to our regularly scheduled program. Set Light On Wait 5 minutes Set Light $lamp.level1 % <---- restore the light to the found value, not Off $lamp.level1 = -1 <--- restore flag value = "not in use" for the next time Else ---- Go to the Integer variable page and set the value of $lamp.level1 to -1, and then set the "init to" value to -1, also. This will guarantee the variable will always boot up with a negative value. Edited February 18, 2020 by larryllix
DennisC Posted February 18, 2020 Posted February 18, 2020 (edited) Here is another case use for variables. Use of a geofence program to alert ISY that a user is home or away. I use Tasker on Android for this. Upon arriving home, I have Tasker set a variable to 1. When I leave home, the variable is set to 0. Now I can write different programs that will execute based on being home or away. For example, if I am away, turn on inside lights at various times to simulate someone moving through the house. I also use the same variable to light up my long driveway and lights on the path to the door when adding home. Edited February 19, 2020 by DennisC Correction 1
asbril Posted February 18, 2020 Posted February 18, 2020 13 hours ago, larryllix said: No. You just picked a complex variable application...LOL I think this should work but it will seem complicated, since ISY does not have a proper inline "If" construct. This is being typed freestyle. If MS1 is switched On OR MS2 is switched ON Then Repeat while $lamp.level1 < 0 <---- use variable also as a flag (-1) to indicate it is already in use $lamp.level1 = light status <------ not in use, save the current light level in it Repeat 1 time <----close out the inline "If" condition, back to our regularly scheduled program. Set Light On Wait 5 minutes Set Light $lamp.level1 % <---- restore the light to the found value, not Off $lamp.level1 = -1 <--- restore flag value = "not in use" for the next time Else ---- Go to the Integer variable page and set the value of $lamp.level1 to -1, and then set the "init to" value to -1, also. This will guarantee the variable will always boot up with a negative value. Thanks. I may keep this motion sensor --} lights working with the programs that I have already. I am a relatively not-stupid person in general, but even with your explanations I still have a blockage about the concept of Variables. And I need to grasp the concept so that I can create my own programs.
DrLumen Posted February 18, 2020 Posted February 18, 2020 (edited) If it works for you without variables and you don't ever see that the conditions or actions will be 'variable' then what you have is best. No need to over complicate things. FYI, you are already using variables. The descriptions you are making for your motion sensors and switches are technically variables. They change to on/off (Boolean true/false or 1/0). Can hold changing integer values like levels. And in some cases hold floating point values, perhaps like temperature. The only real difference is you can change the values for the variables you create instead of them being tied to the status of a device. You don't have to send them to a device (ie levels) to change them. Edited February 18, 2020 by DrLumen 1
larryllix Posted February 18, 2020 Posted February 18, 2020 Just now, asbril said: Thanks. I may keep this motion sensor --} lights working with the programs that I have already. I am a relatively not-stupid person in general, but even with your explanations I still have a blockage about the concept of Variables. And I need to grasp the concept so that I can create my own programs. Comfort with them will come with beating down your anxieties with practice. Just experiment with them using little programs. You can always delete the whole thing when you are done. ISY is your playground. I think we have a success with the light blink program for you. It is very handy for troubleshooting questionable programs. Insert a program call to the flash program, move it up and down in your programs and delete the lune when done. Keep your programs small and limited to small tasks at a time. Here is a simple programmable timer using State variables. It counts down by minutes during waking hours only. Occupied.countdowner - [ID 0167][Parent 000B][Run At Startup] If $sHouse.occupied.timer > 0 And From 7:00:00AM To 11:00:00PM (same day) Then Wait 1 minute $sHouse.occupied.timer -= 1 Else - No Actions - (To add one, press 'Action') Self retriggering timer. Enabled to run at startup! -If startup occurs ouside wake timeframe, will self start at beginning of timeframe. -If timeframe commences while .timer is 0, first new occupied.timer value will start again. This is the resultant checker that monitors the variable and controls the Occupancy flag variable. That controls all the other functions Occupied.flagger - [ID 0168][Parent 000B] If $sHouse.occupied.timer > 0 Then $sHouse.occupied = $cTRUE Else $sHouse.occupied = $cFALSE Power up assumes home unoccupied! Shouldn't be long to correct that. Program cannot be combined into "Occupied countdowner" program as it's timeframe end would zero occupied.timer Here is a sample MS program that triggers the timer. I have about 12 MSes that activate the timer with different times. Motion.MBR - [ID 0009][Parent 000B] If 'Master Bedroom / MBR.MS' is switched On Then Wait 2 seconds $sHouse.occupied.timer = 180 <----- in 180 minutes the house will be considered "Unoccupied" Else - No Actions - (To add one, press 'Action') 1
DrLumen Posted February 18, 2020 Posted February 18, 2020 Next week is the use of arrays and pointers. Oops, not in ISY - nevermind. 1
dbwarner5 Posted February 18, 2020 Posted February 18, 2020 @asbril Another attempt to explain variables......Think of a variable as basically a holding spot for almost anything. The first step is always to create the variable. This requires deciding if it's going to be a STATE variable or an INTEGER variable. Only STATE variables will cause programs to run if they change. Integer variables can still be used as part of an IF, but they will be a "condition" that is checked when something else causes the program to run, such as being called by another program, or some other IF condition causes ISY to test its conditions. Generally, Integer variables are a way of keeping track of things. Example below: So the Integer variable below can change all day long, but will never cause this program to run. But if the time is 6:00am, then ISY will "check" this program for true or false, based on the value of the integer variable. The value of the variable in this case gets set by another program. So its a "condition" of the IF statement, but it won't cause the ISY to check the IF statement if it changes. This is different for STATE variables and hence the name. If Time is 6:00:00AM And $I_Alarm_Value is 600 Then Run Program 'Alarm Process LD' (Else Path) So switching back to STATE variables, once you have defined a state variable to X or Y, you can now use it in a program as a condition. The ISY will check the IF statement if a state variable changes its value --> ie its "state". In the body of any program, you can adjust the variable to change which will cause any programs that are relying on it to do something like run the THEN, or run the ELSE. This is the easiest use of variables. So as a simple example, if I Arm my security system (Elk), the ISY recognizes its condition and sets a variable AWAY to 1. I then have many other programs and folders that are watching the state of the AWAY variable. And when it changes, it causes those programs to run. In this case, some folders become false and stop running, other folders become true and start to run, etc. Other programs begin running like random lights during the evening hours, Water gets shut off etc. So essentially, by changing one variable, I can control the run pattern of many many programs all at once. In the example that Larry wrote for you for your MS, the variable is used in a slightly different way. Its a temporary storage of something. The start of the program stores the value of the light%, and then it can now change the light however you would like.. blink it, turn it on, turn it off, wait... etc.. Do whatever you want for as long as you want. Then when you want to "remember" what it was at, you have that information protected and stored as a variable. You then are simply setting the light equal to the value of that variable, which was created at the beginning. That variable will stay at that value until one of two things happens: it is changed by a program(s), or if the ISY reboots. When the ISY reboots, all variables are set to their INIT setting under the variables tab. To protect the value of an important variable, you can write a line in a program that will set the init value to the current value of that variable. This way, if the isy reboots, the value of the variable will get reset (init) to the value it had before the power failure. As others have said, variables become a huge part of isy programming. The more you understand and use them, the more you will use them. A fun and simple way to play with variables to learn about them is to set up a program that can "count" something, such as how often a certain light gets turned on/off during the day. If From 8:00:00AM To 11:00:00PM (same day) And ( 'Bar under cabinet' is switched On Or 'Bar under cabinet' is switched Off ) Then $I_Test += 1 Else $I_Test = 0 During 8-11pm, each time the light is switched on or off, the integer variable ITest will increase by one. After 11, the program becomes false so the variable resets to zero. If you try this using a STATE variable, you can then write a second program that when the variable becomes > 10, it sends you a text.. or turns on a certain light... something to give you the feel of how state variables can keep track of something and then trigger something else. Cheers and good luck.. keep at it.!! 1
Teken Posted February 18, 2020 Posted February 18, 2020 1 hour ago, asbril said: Thanks. I may keep this motion sensor --} lights working with the programs that I have already. I am a relatively not-stupid person in general, but even with your explanations I still have a blockage about the concept of Variables. And I need to grasp the concept so that I can create my own programs. Keep in mind as others mentioned if what you have in place works ~ it works! Another benefit of using variables is it gives you the ability to count and do basic math. I use variables to track activity for motion sensors and receive a final report each day / month. This in a round about way allows me to gauge if X battery vs Y battery is offering the run time I expect. The use of variables also enables me to track how long something has been running for. Good to know for things like HWT, Sump, Water Flow . . . Lastly, variables allow me to track the current, low, and high values for a temperature sensor. This allows me to know exactly how hot, cold, just right, that porridge is for those three little bears!
Recommended Posts