ADICON Support Forum Applied Digital, Inc.
Page 1 of 1 1
Topic Options
#17568 - 02/22/07 10:40 PM Could someone please look at this Ocelot code??
Les Offline
newbie


Registered: 02/22/07
Posts: 9
The application is to turn on 4 light to 38% Dim at sunset and if Power Flash (driveway sensor)is tripped during night the light will go full bright for 8 minutes and then dim back to 38% before midnight and 0% after midnight. All lights to turn off after midnight. I also set some daylight commands to ensure the lights stay off during the day.

After looking over some other code here it seems that there may be a better ways to write this short program. Anyone with some thoughts on this code. TIA

0001 - IF Time of Day becomes = Sunset offset 0 minutes // Turn On Lights at Sundown
0002 - THEN Set X-10 House A / Unit 1, to: 38 % //
0003 - THEN Set X-10 House A / Unit 2, to: 38 % //
0004 - THEN Set X-10 House A / Unit 3, to: 38 % //
0005 - THEN Set X-10 House A / Unit 4, to: 38 % //
0006 - //
0007 - IF Time of Day is > Sunset offset 0 minutes // Go to Full Bright when
0008 - OR Time of Day is < Sunrise offset 0 minutes // Driveway Sensor is Tripped
0009 - AND Receive X10, A - 5 //
0010 - THEN Set X-10 House A / Unit 1, to: 100 % //
0011 - THEN Set X-10 House A / Unit 2, to: 100 % //
0012 - THEN Set X-10 House A / Unit 3, to: 100 % //
0013 - THEN Set X-10 House A / Unit 4, to: 100 % //
0014 - THEN Timer #0 = 1 // Start Timer for Lights to return to Dim
0015 - //
0016 - IF Timer #0 is = 480 // After 8 Minutes return
0017 - THEN Set X-10 House A / Unit 1, to: 38 % // to original Dim Level
0018 - THEN Set X-10 House A / Unit 2, to: 38 % //
0019 - THEN Set X-10 House A / Unit 3, to: 38 % //
0020 - THEN Set X-10 House A / Unit 4, to: 38 % //
0021 - THEN Timer #0 = 0 //
0022 - //
0023 - IF Time of Day becomes = 23:59 // At 12:00am Turn Off all lights
0024 - THEN Set X-10 House A / Unit 1, to: 0 % //
0025 - THEN Set X-10 House A / Unit 2, to: 0 % //
0026 - THEN Set X-10 House A / Unit 3, to: 0 % //
0027 - THEN Set X-10 House A / Unit 4, to: 0 % //
0028 - //
0029 - IF Time of Day is > 00:01 //
0030 - OR Time of Day is < Sunrise offset 0 minutes // Turn on Lights if driveway
0031 - AND Receive X10, A - 5 // tripped after midnight
0032 - THEN Set X-10 House A / Unit 1, to: 100 % //
0033 - THEN Set X-10 House A / Unit 2, to: 100 % //
0034 - THEN Set X-10 House A / Unit 3, to: 100 % //
0035 - THEN Set X-10 House A / Unit 4, to: 100 % //
0036 - THEN Timer #1 = 1 //
0037 - //
0038 - IF Timer #1 is = 480 // After 8 Minutes return to OFF
0039 - THEN Set X-10 House A / Unit 1, to: 0 % //
0040 - THEN Set X-10 House A / Unit 2, to: 0 % //
0041 - THEN Set X-10 House A / Unit 3, to: 0 % //
0042 - THEN Set X-10 House A / Unit 4, to: 0 % //
0043 - THEN Timer #1 = 0 //
0044 - //
0045 - IF Time of Day is > Sunrise offset 0 minutes // Back Up to turn Off All Lights Off
0046 - THEN X-10 House A / Unit 1, Turn OFF //
0047 - THEN X-10 House A / Unit 2, Turn OFF //
0048 - THEN X-10 House A / Unit 3, Turn OFF //
0049 - THEN X-10 House A / Unit 4, Turn OFF //
0050 - //
0051 - IF Time of Day is < Sunset offset 0 minutes // Do Not Turn On Lights During the Day
0052 - THEN X-10 House A / Unit 1, Turn OFF //
0053 - THEN X-10 House A / Unit 2, Turn OFF //
0054 - THEN X-10 House A / Unit 3, Turn OFF //
0055 - THEN X-10 House A / Unit 1, Turn OFF //
0056 - //
0057 - End Program //

