Announcement

Collapse
No announcement yet.

Script Snippit .. thought it might be useful

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

    Script Snippit .. thought it might be useful

    I wanted to perform different actions in response to multiple presses of a single button on a keychain remote..

    Example..
    On first press of button.. announce over speakers what the "wake-up" time is tomorrow morning..

    If the button is pressed again in the next 5 seconds... add an hour to the "Wake-up" ... and announce the new time over the speakers..

    i haven't gotten it all done yet (Modifying event run times?) ... but i did get the part working that causes different actions to happen in response to repeated keychain remote button presses...

    I came up with the following:

    It can be copied into a script and run from an event..

    On the first run.. it performs some action.. (HS.Speak command in current script)

    On subsequent button presses (within 5 seconds of the first button press).. it performs some different action. (Different HS.Speak action in current script)

    I think you need to have the checkbox on the HS setup page that lets multiple instances of a script to run for it to work...

    But i thought i'd share... and see if anyone else thinks it is a nifty idea.

    Code:
    Sub Main(ByVal parms As Object)
            ' This script enters the first time, and sets a "Homeseer Global" variable and waits a specified amount of time
            ' If another instance of the script is run before that time has expired.. it executes  a separate block of code.
            '
            ' Homeseer Global Varialbes are
            ' "ScriptActive" - Set first time script enters, deleted after the initial run of script ends (after specified amount of time)
            ' "ScriptCount" - Set to 1 the first time the script is run, increments each each time the script is run until the "Wait Time" has expired.
            ' "ScriptTimeReset" = Reset Flag is HS global variable if you want to Reset it to initial on subsequent runs
            '
            ' Constants
            ' SCRIPT_WAIT_TIME the time that the script waits for additional runs... after which it exits and reset's H.S. variables.
            '
    
            Const SCRIPT_WAIT_TIME As Integer = 5 ' Set Time to monitor here... to determine the time the script "Waits" for additional runs.
    
            Dim ScriptTimeleft As Integer
            Dim SCount As Integer ' integer count of number of times Script has run
            Dim StrCount As String ' Holder for String Value of HS Global Variable "ScriptChount"
            Dim IsRunning As String ' Holder for string value of HS Global Variable "ScriptActive"
            Dim TimeReset As String ' Holder for string value of HS Global Variable "ScriptTimeReset"
    
            IsRunning = hs.CreateVar("ScriptActive")
    
            StrCount = hs.CreateVar("ScriptCount")
    
            TimeReset = hs.CreateVar("ScriptTimeReset")
    
            '
            ' This section of the script will only run on the "First" run of the script.
            '========================================================================================================
            If IsRunning = "" Then      ' If this is the FIRST time/Instance  that the Script has run... then
    
                If StrCount = "" Then    ' Initiate ScriptCount to 1 on first run.
                    StrCount = CStr(1)
                    hs.SaveVar("ScriptCount", 1)
                End If
    
                hs.SaveVar("ScriptActive", True) ' Set HS Global "ScriptActive" to indicate script is running
    
                hs.SaveVar("ScriptTimeReset", False) ' Set HS Global "ScriptTimeReset" to False
    
                ' Perform Any action(s) desired on "First Run"
                '
                hs.Speak("Script Run Number is " & CStr(hs.GetVar("ScriptCount")))
                '
    
                ScriptTimeleft = SCRIPT_WAIT_TIME ' Set initial Script time in seconds
    
                Do Until (ScriptTimeleft < 1) ' Loop until Time left is 0
    
                    hs.WaitSecs(1) ' Time/Pause 1 second
    
                    If CBool(hs.GetVar("ScriptTimeReset")) = True Then
                        ScriptTimeleft = SCRIPT_WAIT_TIME ' Reset the ScriptTimer to Start
                        hs.SaveVar("ScriptTimeReset", False)
                    End If
                    '
                    ' insert any actions you want to occur each second that the script is active.
                    ' i.e... toggle a status point... beep over speakers... etc
                    '
                    ScriptTimeleft -= 1  ' Decrement Time
    
    
                Loop
    
                ' Script has Now finished initial run, 
                ' Clean up variables, and delete them so that they do not exist the next time an "Initial run" is performed
    
                hs.SaveVar("ScriptActive", False)
                hs.DeleteVar("ScriptActive")
    
                hs.SaveVar("ScriptCount", False)
                hs.DeleteVar("ScriptCount")
    
                hs.SaveVar("ScriptTimeRemain", False)
                hs.DeleteVar("ScriptTimeRemain")
    
    
                '  Perform any actions here that you want to do after "timer" has expired
                '========================================================================================================
    
            Else
                ' This section of the script will only run on the "Seubsequent" run(s) of the script.
                ' It can be used to perform specified actions on "Second" or "Third", etc run.
                '========================================================================================================
    
                StrCount = CStr(hs.GetVar("ScriptCount"))
    
                SCount = CInt(StrCount) + 1   ' Increment Count
                '
                ' perform actions here... such as Case statements based on "Scount"
                '
                hs.Speak("Script Run Number is now " & CStr(SCount))
                '
                hs.SaveVar("ScriptTimeReset", True) ' save flag to reset timer
    
                hs.SaveVar("ScriptCount", SCount) ' Save Current "Scount"
    
    
            End If
    
    
        End Sub
    Regards,

    Andrew B.

    #2
    Just a quick question about what switch you're using to activate this. Unfortunately none of my Intermatic (supporting instant status) send another ON or OFF response if they're already on their way to being ON of OFF.

    I think your script above is excellent and I'd love to use it (such as: about to go to bed and forgot to turn off lights downstairs -- these area already controlled via timers but perhaps I'm going to bed earlier tonight -- I can just double tap the bedroom light and voila!) but can't seem to get it to respond to multiple taps.

    Any ideas?

    Cheers!

    Comment


      #3
      I'm using a X10 Keychain Remote for triggering..

      I don't have any X10 except for RF Motions and the "keychain" remotes.. so i Use ACRF plugin and a W800 to receive.

      I think it would work with anything that would report status to H.S...

      I think for an insteon switch.. if i press it multiple times.. i think it sees two separate "Set to on" commands... but i'm not sure what the internal "Debounce" time is..

      If the built in Debounce (assuming there is one..) is 1 second.. you'd have to tap pause tap
      Regards,

      Andrew B.

      Comment

      Working...
      X