Home Toys Article
- February 2006 -
[Home Page]

[Click Message To Learn More]

How to Build the
Ultimate Garage Door Monitor
 (For Your Home Automation System)

Remember, any amateur home automation enthusiast can tell you if the garage door is "open or closed" based on magnetic contact sensors, but a REAL home automation enthusiast can tell you within a few inches the EXACT position of the garage door itself!!


One critical monitoring element for any home automation system is the garage door.  There are many ways to do this including using your traditional magnetic contacts which will change state when the garage door is open or closed.  This method satisfies the minimal requirement of knowing the open/close status of the garage door.  But what happens if more detail about the garage door is needed?   For instance what can you do if you would like to know the exact position of the door (say if it got stuck during its open/close travel)?  What if you wanted to know this garage door position to within a few inches?

Background

There have been many posts on various forums on how to do this including using multiple magnetic contacts which open or short a chain of resistors in "series".  Thus when you bias this series chain with a voltage you will get a different voltage output depending on what magnetic contact the door has just passed.  The problem with this method is that the resistor doesn't "stay" open or shorted; it's just a momentary situation as the door passes the contact.  Plus the contacts would be a pain to install on your garage door's tract.  Also your "resolution" of knowing the exact position of the garage door would depend on the number of magnetic contacts installed.

This method will show a way to monitor your garage door's position using a "ten-turn" rotary potentiometer and an analog to digital (A-D) converter.  The end product will yield a voltage output that is proportional to the garage door's position; therefore the "resolution" or accuracy would highly depend on the analog to digital converter used.

Please note that if you only wanted to know if your garage door was "fully" opened or closed, much simpler methods should be chosen over this one (i.e. magnetic contacts as first described).  But, if you would like to know if your garage door did fully close, or if it got jammed in-between it's travel, or if you sometimes open your door partway and want to know the door's exact position it is currently in, then this articles may interest you.

This method uses "analog to digital" principles that are basically described to satisfy the build of this garage door monitor.  For a more detailed explanation, please refer to the CocoonTech.com's "How-To" Guide on "Analog to Digital Converters for Home Automation Applications" in the link below.

http://www.cocoontech.com/index.php?showtopic=2827

Theory

I initially came up with this idea by studying exactly "what" moves with the garage door when it opens and closes.  I noticed that the metal pipe which holds the garage door's large coiled spring (over the top length of the garage door) turns multiple times as the garage door is moving (see below).  Of course, if your garage door does not operate in a way that has a rotating pipe, this method may not work without alterations.

Inside View of Garage Door

I marked the pipe with a marker and counted the number of times the pipe rotated during the entire garage door travel from open to close.  Mine rotated between six and seven times.  I also noticed that the end of the pipe was hollow. 

Well, this had me thinking about a way to monitor this "rotary" movement as it should be linear with the garage door's travel.  In other words, the amount of times the pipe rotated can be compared to the amount the garage door has "opened" (more on this later).

I now needed to somehow mount something on that pipe that would change a voltage (linearly) as it turned.  Since the end of the pipe was opened (i.e. not a solid end) I elected to use a ten turn rotary potentiometer for this purpose.  The potentiometer (pot) would not get "bound" up as the pipe only turned less than six rotations (and the pot incorporates "ten" turns).  Also, the one I had laying around was a good "Bourns" ten-turn, wire wound, linear pot whose value went from zero to 100 ohms as the center shaft rotated.  The Bourns part number is 3540s-1-101-ND.

Bourns Ten-Turn Potentiometer

You can obtain this pot from DigiKey (enter that part number in their "part search" dialog box on their main site).  Their price is $13.38 plus shipping.

Methodology

In order to get a voltage value from this potentiometer a DC Power Supply is needed to supply a "bias" voltage.  Thus as the shaft of the pot turns the pot's output voltage would vary.  This voltage would then be measured with an analog to digital converter, thus converting this voltage to a "bit" number whose value would correspond with the voltage reading.  This "bit" value would then be converted to "inches" via home automation software.