Top
#17569 - 02/23/07 12:37 AM Re: Could someone please look at this Ocelot code? [Re: Les]
Just Another Joe Offline
enthusiast
****

Registered: 09/02/03
Posts: 204
Loc: Adanac
Les, the first and greatest concern I would address with your program, is with the two line groups at the end, beginning at line 45 and at line 51. The first group will flood your line with a continuous sequence of OFF commands, from sunrise until midnight. The second will do the same from midnight till sunset. The first can be fixed by changing the 'is >' to 'becomes ='; the second is redundant and can be removed. Also, instead of sending the four TURN OFF commands, a slight performance gain could be made by sending four addresses followed by an OFF, which would cause all four to turn off simultaneously:

0001 - IF Time of Day becomes = Sunrise offset 0 minutes // Turn all four lights off at sunrise
0002 - THEN Transmit X10, A - 1 //
0003 - THEN Transmit X10, A - 2 //
0004 - THEN Transmit X10, A - 3 //
0005 - THEN Transmit X10, A - 4 //
0006 - THEN Transmit X10, A - OFF (20) //

This will place five X-10 commands on the line, rather than eight commands, and so will be slightly faster.

Next, I'm not sure what the Power Flash does. If it sends repeated A5 commands in response to repeated events, then each event will restart your timer at line 14 and again at line 36, even if it has not timed out. So, an event that occurs six minutes after a previous event will give the lights another eight minutes, for a total of 14 minutes. I'll assume that that is what you want. However, each event will also send the SET commands again, which is unnecessary. I'm not familiar with the X-10 SET command, so I don't know whether the same optimization above could be used by sending A1, A2, A3, A4, A-SET-100% (or 38%, or 0%).

When your timers expire at lines 16 and 38, it would be better to use 'is > 480' rather than 'is = 480.' First, this will give you 480 seconds rather than 479, which is likely completely insignificant in this case, but could be very important when timing a three or four or five second event. More important, if your program ever grows so large that it takes more than one second to complete a single pass, your timer could increment by two between passes, so it could go from 479 to 481.

Also, if your sensor trips at 23:57, then the lights will remain on for only two minutes before being turned off at 23:59 at line 23.

Finally, you could combine both timeframes and use just a single timer. The end result could look something like this:

