dleduc Posted February 9 Posted February 9 In the past, whenever I wanted to turn a device on for a certain amount of time I would use code like: However, when I went to set up a new program I noticed that I could do Set 'Mister' On '$Timer %' I'm wondering if this offers superior control, and if so, how do I set the $timer variable? Thanks Quote
jkmcfadden Posted February 9 Posted February 9 I also could see this being useful. But I don't see '$Timer' anywhere in my dropdown choices. Can you show a more detailed screenshot? Quote
Guy Lavoie Posted February 9 Posted February 9 I think it's just a variable that's named "Timer", and is being used to set a light level percentage in this case. There is no built-in timer function. You can cycle through the "Set" command options by clicking on the "Click to specify" triangle below the device name. That said, there is a way to make such a timer, using a simple program. I just created a state variable called Timer, and made this program: If $Timer > 0 Then Wait 1 second $Timer += 1 Now, if you set this variable to a value other than 0, it will increment once per second. You can use this to have one program trigger another one later, or test for a time interval between two triggering events., or measure the time between them. An additional advantage is that it won't die if the triggering program becomes false, like a "Wait" does, if that is what you need. Quote
IndyMike Posted February 9 Posted February 9 9 hours ago, dleduc said: In the past, whenever I wanted to turn a device on for a certain amount of time I would use code like: However, when I went to set up a new program I noticed that I could do Set 'Mister' On '$Timer %' I'm wondering if this offers superior control, and if so, how do I set the $timer variable? Thanks @dleduc, I think you may be misinterpreting how the variable is being used in this statement. The Set 'Mister' On '$Timer %' will transfer the value of the variable as the ON LEVEL for the "mister" device. Valid range is 0 to 100%. The Example Program below sets the On Level of one of my dimmers to 4 different levels specified by the Variable 'IOnLevel'. 100 = 100% and 0 = off. The event viewer shows the ISY commanding the dimmer through the 4 different states. Note that this applies to devices only. If you attempt to assign a variable % to a scene you will only be able to command ON/OFF (anything >0 = ON, 0=OFF). Variable On Level - [ID 0070][Parent 0067] If - No Conditions - (To add one, press 'Schedule' or 'Condition') Then $IOnLevel = 100 Set 'Basement / BSMT Video Cans' On '$IOnLevel %' Wait 1 second $IOnLevel = 50 Set 'Basement / BSMT Video Cans' On '$IOnLevel %' Wait 1 second $IOnLevel = 10 Set 'Basement / BSMT Video Cans' On '$IOnLevel %' $IOnLevel = 0 Wait 1 second Set 'Basement / BSMT Video Cans' On '$IOnLevel %' Else - No Actions - (To add one, press 'Action') Event Viewer (IOnLevel =100) Sun 02/09/2025 08:19:03 AM : [INST-TX-I1 ] 02 62 17 F7 B6 0F 11 FF Sun 02/09/2025 08:19:03 AM : [INST-ACK ] 02 62 17.F7.B6 0F 11 FF 06 LTONRR (FF) Sun 02/09/2025 08:19:03 AM : [INST-SRX ] 02 50 17.F7.B6 53.BC.3A 2F 11 FF LTONRR (FF) Sun 02/09/2025 08:19:03 AM : [Std-Direct Ack] 17.F7.B6-->ISY/PLM Group=0, Max Hops=3, Hops Left=3 (IOnLevel =50) Sun 02/09/2025 08:19:04 AM : [INST-TX-I1 ] 02 62 17 F7 B6 0F 11 80 Sun 02/09/2025 08:19:04 AM : [INST-ACK ] 02 62 17.F7.B6 0F 11 80 06 LTONRR (80) Sun 02/09/2025 08:19:04 AM : [INST-SRX ] 02 50 17.F7.B6 53.BC.3A 2F 11 80 LTONRR (80) Sun 02/09/2025 08:19:04 AM : [Std-Direct Ack] 17.F7.B6-->ISY/PLM Group=0, Max Hops=3, Hops Left=3 (IOnLevel =10) Sun 02/09/2025 08:19:05 AM : [INST-TX-I1 ] 02 62 17 F7 B6 0F 11 1A Sun 02/09/2025 08:19:05 AM : [INST-ACK ] 02 62 17.F7.B6 0F 11 1A 06 LTONRR (1A) Sun 02/09/2025 08:19:05 AM : [INST-SRX ] 02 50 17.F7.B6 53.BC.3A 2F 11 1A LTONRR (1A) Sun 02/09/2025 08:19:05 AM : [Std-Direct Ack] 17.F7.B6-->ISY/PLM Group=0, Max Hops=3, Hops Left=3 (IOnLevel =0) Sun 02/09/2025 08:19:06 AM : [INST-TX-I1 ] 02 62 17 F7 B6 0F 13 00 Sun 02/09/2025 08:19:06 AM : [INST-ACK ] 02 62 17.F7.B6 0F 13 00 06 LTOFFRR(00) Sun 02/09/2025 08:19:06 AM : [INST-SRX ] 02 50 17.F7.B6 53.BC.3A 2F 13 00 LTOFFRR(00) Sun 02/09/2025 08:19:06 AM : [Std-Direct Ack] 17.F7.B6-->ISY/PLM Group=0, Max Hops=3, Hops Left=3 Quote
larryllix Posted February 10 Posted February 10 12 hours ago, Guy Lavoie said: I think it's just a variable that's named "Timer", and is being used to set a light level percentage in this case. There is no built-in timer function. You can cycle through the "Set" command options by clicking on the "Click to specify" triangle below the device name. That said, there is a way to make such a timer, using a simple program. I just created a state variable called Timer, and made this program: If $Timer > 0 Then Wait 1 second $Timer += 1 Now, if you set this variable to a value other than 0, it will increment once per second. You can use this to have one program trigger another one later, or test for a time interval between two triggering events., or measure the time between them. An additional advantage is that it won't die if the triggering program becomes false, like a "Wait" does, if that is what you need. I think that should have been (typo) $Timer -= 1 For more complete If $sTimer > 0 Then Repeat While device is OFF <---- avoid repeated useless comm traffic if desired Set device ON Repeat 1 time(s) Wait 1 second $sTimer -= 1 Else Set device Off Now to turn device on for X seconds, and automagically turn it off after X seconds. $sTimer = X Quote
Guy Lavoie Posted February 10 Posted February 10 No, I meant an incrementing variable. Simply because that's the type I was used to, and how timers worked in the Ocelot controller. They can be made to work both ways. In your sample program, you're only really replacing a Wait statement. The things I use timers for are more for timings between programs, or actions. Things that a single program can't do. I'll give two examples, in pseudo code to keep it short. 1- Implement a "fast on" functionality for a device that doesn't have that built in. I'd do this with X-10 switches on the Ocelot. If you turn the switch on again within 3 seconds, do a secondary function: If Control Switch ON And Timer > 0 Then do secondary function Then Timer = 0 If Control Switch ON And Timer = 0 Then Timer = 1 (start the timer) If Timer > 3 Then Timer = 0 Now the problem with IoX is that you don't know what order the programs are executed in, so if the second program above is actually executed before the first one, then secondary function will trigger every time, because the timer was just set to greater than zero by the program executed previous to it, so additional code could be needed. 2- A more concrete example is the good ole bathroom fan timer application. I actually have this programmed in my eisy, so I'll post the actual code (minus the empty Else statements). It's four programs: G2 toilette 1 fan debut - [ID 0010][Parent 0016] If 'T2 Toilette Fan' Status is On And 'Timers / t0_toilette' raw data 0 is 0 Then $iT2_toilette_temps = 600 Set 'Timers / t0_toilette' Raw value 1 G2 toilette 2 fan ajout temps - [ID 0007][Parent 0016] If 'T2 Toilette Fan' is switched On And 'Timers / t0_toilette' raw data 0 > 0 And $iT2_toilette_temps < 1080 Then $iT2_toilette_temps += 240 G2 toilette 3 fan fin - [ID 0008][Parent 0016] If 'Timers / t0_toilette' raw data 0 > '$iT2_toilette_temps Raw' Then Set 'Timers / t0_toilette' Raw value 0 $iT2_toilette_temps = 0 Set 'T2 Toilette Fan' Off G2 toilette 4 fan off manuel - [ID 0006][Parent 0016] If 'T2 Toilette Fan' Status is Off Then $iT2_toilette_temps = 0 Set 'Timers / t0_toilette' Raw value 0 The names are in French but I think it's easy enough to see what it does. Prog 1: Turning on the bathroom fan the first time starts the timer, and sets the desired time variable to a default 600 seconds (10 minutes). Prog 2: Pressing the On switch again while the timer is running adds another 4 minutes (240 seconds) and you can do that twice (for those big bathroom jobs...) for a maximum for 18 minutes. Prog 3: stops the fan when the timer finally exceeds the desired value, and resets the timer and variable. Prog 4: resets the timer and variable if the fan is turned off manually. The "Timers / t0_toilette' raw data:" statements look like that because my timers are actually a plugin (my first plugin!) so there is no program to do an auto incrementing variable like in my first post. The nodes look like this in IoX If I want to make a self stopping timer, I can set it to a negative number (eg: -5) and it then increments towards 0 and stops on it's own. One tricky thing with the timers is that they're "clock aligned", so they increment when the clock rolls over to the next second. This makes the first count vary in length from almost nothing to almost one second. Good to know if programming very short timings. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.