I already had a 10-bit analog to digital converter from PH Anderson incorporated into my home automation system (http://phanderson.com/adc180/adc180.html).

Other digital to analog converters can be used as well.  This one from DataQ (http://www.dataq.com/194.htm) offers four ten-bit channels.  Also analog to digital conversion capability is included with systems such as an Elk M1 Gold (from Elk Technologies) and an Ocelot (from Applied Digital) with an SECU16 expansion module (though the last two are only eight bit systems).

As described above, you may want to reference this guide for detailed information on how analog to digital converters work and how to formulate equations to obtain real world (in this case inches) numbers into your home automation system.

The monitoring methodology would thus be:

  1. Mount the rotary potentiometer on the end of the pipe as mentioned above
  2. Wire a DC Power Supply to the "coil" sides of the potentiometer
  3. Monitor the output voltage of the pot with an analog to digital converter
  4. Supply an algorithm (equation) to convert this voltage to inches (that the garage door is "opened")

Preliminary Testing

There are a couple of variables here that need to be mentioned depending on your integration hardware you are planning to use.  For instance in my case, the PH Anderson analog to digital converter can only accept a maximum of five volts for its channel's input value.  This will influence the maximum voltage that I will excite the potentiometer with. 

Another factor to consider is that this is a "hardwired" system.  In other words you need at least one pair of wires to go from the potentiometer to wherever your analog to digital converter is mounted.  Since this wire length may be substantial it is a good idea to also "tailor" your potentiometer's bias voltage setting so it outputs the maximum permissible value during the entire travel length of the garage door (i.e. bias with the highest allowable voltage value).  This will also keep noise influence to a minimum as well as increase accuracy of the system (I noticed that my analog to digital converter was slightly non-linear for very low voltage levels).

Let me explain this step in detail as it is important.  I wanted a maximum reading of five volts for my analog to digital converter since this was its maximum permissible input as stated above.  I have a lot of DC voltage "Wall Warts" that I accumulated over the years (voltage converters that you plug into your wall to operate small electronic devices). 

I selected a wall wart that stated a 5 volt output.  I then wired this up to my potentiometer as shown below.  Note that an in-line fuse was added for safety, even though you are dealing with very small DC voltage levels.  These in-line fuse holders can be purchased from a variety of sources including Radio Shack.

Since I'm using a 5 volt supply and biasing a 100 ohm potentiometer, the current I will draw from the wall wart is calculated using the equation:

Current  =  Voltage / Resistance, or 5/100, which equals 0.05 amps (50 milliamps).

Therefore you can select a very small fuse for your in-line fuse holder.

The power that will be dissipated by the potentiometer is calculated using the equation:

Power = Voltage * Current, or 5 * 0.05, which equals 0.25 watts (one-quarter watt).  Note that the potentiometer I selected will handle up to two watts.

I then bench tested the potentiometer, wall wart, and fuse holder by wiring them according to the schematic below.

Schematic Diagram

This setup was then tested by connecting a DC voltmeter on the potentiometer's output connections (as shown on the schematic).  As the potentiometer turns the voltage should change accordingly. 

You may want to also perform a quick test of your analog to digital converter by connecting the output of the potentiometer to your analog to digital converter's input channel and see if the corresponding bit output from the computer screen correlates properly with the voltage measured by the meter.  This would give you a feel for how to use your analog to digital converter as well as test its linearity.

If you need additional information on how to convert from bits measured by the analog to digital converter to a voltage value (or vice versa) please refer again to the Analog to Digital Converters guide described above.  I would also plot your results as a double check that a straight line can be drawn between your "data points" in order to verify linearity.  More on this later below.

Now you need to determine whether you need a clockwise or counterclockwise rotation on the shaft of the potentiometer to increase your voltage output.  Carefully watch the pipe above the garage and note which direction it turns when the garage door opens.  Also watch with closer accuracy on how many rotations are used.  I wanted the voltage to increase as the garage door was opened, but either way would work.

After you get a feel for how this works you may want to determine the shaft's "turn" position that you want the potentiometer to be at when the garage door is opened (i.e. the voltage that the potentiometer will read when the garage door is fully opened).  The way I determined this is that I rotated the potentiometer's shaft till I obtained the maximum (limited out) voltage output reading from the meter as connected in the above described test.  I then backed off a little less then a half turn.  I then noted the output voltage to insure that this reading was below the maximum allowable input of my analog to digital converter. 

If the reading is to high, back off on the potentiometer until you get below this value (for me it was five volts maximum input so I had the potentiometer read 4.90 volts).  This not only insured that I would never get above my maximum voltage, but also insured that I had enough "play" or rotation length left in the pot so that I would never be able to "bind" the pot when the garage door was in its maximum open position.  Also note that I wanted to get somewhere in the ballpark of over four volts since I wanted to have a reading well above the noise level when the garage was lowered. 

You can test this value as well by turning the pot the maximum number of rotations that your garage door pipe rotates and see what this value would be.  Since we know that this is a ten turn pot and that the garage pipe rotates a number well under ten, there is no way that we would be able to "bind" the pot past its lower position when the garage door closed.

Note these upper and lower (garage door opened and closed) potentiometer values for later reference.

This is why we tested both the travel and maximum voltage the pot would see when the garage door is in the "opened" position (important knowledge for when we mount the pot to the pipe end).

Turn the potentiometer to this new "garage door opened" position and maybe even put a piece of tape between the pot and its shaft to "keep" this position in place.  During the course of following the hardware installation instructions below, you can always double check this reading/position.

Hardware Installation

I purchased some solid rubber corks/stoppers/plugs from my local hardware store (Home Depot).  This rubber plug will be used to mount the shaft of the potentiometer to the end of the hollow round pipe that turns when the garage door moves.  The rubber plug that I wound up using was one inch long in length and had a one inch diameter on its larger round end.  This web site, http://www.stockcap.com/prod_detail.asp?id=140&cat=18 has an excellent selection of rubber plugs of various sizes AND they will even send you a free sample on request!  This rubber plug would then be "jammed" inside the end of the pipe as pictured below.

Testing Rubber Stopper's Fit

Rubber Stopper Mounted on Pipe

Now that you know the rubber stopper will mount properly to the pipe's end it's time to work on interfacing it to the potentiometer's shaft.  To do this I selected a drill bit whose diameter was slightly undersized from the pot's shaft diameter.  I then drilled a hole in the large diameter end of the rubber stopper as shown below.  It is VERY important to make sure this hole is centered on the rubber stopper's round end. 

Drilling Hole in Rubber Cork

Now that the hole is drilled test fit the potentiometer by inserting its shaft into the rubber stopper's end.  This fit needs to be very snug so no slipping can occur between the rubber cork and the shaft.  You can always go with a larger drill bit if the shaft just will not fit.

Pot Mounted to Rubber Cork

Now solder long wire leads to each of the potentiometers connections referencing the above schematic.  Use shrink tubing over the connections and wire ends.  Insure that you have the proper clockwise/counterclockwise selections for connections 1 and 3.  Note that you will probably need to use a nearby outlet for the wall wart (unless you are running this voltage from the analog to digital converter's location) so make your wire leads are long enough to reach.  Also, use different color wire or mark the wire ends so you know which are the proper ones to use for the wall wart and which ones to use for the analog to digital converter's input.

Obtain a 3/4 inch "EMT" metal conduit holder from a hardware store as shown below.

Conduit Holder for Pot's Mount

Next, mount the potentiometer inside this conduit holder as shown below.  Insure that the leads from the pot are isolated from the metal of the conduit holder.  I had to "slightly" bend the back lead a bit.

Pot Mounted to Conduit Holder

Now temporarily mount this unit to the garage door's pipe end using the rubber stopper as shown below.

 Test Mount to Pipe's End

To mount this pot/conduit holder to the garage door end, I used a metal mounting strap (same style/type of metal strap that is used to suspend my garage door opener unit from the ceiling) that I bent as shown below.  You can take some measurements while the potentiometer/conduit holder is temporarily installed to see what means are needed.  I elected to use the channel of the garage door directly below to mount this assembly to (via this mounting strap).  I cut the strap to length, bent it 90 degrees in two places and then bolted the conduit holder onto the metal strap as shown below.  The plethora of holes these straps provide make it easy to obtain a properly oriented mount to the garage door's upper pipe end.

Final Mount/Holder

Now make sure the rubber stopper is jammed tightly into the garage door's pipe end.  I used a rubber mallet.  OPEN the garage door.

Insure the potentiometer's shaft position is at the same "garage door opened" position during your testing above (you did place a piece of tape on it right?).

Install the above assembly onto the garage door channel and rubber stopper.  Insure that the unit is centered with the pipe and that the pot's shaft is fully inserted into the rubber stopper.  Some "fine tuning" may be necessary in order to accomplish this by adjusting the bends of the metal strapping used to mount the pot/conduit holder to the garage door's channel.

 

Assembly Mounted to Garage Frame

Close up of Final Mount

Close the garage and note how this assembly travels.  If excessive "swaying" back and forth occur, you may have to re-adjust the alignment to the pipe.  If this does not work your hole placed in the rubber stopper may not be centered.  The assembly will have a "little" play though the garage door's travel.  This is why a rubber mounting method to the pipe shaft was chosen.  Also, the metal strapping will let the assembly "ride" a certain distance up and down during the travel cycle as well.

Obtaining Data

Once you are satisfied with the way the potentiometer assembly is mounted to the pipe end you may now test the system by seeing how linear the relationship is between the potentiometer's output and the bottom garage door's distance from the floor.

Connect a voltmeter (set to measure DC Volts) on the output of the potentiometer and then plug the wall wart into an AC outlet.  Open the garage door and note the voltage on the meter.  Close the garage door and note the voltage on the meter.  Did it decrease as the garage door closed?

Now it's time to take some data!  You will do this by running the garage door to various stopped distances (above the floor) and record the distance  the bottom of the garage door is from the floor along with the voltmeter reading (from the potentiometer)  for that distance.  Divide the garage door travel distance up to about eight different intervals, then move the bottom of the garage door to that interval and take a voltage reading as well as measure (in inches) the distance between the bottom of the garage door and the floor.  Note that for my first test (pictured below) I just used a variable DC power supply instead of a wall wart (since I was just playing around to see if this concept worked). I did retake this data once I determined which exact wall wart I was going to use for the final installation though.

Close up of Final Mount

To see how linear your data is you need to plot it on a graph.  If a straight line can connect the data points, then you have a great linear relationship.  This is important for when we determine an equation of this line in order to read total inches with our Home Automation software (more on this later).

The easiest way to plot numbers is to use Microsoft Excel, though you can just use regular graph paper as well.  The table and graph below show my results.

Data Set & Graph

Doing the Math

As you can see the line is fairly straight.  If you did not obtain a straight line from your plotted results, you may want to retake the data.  Other than that you may want to try to change your voltage (bias) range.  Also, make sure the potentiometer and rubber stopper are not "slipping" while the door is in travel.

If the data line is not straight you will have difficulty solving for an equation to represent that line.  An equation is needed in order to calculate the analog to digital voltage reading to an inch number via your home automation software.

Now you can create an equation to represent this line.  Please note that these instructions are described in detail in the Analog to Digital Converters Guide described above. 

This equation would solve for distance (inches) when given a voltage value.  You could then convert this voltage value to bits which are what would be read for your analog to digital input.  In short a total calculation would convert "bits to voltage to inches".

One easier way to do this conversion would be just to retake the data but connect the potentiometer to an input channel of your analog to digital converter and record BITS instead of VOLTAGE.  In other words you would do the exact same test as above, but instead of taking a voltage reading from a DC meter, you would just record the raw bits from the computer that is connected to the analog to digital converter.  This would prove both that your potentiometer output was linear AND that your analog to digital converter was linear at the same time.

Testing the Analog to Digital Converter

Connect your analog to digital converter to your computer via its proper interface.  In my case using my PH Anderson A-D board, a serial port was used.  This board will echo all eight channels of its outputs in raw bits after it receives any ASCII character from the serial port. 

HyperTerminal was used to read the channel bit values.  Power was also applied to the board.  The proper baud and communication settings were made and a carriage return was sent to the board.  Indeed the eight channel's bit values were echoed back on the computer screen.

I then retook the garage door data.  I just hit a carriage return after moving the garage door to a certain level and read channel one's bit value.  I then recorded this bit value along with the distance the garage door was from the floor.  A plot was then made of the bit value vs. the garage door's position above the floor (in inches).

Data Set & Graph

Again you can see that a straight line was obtained. 

Finalize all of your wiring and routing and mount your analog to digital converter and connect it permanently to your home automation computer.  Insure all wires are routed properly so they do not interfere with any garage door operation.  Connect the potentiometer output wires to the analog input channel.  Plug the wall wart into its designated outlet.

Develop the Software Interface

Now that you are finished with the hardware interface it is time to work on the software.  This software will convert the bits displayed on your analog to digital converter to inches (that the garage door bottom is above the floor).

If you have any problems with the instructions below, please post your data obtained and I'll help you through the rest of this procedure.

The slope intercept formula of Y = mX + b will be used with Y being the bit value and X being the inches the garage door is from the floor value.

To solve for m (slope) and b (Y intercept) we need to select two data points from the graph above.  I like to select two data points just inside the max and min values so the following points (X, Y Pairs) will be used (again these values are read directly off of the data graph/chart above).

10.5, 276

68, 856

Solve for m using the equation:

m = (Y2 - Y1) / (X2 - X1) or (856 - 276) / (68 - 10.5) or 580 / 57.5 or 10.087

The b intercept can be calculated using Y = mX + b and substitute the m value above with the first data point used (in this case 10.5, 276).

276 = 10.087 (10.5) + b

Solving for b yields b = 276 - (10.087 * 10.5) or 161.865

So now our equation can be represented by:

Y = mX + b

Y = 10.087X + 161.865

Since Y represents BITS and X represents INCHES, we can rewrite this equation as follows:

BITS = 10.087 (INCHES) + 161.865

Since we will know the BITS from the Analog to Digital converter, we must solve the above equation for INCHES (the unknown variable).  Rearranging the above equation yields.

INCHES = (BITS - 161.865) / 10.087 or

[b][SIZE=7]INCHES = 0.099 * BITS - 16.05[/b][/SIZE]

Test this calculation by using another X,Y pair from the graph above.  Let's take the pair 57,752.

If we use the equation above to solve for INCHES knowing the BIT number we get

INCHES = 0.099 * 752 - 16.05 which yields 58.4 which is pretty close to 57 (the corresponding X value)

Lets further test this calculation using another X,Y pair from the data above.  This time let's use pair 20.5, 375.

INCHES = 0.099 * BITS - 16.05

INCHES = 0.099 * 375 - 16.05, which yields 21.08 which is pretty close to 20.5 (it's corresponding X value).

Final Accuracy Test

Now that you can convert a bit number from the analog to digital converter to real world inches, test the final accuracy of your measurement system.  Move the garage door to a position say 1/3 of the way open.  Read the bit value from the analog to digital converter.  Using the above equation INCHES = 0.099 * BITS - 16.05, calculate the expected inches result.  Then measure the actual distance the bottom of the garage door is from the floor and it should match this value very closely.

Continue this test for other open stages of the garage door (say 1/2. 2/3, and 3/4 open).  Also check the fully closed and fully open positions.  These results will let you know the relative accuracy you can expect for your system.

Please note that several factors will determine the accuracy and repeatability of your system, most importantly the total bits of your analog to digital converter.  If you have an eight bit converter vs. a ten bit your resolution would be less and repeatable results would be more sporadic (though within a certain "window" range).  Again, please refer to the guide Analog to Digital Converters for further details.

The PH Anderson Analog to Digital Converter

As mentioned earlier, I am using this http://phanderson.com/adc180/adc180.html PH Anderson eight channel 10-bit analog to digital converter.  The unit is $40 plus $6 shipping.  I also emailed Mr. Anderson and asked for a version so all of the eight channels of bit data is in one line, rather than the two separate lines as shown in its literature.  This made the serial program to retrieve the specific bit channels of data a lot easier to write.

The main advantage this unit has over other analog to digital converters included in the Ocelot's SECU16 and the Elk M1 Gold is its ten bit accuracy vs. just the eight bits included with those other two systems.  I also wanted the additional ten bit resolution channels for other projects as well.  I would also like to add that I found corresponding with Mr. Anderson via email to be a very pleasant experience. 

Integrating With Home Automation Software

The following paragraphs describe how to set this data up using Homeseer (http://homeseer.com) and Main Lobby (http://www.cinemaronline.com/mainlobby.html) home automation software.  Though the code and instructions are specific to these packages, the techniques could be modified for other methods.

I currently use HomeSeer ver 1.7.43 with Main Lobby for my visual displays.  In order to integrate the PH Anderson Analog to Digital Converter I had to create a couple of scripts.  These scripts also incorporated the equation determined above which converted the bit number to inches that the bottom of the garage door was above the floor.

First, two scripts are required for the PH Anderson Analog to Digital Converter.  One script sets up the serial port and polling, and the other actually acquires the data from the channels.

I currently have the PH Anderson's board on serial port number ten, but had to use serial port number three's resources.  This is partly because I have two on-board serial ports on my HomeSeer's computer and also incorporate an Edgeport 8 serial expander.  The serial ports start at Com1 and Com2 for the on-board motherboard's ports, but then skip to Com5, Com6, Com7, Com8, Com9, Com10, Com11, and Com12 for the Edgeport's serial ports.  I simply could not get any programs working within HomeSeer using any OpenComPort or CloseComPort with that higher serial port number (so I therefore used Com Port 3's resources since Com3 and Com4 were not used in my system).

I created HomeSeer devices (device type "interface variable") R1 through R8 which will represent the value of the eight channels of the PH Anderson Analog to Digital Converter.

To set this serial interface up I incorporated the following VB Script below.  Note that two resources I found handy while writing this code were the ASCII Lookup Tables and Microsoft's Visual Basic Scripting Guide.

[CODE]

sub main() 'Analog board connected to Com 10, but using Com3's "resources"!

hs.CloseComPort(3)

e=hs.OpenComPortex(10,"9600,n,8,1",1,"analogdatanew.txt","Fran", chr(10), 3)

if e<> "" then msgbox "Error opening COM10: " & e

hs.SendToComPort(3), chr(100) 'you can send "ANY" data to the comm port to get data back

hs.waitsecs 2

hs.CloseComPort(3)

end sub

[END OF CODE]

This program opens the com port, calls the subroutine "Fran" in the "analogdatanew.txt" script (which it will pass the data to), then sends an ASCII character 100 (any ASCII character will do) to the A-D board so it will echo the data back via the serial port.

I then setup an event in HomeSeer which runs every 20 seconds that calls the above script (as shown below).  The timing of the run cycle will depend on your specific application.

HomeSeer Event Setup

The details of the analogdatanew.txt script are listed below:

[CODE]

sub Fran (data)

dim myArray

dim i

dim x

dim hc

i = 0

'data separated by spaces, but actual number of spaces between data points change depending on the "bit" value (0 to 1024)

myArray = Split(data," ", -1, 1)

for x = 0 to ubound(myArray)  'Get "data" into the array "myArray"

    If myArray(x) <> "" Then

            i = i + 1

  Select Case i 'This selects Homeseer device house codes for data channels

            Case 1

    hc = "r1"

    myArray(x) = 0.099 * myArray(x) - 16.05  'Calculation Converts Bits to Inches Garage Door is From the Floor

            Case 2

    hc = "r2"

            Case 3

    hc = "r3"

            Case 4

    hc = "r4"

            Case 5

    hc = "r5"

            Case 6

    hc = "r6"

            Case 7

    hc = "r7"

            Case 8

    hc = "r8"

    myArray(x) = 0.486 * myArray(x) 'LM34 Temp Convert

  End Select

            hs.setdevicevalue (hc), myArray(x) 'write data to Homeseer device

            hs.setdevicestring hc, myArray(x)  'write string to Homeseer device

    end if

next

end sub

[/CODE]

Note that HomeSeer device R1 will now contain the inches the garage door is from the floor.  Also note that this value was written in the device value and string as well.

Also, for what it's worth,  notice that I have an LM34 temperature probe installed on channel 8 of the PH Anderson Analog to Digital converter and show the necessary calculation to convert this reading to "degrees F" which is written to the HomeSeer device R8 (showing the versatility of this A-D board).

Well now we have a HomeSeer device which shows the value in inches, but wouldn't it be nice to know the "percent" the garage door is opened?  In other words is the garage door half-way open, 80% open, etc  This may be more useful than knowing the actual inches.

This percentage number is easy to calculate.  When my garage door is fully opened the bottom of the door is 83 inches from the floor.  This represents being 100 percent opened.  Of course when the garage door is closed its bottom is (approximately) zero inches from the floor.  This represents zero percent opened.  Now we need to express the actual inches measured as a percentage based on these two limits.  To do this we need to divide the inch reading from the maximum 83 inch number, and then multiply that result by 100.  In other words the equation would be:

Percent Open = Inches / 83 * 100

I also created a HomeSeer interface variable device R9 which will represent this "percent open" number.  The code is incorporated below (gdpercent is the variable that represents this percent open value).

[CODE]

sub Fran (data)

dim myArray

dim i

dim x

dim hc

dim gdpercent 'Percent that the garage door is opened

i = 0

'data separated by spaces, but actual number of spaces between data points change depending on the "bit" value (0 to 1024)

myArray = Split(data," ", -1, 1)

for x = 0 to ubound(myArray)  'Get "data" into the array "myArray"

    If myArray(x) <> "" Then

            i = i + 1

  Select Case i 'This selects Homeseer device house codes for data channels

            Case 1

    hc = "r1"

    myArray(x) = 0.099 * myArray(x) - 16.53  'Calculation

    gdpercent = ((myArray(x)/83.0) * 100)  'Convert to percentage open

    hs.setdevicevalue "r9", gdpercent 'write data to R9 Device

    hs.setdevicestring "r9", gdpercent  'write string to R9 Device

            Case 2

    hc = "r2"

            Case 3

    hc = "r3"

            Case 4

    hc = "r4"

            Case 5

    hc = "r5"

            Case 6

    hc = "r6"

            Case 7

    hc = "r7"

            Case 8

    hc = "r8"

    myArray(x) = 0.486 * myArray(x) 'LM34 Temp Convert to Deg F

  End Select

            hs.setdevicevalue (hc), myArray(x) 'write data to Homeseer device

            hs.setdevicestring hc, myArray(x)  'write string to Homeseer device

            'hs.writelog "Channel", hc

            'hs.writelog "Data", myArray(x)

    end if

next

end sub

[/CODE]

Wow, we now have two HomeSeer devices which show garage door monitor information.  One device (R1) shows the actual inches the bottom of the garage door is from the floor.  The other device (R9) displays the "percent open" or the percentage the garage door is opened.

You can now use these values to trigger other events or code as you wish.  For instance you may want to trigger an event which calls you after a certain amount of time after you open or close the garage door in case it doesn't open or close fully (garage door opener gets jammed).

Since I have Main Lobby incorporated into my HomeSeer automation system, I wanted a cool display which represented exactly where the garage door was or in other words, graphically show its percent open condition.  I could do this very easily by showing the percent open number as a variable for a slider, but this didn't look much like a garage door.

Well, my Main Lobby friend "Fungun" (aka Tim) came to my rescue by making a series of garage door jpg images (11 total) which showed a white, double car garage door in various stages of "open".  I renamed these images as garage1.jpg (fully opened), garage10.jpg (10% open), garage20.jpg (20% open), etc all the way up to garage100.jpg (fully opened).  Now all I have to do is pass the "garage door percent" HomeSeer device value as a variable to Main Lobby ("range"), then do a condition statement based on the value of this device and display the proper jpg on my Main Lobby scene.

The code which incorporates this feature is shown below.

[CODE]

sub Fran (data)

dim myArray

dim i

dim x

dim hc

dim gdpercent 'Percent that the garage door is opened

i = 0

'data separated by spaces, but actual number of spaces between data points change depending on the "bit" value (0 to 1024)

myArray = Split(data," ", -1, 1)

for x = 0 to ubound(myArray)  'Get "data" into the array "myArray"

    If myArray(x) <> "" Then

            i = i + 1

  Select Case i 'This selects Homeseer device house codes for data channels

            Case 1

    hc = "r1"

    myArray(x) = 0.099 * myArray(x) - 16.53  'Calculation

    gdpercent = ((myArray(x)/83.0) * 100)  'Convert to percentage open

    hs.setdevicevalue "r9", gdpercent 'write data to R9 Device

    hs.setdevicestring "r9", gdpercent  'write string to R9 Device

'Determine Garage Door jpg to display based on percent garage door is opened     

If gdpercent < 3 then

hs.plugin("MLHSPLugin").MLServeCMD "MLServeCMD.SetVariable|range~c:\Program Files\Cinemar\images\garage1.jpg"

elseif gdpercent >= 2 and gdpercent < 10 then

hs.plugin("MLHSPLugin").MLServeCMD "MLServeCMD.SetVariable|range~c:\Program Files\Cinemar\images\garage10.jpg"

elseif gdpercent >= 10 and gdpercent < 20 then

hs.plugin("MLHSPLugin").MLServeCMD "MLServeCMD.SetVariable|range~c:\Program Files\Cinemar\images\garage20.jpg"

elseif gdpercent >= 20 and gdpercent < 30 then

hs.plugin("MLHSPLugin").MLServeCMD "MLServeCMD.SetVariable|range~c:\Program Files\Cinemar\images\garage30.jpg"

elseif gdpercent >= 30 and gdpercent < 40 then

hs.plugin("MLHSPLugin").MLServeCMD "MLServeCMD.SetVariable|range~c:\Program Files\Cinemar\images\garage40.jpg"

elseif gdpercent >= 40 and gdpercent < 50 then

hs.plugin("MLHSPLugin").MLServeCMD "MLServeCMD.SetVariable|range~c:\Program Files\Cinemar\images\garage50.jpg"

elseif gdpercent >= 50 and gdpercent < 60 then

hs.plugin("MLHSPLugin").MLServeCMD "MLServeCMD.SetVariable|range~c:\Program Files\Cinemar\images\garage60.jpg"

elseif gdpercent >= 60 and gdpercent < 70 then

hs.plugin("MLHSPLugin").MLServeCMD "MLServeCMD.SetVariable|range~c:\Program Files\Cinemar\images\garage70.jpg"

elseif gdpercent >= 70 and gdpercent < 80 then

hs.plugin("MLHSPLugin").MLServeCMD "MLServeCMD.SetVariable|range~c:\Program Files\Cinemar\images\garage80.jpg"

elseif gdpercent >= 80 and gdpercent < 90 then

hs.plugin("MLHSPLugin").MLServeCMD "MLServeCMD.SetVariable|range~c:\Program Files\Cinemar\images\garage90.jpg"

elseif gdpercent >= 90 then

hs.plugin("MLHSPLugin").MLServeCMD "MLServeCMD.SetVariable|range~c:\Program Files\Cinemar\images\garage100.jpg"

end if

            Case 2

    hc = "r2"

            Case 3

    hc = "r3"

            Case 4

    hc = "r4"

            Case 5

    hc = "r5"

            Case 6

    hc = "r6"

            Case 7

    hc = "r7"

            Case 8

    hc = "r8"

    myArray(x) = 0.486 * myArray(x) 'LM34 Temp Convert to Deg F

  End Select

            hs.setdevicevalue (hc), myArray(x) 'write data to Homeseer device

            hs.setdevicestring hc, myArray(x)  'write string to Homeseer device

            'hs.writelog "Channel", hc

            'hs.writelog "Data", myArray(x)

    end if

next

end sub

[/CODE]

I copied all of the garage jpg images into my "cinemar/images" directory.  I then created a library button on my Main Lobby scene and pointed its label to this "range" variable.

Main Lobby Button Dialog Settings

The results of this Main Lobby display are shown below. 

Scene with Garage Door 20% Open

Scene with Garage Door 50% Open

Scene with Garage Door 80% Open

Conclusion

That concludes this How-To on building the ultimate garage door monitor.  Remember, any amateur home automation enthusiast can tell you if the garage door is "open or closed" based on magnetic contact sensors, but a REAL home automation enthusiast can tell you within a few inches the EXACT position of the garage door itself!!

Why do you need to know this information, well, because you now CAN!!

My setup has been working for months and it is nice to know the position of the door, especially in the summer months when we "crack" this door to let some air in.  Also, many people have expressed this interest because they occasionally have their garage door openers jam, and come home to an open door at the end of their work day!

Comments (0)

This article does not have any comments. Be the first to leave a comment below.

Post A Comment

You must be logged in before you can post a comment. Login now.

More AV and Automation Industry Resources

 

 

More Technical eMagazine from LJB