0001 - IF Time of Day becomes = Sunset offset 0 minutes // Turn on lights at sunset
0002 - THEN Set X-10 House A / Unit 1, to: 38 % //
0003 - THEN Set X-10 House A / Unit 2, to: 38 % //
0004 - THEN Set X-10 House A / Unit 3, to: 38 % //
0005 - THEN Set X-10 House A / Unit 4, to: 38 % //
0006 - //
0007 - IF Time of Day is > Sunset offset 0 minutes // If nighttime
0008 - OR Time of Day is < Sunrise offset 0 minutes //
0009 - AND Receive X10, A - 5 // and driveway sensor tripped
0010 - ELSE Skip to line 19 // otherwise skip
0011 - IF Timer #0 is = 0 // If timer not running
0012 - THEN Set X-10 House A / Unit 1, to: 100 % // set lights to full bright
0013 - THEN Set X-10 House A / Unit 2, to: 100 % //
0014 - THEN Set X-10 House A / Unit 3, to: 100 % //
0015 - THEN Set X-10 House A / Unit 4, to: 100 % //
0016 - THEN Timer #0 = 1 // and start timer
0017 - ELSE Timer #0 = 1 // otherwise, just restart timer
0018 - //
0019 - IF Timer #0 is > 480 // After eight minutes
0020 - AND Time of Day is > Sunset offset 0 minutes // and before midnight
0021 - THEN Set X-10 House A / Unit 1, to: 38 % // return lights to original dim level
0022 - THEN Set X-10 House A / Unit 2, to: 38 % //
0023 - THEN Set X-10 House A / Unit 3, to: 38 % //
0024 - THEN Set X-10 House A / Unit 4, to: 38 % //
0025 - THEN Timer #0 = 0 // and stop timer
0026 - //
0027 - IF Timer #0 is > 480 // After eight minutes
0028 - AND Time of Day is < Sunrise offset 0 minutes // and after midnight
0029 - THEN Set X-10 House A / Unit 1, to: 0 % // turn lights off
0030 - THEN Set X-10 House A / Unit 2, to: 0 % //
0031 - THEN Set X-10 House A / Unit 3, to: 0 % //
0032 - THEN Set X-10 House A / Unit 4, to: 0 % //
0033 - THEN Timer #0 = 0 // and stop timer
0034 - //
0035 - IF Time of Day becomes = 00:00 // At midnight
0036 - AND Timer #0 is = 0 // if timer is not running
0037 - THEN Set X-10 House A / Unit 1, to: 0 % // turn lights off
0038 - THEN Set X-10 House A / Unit 2, to: 0 % //
0039 - THEN Set X-10 House A / Unit 3, to: 0 % //
0040 - THEN Set X-10 House A / Unit 4, to: 0 % //
0041 - //
0042 - IF Time of Day becomes = Sunrise offset 0 minutes // Turn all four lights off at sunrise
0043 - THEN Transmit X10, A - 1 //
0044 - THEN Transmit X10, A - 2 //
0045 - THEN Transmit X10, A - 3 //
0046 - THEN Transmit X10, A - 4 //
0047 - THEN Transmit X10, A - OFF (20) //
_________________________
Just Another Joe
Why be politically correct, when you can be right?

Top
#17570 - 02/23/07 09:27 AM Re: Could someone please look at this Ocelot code? [Re: Just Another Joe]
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6548
Loc: Montreal, QC, Canada
Les, what kind (brand and model) of switches do you have? If they work with commands like "THEN Set X-10 House A / Unit 1, to: 38 %" then they might also support scenes which would be easier for you to use, allowing them to all dim together to the desired level and by sending only one X-10 command (once the scenes are setup).

