Announcement

Collapse
No announcement yet.

MultiPress Script for 2-Way Switches

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    MultiPress Script for 2-Way Switches

    UPDATE 07Aug03
    The script has been significantly rewritten. Now, there is no need to employ a virtual device to store keypresses. The sript will manage keypresses internally. This capability is enabled by remaining active during the period that a keypress is expected.
    To do this, I have created a Do-Loop that continually checks keypresses. Here is the active portion of the script:
    <pre class="ip-ubbcode-code-pre">
    do ' do loops can be dangerous!
    hs.waitevents ' keeps HomeSeer happy
    if hs.LastX10 &lt;&gt; "" then
    bCommand = hs.LastX10 ' we want to get a valid X10 response
    if instr(bCommand, myHouseBase) then ' only take what is ours.
    localArray = split(bCommand, ";")
    ' the structure here is essentially HcUc DevCmd or "E1 DevOn", or "E2 DevDim", etc.
    StatStr = StatStr & "," & localArray(1) & " " & arrayDevCmd(cint(localArray(2)))
    ' if you want to do things on a "Global action" i.e. (Hc) = "M" then use this:
    GlobalStr = GlobalStr & arrayDevCmd(cint(localArray(2))) & " "
    hs.ClearLastX10 ' clear it for the next one
    localTimer = Timer ' reset the timer
    aCounter = aCounter +1
    end if
    end if
    if Timer &gt; localTimer + localTimeout then exit do
    ' if you have a need for more than 3 presses, increase the number
    ' remember to test for greater than "&gt;", starting at zero (0), so you would
    ' be 2 less than the actual key count.!
    if aCounter &gt; 1 then exit do ' let's let 3 presses do the trick
    loop

    </pre>
    A timer is used to break out of the loop if a period of 2 seconds passes without a keypress. Whenever a keypress is received then the timer is reset. If three keypresses are accumulated, then the Do Loop is also exited.
    There now is a need to also define the HouseCode (Hc). Lines 9 and 10:
    <pre class="ip-ubbcode-code-pre">
    Const myHouseCodes = "M1 M2 M3 M4 M5" ' Define acceptable house codes
    Const myHouseBase = "M" ' this is for evaluating hs.LastX10 stuff
    </pre>
    Be sure you define the keys that will be detected, seperating each one with a space, and then be sure to define the HouseCode(s).
    You must create an event that will trigger on a HouseCode, Any Device, any command. If you plan to use this script for more than one HouseCode (Hc), then create an event for each HouseCode. The name is not important.

    The actions take place in the following sub:
    <pre class="ip-ubbcode-code-pre">
    ' **************************** PROCESS KEYPRESS ************************************
    sub EventProcessor
    ' Select Case GlobalStr ' new method!
    Select Case StatStr ' new method!
    ' Process Master Wall Switch keys
    Case "M1 DevOn,M1 DevOn", "M1 DevOn,M1 DevOff" ' double
    hs.execX10ByName "Master Bed Room Bath", "On"
    hs.execX10ByName "Master Bed Room Closet", "On"

    Case "M1 DevOn,M1 DevOn,M1 DevOn", "M1 DevOn,M1 DevOn,M1 DevOff" ' tripple
    hs.execX10ByName "Master Bed Room Bath", "On"
    hs.execX10ByName "Master Bed Room Closet", "On"
    hs.execX10ByName "Master Bed Room Dennis Table Lamp", "On"
    hs.execX10ByName "Master Bed Room Young Table Lamp", "On"

    Case "M1 DevOff,M1 DevOff" ' double Off
    hs.execX10ByName "Master Bed Room Bath", "Off"
    hs.execX10ByName "Master Bed Room Closet", "Off"

    Case "M1 DevOff,M1 DevOff,M1 DevOff" ' tripple off
    hs.execX10ByName "Master Bed Room Bath", "Off"
    hs.execX10ByName "Master Bed Room Closet", "Off"
    hs.execX10ByName "Master Bed Room Dennis Table Lamp", "Off"
    hs.execX10ByName "Master Bed Room Young Table Lamp", "Off"

    'etc...
    </pre>
    The code is lengthy, but I wanted to show a thorough example. If you are using more than one HouseCode (Hc), then you should use the structure presented above. All that is needed is to define the Device (M1) and the action (DevOn or DevOff). Seperate the HouseCode from the Action with a space, then add a comma after the action. No space is necessary before the next HouseCode. I.E. M1 DevOff,M1 DevOff,M1 DevOff
    If the conditions of the case are met, then the actions will trigger. You may define more than one set of conditions, and you may define any number of actions. The Case statements may be just short of limitless. Be sure you have an End Case at the end.

    regards,
    GenevaDude...

    -----Original Message ---------------------
    MultiPress is a script that reads keypresses from 2-Way switches. It was primarily designed with the SwitchLinc wall switch but ought to work with almost any 2-Way wall switch.

    What it does is read "keypresses" and determines actions based on key sequencing. So, if you press a wall switch "On On", you can make other lights turn on. If you press "On On On" you can make other actions occur. The capability is only limited by your imagination.

    When I go to work, I press the MBR wall switch Off three times and it turns off all the lights in the MBR. You could also have it turn off the MBR TV, turn on lights in other parts of the house. It can do most anything you can imagine, within the confines and capabilities of HomeSeer.

    Keep your sequences simple and logical.

    Have fun.

    The discussion thread is here.

    regards,

    GenevaDude

    [This message was edited by GenevaDude on Thu, 07 August 2003 at 09:36 PM.]

    [This message was edited by GenevaDude on Thu, 07 August 2003 at 09:38 PM.]
    Attached Files
Working...
X