The other thing (aside from Joe's other useful suggestions) is to make sure you are looking for the right X-10 command. Your line:

AND Receive X10, A - 5 // and driveway sensor tripped

is looking for just the addressing part of what is normally a command pair. The Powerflash probably sends A/5 and A/ON when first tripped, followed by A/5 and A/OFF a few seconds later. In this case it might not matter much but you would be better off looking for the whole command pair using the "IF X-10 Status/Cmnd Pair" instruction, and look for the ON command pair like this:

AND X-10 A/5 ON Command Pair
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#17571 - 02/23/07 06:59 PM Re: Could someone please look at this Ocelot code? [Re: Just Another Joe]
Les Offline
newbie


Registered: 02/22/07
Posts: 9
Joe,

Thanks for the quick response. I have read your response and it really helps. I knew there was something wrong but could not really see it at the time.

One of my issues is the 'ELSE' command. I just can't seem to get my brain around that one. I see how you are using it but not sure why you are using it. I need to do some more research on this.

Concerning you question about the A5 from the driveway sensor getting a second trip and extending the 8 minute to something else, that is not a bad thing. If a number of cars come in 4 minutes apart the lights would stay up until 8 minutes after the last car. It would be more desirable in this mode.

Thanks for the adjusted code. I entered it today and it seems to work just fine.

I do have an additional question concerning these lines.

0020 - AND Time of Day is > Sunset offset 0 minutes // and before midnight

0028 - AND Time of Day is < Sunrise offset 0 minutes // and after midnight

This does work but I am a bit mystified since the statement and the associated commands are a bit over lapping unless the '> sunset' command is only good till midnight and the '< sunrise' command is only back till midnight. If so then it makes sense.

Also I wanted to use the 'GROUP' command for each light but either I have not found the correct 'click' to make or it is a non functional command. Any hints??

Again thanks and have a good day.

Les

Top
#17572 - 02/23/07 07:24 PM Re: Could someone please look at this Ocelot code? [Re: Guy Lavoie]
Les Offline
newbie


Registered: 02/22/07
Posts: 9
Quote:

Les, what kind (brand and model) of switches do you have? If they work with commands like "THEN Set X-10 House A / Unit 1, to: 38 %" then they might also support scenes which would be easier for you to use, allowing them to all dim together to the desired level and by sending only one X-10 command (once the scenes are setup).




Guy,

Thanks for your the response. The swithes are from ToggleLinc and I will have to check if they have the feature you describe. At this point since it is working thanks to the help from Joe, I will leave well enough alone.




Quote:

The other thing (aside from Joe's other useful suggestions) is to make sure you are looking for the right X-10 command. Your line:

AND Receive X10, A - 5 // and driveway sensor tripped

is looking for just the addressing part of what is normally a command pair. The Powerflash probably sends A/5 and A/ON when first tripped, followed by A/5 and A/OFF a few seconds later. In this case it might not matter much but you would be better off looking for the whole command pair using the "IF X-10 Status/Cmnd Pair" instruction, and look for the ON command pair like this:

AND X-10 A/5 ON Command Pair




Yes, I have the PowerFlash set to send A/5 upon contact clouser from the Cartel. And yes it does send a A/5 ON and then A/5 OFF. I do see what you mean using the Cmnd Pair but I think I will let well enough alone at this time. The next time I add something I will do some tweeking thanks to your input. Very helpful.

Again Thanks,

Les

Top
#17573 - 02/23/07 07:46 PM Re: Could someone please look at this Ocelot code? [Re: Les]
John Vomastic Offline
active contributor


Registered: 01/26/03
Posts: 151
Loc: Manitou Springs, Colorado
Quote:


Also I wanted to use the 'GROUP' command for each light but either I have not found the correct 'click' to make or it is a non functional command. Any hints??





You need to have the correct Leviton Switches in order to use GROUP commands

Open Cmax
From the COMMS pull down menu select ATTACH TO CONTROLLER
From the X10 pull down menu select SEND LEVITON X10
o Select a Group Number (0 to 64)
o Select the house code and key code for the switch or lamp module
o Enter the Brightness Level (0% to 100%)
o Click on the SET LIGHT LEVEL button. (Note: this step is easy to forget)
o Click on the INCLUDE IN GROUP AT THE CURRENT LEVEL button

Repeat the above steps until you have added all of the lights you wish to have in the group at the set brightness level.

You can now test to see if the desired lights and brightness levels have been entered correctly.
Select the desired Group Number
Click on the ENTIRE GROUP TO LEARNED LEVEL button
Check that all of the lights have come on (and only those lights in the Group) and that the brightness levels are satisfactory. If not, make the desired changes.
Click on the ENTIRE GROUP OFF button
Check that all of the lights have turned off (and only those lights in the Group)

Repeat the process for other Leviton Groups

The nice thing about the Leviton groups is that all of the lights come on together (not one at a time). Also they come to the desired level and remain there from above or below a previously set brightness level. They do NOT have to come to full brightness and then dim to the desired level. Each light in the group can be set at any brightness level.

A word of caution. Make a note of what lights are in each group and the corresponding light levels as you enter them. This information is not recorded in Cmax. I log the information in the COMMENTS column of the Cmax code after the END statement.

Top
#17574 - 02/23/07 08:09 PM Re: Could someone please look at this Ocelot code? [Re: John Vomastic]
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6548
Loc: Montreal, QC, Canada
John, he mentions having ToggleLincs. Depending on the exact model they might support scenes, but setting up scenes with Smarthome switches is different then with Levitons (and cannot use the handy Leviton scene setup utility in C-Max). But the commands to actually trigger the scenes are the same as for Levitons.
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#17575 - 02/23/07 09:01 PM Re: Could someone please look at this Ocelot code? [Re: Les]
Just Another Joe Offline
enthusiast
****

Registered: 09/02/03
Posts: 204
Loc: Adanac
Glad it's working for you, Les.

Quote:

One of my issues is the 'ELSE' command. I just can't seem to get my brain around that one. I see how you are using it but not sure why you are using it. I need to do some more research on this.




You could think of ELSE as being the opposite of THEN. After any (compound) conditional test, THEN statements will be executed only if the final result of the conditional(s) is TRUE; ELSE statements will be executed only if the final result is FALSE. Since the result remains in effect until another test (IF statement) is done, any number of THEN and ELSE statements may be used, and in any order. It is somewhat different than structured languages in which only one ELSE is allowed, and must come after the THEN.

The first ELSE (line 10) is saying if the test above was FALSE, then skip the following group of lines; i.e. if there hasn't been an A5 received during nighttime, then skip the group of lines from 11 to 18 which set the lights to full bright and start or restart the timer.

Within that group of lines (when A5 has been received at nighttime), the first thing that is done is to see if the timer is already running. If it is not, then the lights are set to full bright and the timer is started (the THEN statements). If the timer is already running, there is no need to set the lights since they must already be at full bright, and the THENs are not executed. If this is the case (timer 0 is not 0), then the test is FALSE and so the second ELSE (line 17) is executed; its purpose is to start the timer back at 1, to give the lights another eight minutes.

Quote:

I do have an additional question concerning these lines.

0020 - AND Time of Day is > Sunset offset 0 minutes // and before midnight

0028 - AND Time of Day is < Sunrise offset 0 minutes // and after midnight

This does work but I am a bit mystified since the statement and the associated commands are a bit over lapping unless the '> sunset' command is only good till midnight and the '< sunrise' command is only back till midnight. If so then it makes sense.




That is exactly correct. Since the clock rolls over to 00:00 at midnight, a value greater than sunset must be before midnight of that day, since once midnight is reached and the clock rolls over, then the value will be less than sunset (of the following day). Likewise, any time after midnight will have a value less than sunrise, until sunrise is reached.

Quote:

Also I wanted to use the 'GROUP' command for each light but either I have not found the correct 'click' to make or it is a non functional command. Any hints??




From what I could find on the Smarthome site (by ToggleLinc you did mean Smarthome switches, correct?), all the ToggleLinc dimmer switches are scene capable. I'm not familiar with using scenes with them, but I'm sure that Guy and John and many others here will be able to give you exact instructions on setting up those scenes. They really will make things much nicer, since as the others said, the lights will go on/off/dim/brighten together. And, you will save code space and execution time as well.
_________________________
Just Another Joe
Why be politically correct, when you can be right?

Top
#17576 - 02/24/07 09:54 AM Re: Could someone please look at this Ocelot code? [Re: Just Another Joe]
Les Offline
newbie


Registered: 02/22/07
Posts: 9
Quote:

Glad it's working for you, Les.




Thanks Joe.

And thanks for the info on the Sundown/Sunrise question. Originally I was not thinking that way but now it make sense. Very helpful.

Also the ELSE still needs some work but I am getting the idea. Practice - Practice - Practice

Thanks again had have a good weekend where ever you may be.

Les

Top
Page 1 of 1 1


Moderator:  Dan Smith, Monte G, ADI Tech Support, Guy Lavoie 
Hop to:
Who's Online
0 registered and 56 anonymous users online.
Recent Posts
am pm
by edr
05/05/17 05:25 PM
Shout Box

Newest Members
brigiel, vevevie, zhutree, 416, saiqul
3003 Registered Users
Forum Stats
3003 Members
19 Forums
3999 Topics
23425 Posts

Max Online: 132 @ 11/13/16 10:07 AM
May
Su M Tu W Th F Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31