Announcement

Collapse
No announcement yet.

Homeland security

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

  • Homeland security

    Anyone have the homeland security script working in 2.0.2003?
    Just cannot get mine to work.
    Thanx
    Tim
    FB Page - https://www.facebook.com/pages/Capt-Tim/209398425902188

    HSTouch Layouts - https://www.facebook.com/media/set/?...5902188&type=3

    No, Im from Iowa. I only work in outer space. Captain Kirk

  • #2
    I have it working for Homeseer 2 version 2003, see attached.

    I modifed the code to use the GetEventEnumerator and also added some logging that can be turned on.
    Attached Files
    Billy Draper

    Comment


    • #3
      Tried it out, no workie
      Even deleted the device and event, recreated them with a diff device code and adjusted script to suit, but still says "unknown"
      Tim

      PS got it a simple code error on my part
      Thanx
      Tim
      FB Page - https://www.facebook.com/pages/Capt-Tim/209398425902188

      HSTouch Layouts - https://www.facebook.com/media/set/?...5902188&type=3

      No, Im from Iowa. I only work in outer space. Captain Kirk

      Comment


      • #4
        I'll install it from scratch and see if I can figure something out.

        Sorry about that..
        Billy Draper

        Comment


        • #5
          Looks like it was not ever getting to the Sub AlertChange after it had been ran once and the event "Trigger every "X" minutes were the same. I made a minor change to the logic. I also made the device code a variable so that you just have to change it in one place. Also the event name must be "Homeland Security" as in the doc.

          I tested it several times with the logging turned on and created different devices and had it update them.

          If you are getting an error, post it back.

          Thanks.
          Attached Files
          Billy Draper

          Comment


          • #6
            Made the Homeland Security script work again

            I don't know if anybody's interested but I tried out this script and was beating my head against the wall trying to figure out why it wouldn't work for me. Well, in looking through the script I was presuming the URL to get the threat level was working. Guess what? They changed it! So I did a lot of Googling and found the source code for a Windows SysTray app that had the source code available. Digging through that I found a working URL. So I fixed the URL in the program and changed the test criteria it uses to find the level to match that returned by the new URL.

            Enjoy!

            Code:
            '****************************************************************************************************
            '* Author : Steve Rauco                                                                             *
            '* Date   : 05-Jan-2005                                                                             *
            '* Email  :                                                                                         *
            '* Web    : http://                                                                                 *
            '* Script : homeland_security.txt                                                                   *
            '*                                                                                                  *
            '* Purpose: This script will find the current Homeland Security Advisory condition. You can place   *
            '* any code you like in the function AlertChange. The msgbox command is NOT really useful here as   *
            '* it must be clicked on to dismiss. It was only there for example purposes.                        *
            '*                                                                                                  *
            '* This example will check every X minutes based on the alert status.                               *
            '*                                                                                                  *
            '*      Green  (Low)      every 6 hours                                                             *
            '*      Blue   (Guarded)  every 3 hours                                                             *
            '*      Yellow (Elevated) every 1 hour                                                              *
            '*      Orange (High)     every 1/2 hour                                                            *
            '*      Red    (Severe)   every 15 minutes                                                          *
            '*                                                                                                  *
            '* You can change these times (in seconds) to any time you like, but remember, we're polling the    *
            '* White House, so let's not flood Dubya's server. :)                                               *
            '*                                                                                                  *
            '* When the alert status is found the event recurrence time is changed accordingly. To use this     *
            '* script properly, create an event called "Homeland" and set it to recur every 10 seconds. The     *
            '* first time through it will set itself to the proper interval.                                    *
            '*                                                                                                  *
            '* Credits: Not sure, got the base on the old Homeseer board and modifed quite a bit.               *
            '*                                                                                                  *
            '* Requirements: None                                                                               *
            '*                                                                                                  *
            '* Issues: None known                                                                               *
            '*                                                                                                  *
            '* Modification History: 05-Jan-2005 Steve Rauco  Created.                                          *
            '*                       02-Feb-2005 Billy Draper Modified.                                         *
            '*                        Converted to Homeseer 2.                                                  *
            '*                        Modified GetEventEx to GetEventEnumerator.                                *
            '*                        Added the ability to log information to Homeseer log file.                *
            '*                       27-Nov-2005 Billy Draper Modified.                                         *
            '*                        Minor change to If statement calling AlertChange checked for null status. *
            '*                       16-Jan-2011 Steve Knapp modified.                                          *
            '*                        Changed URL to one that still works
            '*                                                                                                  *
            '* Installations:                                                                                   *
            '*      a) Place the file "homeland_security.txt" in Homeseer\scripts directory.                    *
            '*      b) Place gifs in html\images\homeland directory.                                            *
            '*      c) Setup a event in Homeseer named "Homeland Security" that occurs every 10 minutes.        *
            '*      d) All user selectable values/parameters are commented below.                               *
            '*                                                                                                  *
            '****************************************************************************************************
            '
            'Constant declarations.
            '
            Const v_script_name                = "homeland_security.txt"        ' Script name.
            Const v_logging_name               = "Homeland"                     ' Logging name.
            Const v_logging_enable             = False                          ' Boolean (True or False) True enables logging feature. 
            Const v_device_code                = "V51"                          ' House and Unit Code to populate. 
            
            Sub Main()
            
              Dim strPage
              Dim strAdvise
              Dim strAlert
              Dim strMinutes
              Dim ev
              Dim evOldTime
              Dim en
            
              If v_logging_enable Then
                 hs.WriteLog v_logging_name, "Begin " & v_script_name & " script."
              End If
            
              strPage = hs.GetURL("www.dhs.gov","/dhspublic/getAdvisoryCondition",FALSE,80)
              strMinutes = 0
            
              strAdvise = instr(1,lcase(strPage),"severe")
              If strAdvise > 0 Then 
                strAlert = "Severe"
                strMinutes = 15     'check every 15 minutes
              End If
            
              strAdvise = instr(1,lcase(strPage),"high")
              If strAdvise > 0 Then 
                strAlert = "High"
                strMinutes = 30      'check every 1/2 hour
              End If
            
              strAdvise = instr(1,lcase(strPage),"elevated")
              If strAdvise > 0 Then 
                strAlert = "Elevated"
                strMinutes = 60      'check every hour
              End If
            
              strAdvise = instr(1,lcase(strPage),"guarded")
              If strAdvise > 0 Then 
                strAlert = "Guarded"
                strMinutes = 180     'check every 3 hours
              End If
            
              strAdvise = instr(1,lcase(strPage),"low")
              If strAdvise > 0 Then 
                strAlert = "Low"
                strMinutes = 360     'check every 6 hours
              End If
            
              If strMinutes > 0 Then
                 set en = hs.GetEventEnumerator
                 If IsObject(en) Then
                 Else
                     If v_logging_enable Then
                        hs.WriteLog v_logging_name, "ERROR! The Event enumerator is invalid."
                     End If
                 End If
                 Do while not en.Finished
                    If en.CountChanged Then
                       If v_logging_enable Then
                          hs.WriteLog v_logging_name, "ERROR! The Event enumerator has changed."
                       End If
                    End If
                    Set ev = en.GetNext
                    If not ev is nothing Then
                       If ev.name = "Homeland Security" Then
                          If v_logging_enable Then
                             hs.WriteLog v_logging_name, "Event Name:                   " & ev.name
                             hs.WriteLog v_logging_name, "Homeland Alert level          " & strAlert
                             hs.WriteLog v_logging_name, "Homeland Alert time (min)     " & strMinutes
                             hs.WriteLog v_logging_name, "Old Event record minutes      " & ev.rec_mins
                             hs.WriteLog v_logging_name, "Old Event record seconds      " & ev.rec_secs
                          End If
                          evOldTime = ev.rec_secs
                          If ev.rec_mins <> strMinutes Then
                             ev.rec_mins = strMinutes
                             ev.rec_secs = 0
                             AlertChange(strAlert)
                          ElseIf hs.devicestring(v_device_code) = "" Then
                             ev.rec_mins = strMinutes
                             ev.rec_secs = 0
                             AlertChange(strAlert)
                          End If
                       End If
                    End If
                 Loop
              End If   
            
              If v_logging_enable Then
                 hs.WriteLog v_logging_name, "End   " & v_script_name & " script."
              End If
            
            End Sub
            
            '------------------------------------------
            
            Private Sub AlertChange(strAlert)
            
              If v_logging_enable Then
                 hs.WriteLog v_logging_name, "Begin Alert Sub " & v_script_name & " script."
              End If
            
              select case strAlert
                case "Low"
                  strImage = "low.gif"
                  strColor = "#008000"
            
                case "Guarded"
                  strImage = "guarded.gif"
                  strColor = "#000080"
            
                case "Elevated"
                  strImage = "elevated.gif"
                  strColor = "#FFCC00"
            
                case "High"
                  strImage = "high.gif"
                  strColor = "#FF9933"
            
                case "Severe"
                  strImage = "severe.gif"
                  strColor = "#800000"
            
              end select
            
              strHTML = "<img border='0' src='/Images/homeland/" & strImage & "' "
              strHTML = strHTML & "align='absmiddle'> "
              strHTML = strHTML & "<font color='" & strColor & "'><b>" & strAlert & "</b></font>"
              'strHTML = strHTML & strAlert
              hs.SetDeviceString v_device_code, strHTML, TRUE
              hs.SetDeviceLastChange v_device_code, now
            
              If v_logging_enable Then
                 hs.WriteLog v_logging_name, "Device Code     " & v_device_code
                 hs.WriteLog v_logging_name, "End   Alert Sub " & v_script_name & " script."
              End If
            
            End Sub
            Last edited by spknapp; January 18th, 2011, 10:12 AM. Reason: Added code
            Steve

            (System configuration is in my profile)

            Comment


            • #7
              Code:
                
              '****************************************************************************************************
              '* Author : Steve Rauco                                                                             *
              '* Date   : 05-Jan-2005                                                                             *
              '* Email  :                                                                                         *
              '* Web    : http://                                                                                 *
              '* Script : homeland_security.txt                                                                   *
              '*                                                                                                  *
              '* Purpose: This script will find the current Homeland Security Advisory condition. You can place   *
              '* any code you like in the function AlertChange. The msgbox command is NOT really useful here as   *
              '* it must be clicked on to dismiss. It was only there for example purposes.                        *
              '*                                                                                                  *
              '* This example will check every X minutes based on the alert status.                               *
              '*                                                                                                  *
              '*      Green  (Low)      every 6 hours                                                             *
              '*      Blue   (Guarded)  every 3 hours                                                             *
              '*      Yellow (Elevated) every 1 hour                                                              *
              '*      Orange (High)     every 1/2 hour                                                            *
              '*      Red    (Severe)   every 15 minutes                                                          *
              '*                                                                                                  *
              '* You can change these times (in seconds) to any time you like, but remember, we're polling the    *
              '* White House, so let's not flood Dubya's server. :)                                               *
              '*                                                                                                  *
              '* When the alert status is found the event recurrence time is changed accordingly. To use this     *
              '* script properly, create an event called "Homeland" and set it to recur every 10 seconds. The     *
              '* first time through it will set itself to the proper interval.                                    *
              '*                                                                                                  *
              '* Credits: Not sure, got the base on the old Homeseer board and modifed quite a bit.               *
              '*                                                                                                  *
              '* Requirements: None                                                                               *
              '*                                                                                                  *
              '* Issues: None known                                                                               *
              '*                                                                                                  *
              '* Modification History: 05-Jan-2005 Steve Rauco  Created.                                          *
              '*                       02-Feb-2005 Billy Draper Modified.                                         *
              '*                        Converted to Homeseer 2.                                                  *
              '*                        Modified GetEventEx to GetEventEnumerator.                                *
              '*                        Added the ability to log information to Homeseer log file.                *
              '*                       27-Nov-2005 Billy Draper Modified.                                         *
              '*                        Minor change to If statement calling AlertChange checked for null status. *
              '*                       16-Jan-2011 Steve Knapp modified.                                          *
              '*                        Changed URL to one that still works
              '*                                                                                                  *
              '* Installations:                                                                                   *
              '*      a) Place the file "homeland_security.txt" in Homeseer\scripts directory.                    *
              '*      b) Place gifs in html\images\homeland directory.                                            *
              '*      c) Setup a event in Homeseer named "Homeland Security" that occurs every 10 minutes.        *
              '*      d) All user selectable values/parameters are commented below.                               *
              '*                                                                                                  *
              '****************************************************************************************************
              '
              'Constant declarations.
              '
              Const v_script_name                = "homeland_security.txt"        ' Script name.
              Const v_logging_name               = "Homeland"                     ' Logging name.
              Const v_logging_enable             = False                          ' Boolean (True or False) True enables logging feature. 
              Const v_device_code                = "V51"                          ' House and Unit Code to populate. 
              
              Sub Main()
              
                Dim strPage
                Dim strAdvise
                Dim strAlert
                Dim strMinutes
                Dim ev
                Dim evOldTime
                Dim en
              
                If v_logging_enable Then
                   hs.WriteLog v_logging_name, "Begin " & v_script_name & " script."
                End If
              
                strPage = hs.GetURL("www.dhs.gov","/dhspublic/getAdvisoryCondition",FALSE,80)
                strMinutes = 0
              
                strAdvise = instr(1,lcase(strPage),"severe")
                If strAdvise > 0 Then 
                  strAlert = "Severe"
                  strMinutes = 15     'check every 15 minutes
                End If
              
                strAdvise = instr(1,lcase(strPage),"high")
                If strAdvise > 0 Then 
                  strAlert = "High"
                  strMinutes = 30      'check every 1/2 hour
                End If
              
                strAdvise = instr(1,lcase(strPage),"elevated")
                If strAdvise > 0 Then 
                  strAlert = "Elevated"
                  strMinutes = 60      'check every hour
                End If
              
                strAdvise = instr(1,lcase(strPage),"guarded")
                If strAdvise > 0 Then 
                  strAlert = "Guarded"
                  strMinutes = 180     'check every 3 hours
                End If
              
                strAdvise = instr(1,lcase(strPage),"low")
                If strAdvise > 0 Then 
                  strAlert = "Low"
                  strMinutes = 360     'check every 6 hours
                End If
              
                If strMinutes > 0 Then
                   set en = hs.GetEventEnumerator
                   If IsObject(en) Then
                   Else
                       If v_logging_enable Then
                          hs.WriteLog v_logging_name, "ERROR! The Event enumerator is invalid."
                       End If
                   End If
                   Do while not en.Finished
                      If en.CountChanged Then
                         If v_logging_enable Then
                            hs.WriteLog v_logging_name, "ERROR! The Event enumerator has changed."
                         End If
                      End If
                      Set ev = en.GetNext
                      If not ev is nothing Then
                         If ev.name = "Homeland Security" Then
                            If v_logging_enable Then
                               hs.WriteLog v_logging_name, "Event Name:                   " & ev.name
                               hs.WriteLog v_logging_name, "Homeland Alert level          " & strAlert
                               hs.WriteLog v_logging_name, "Homeland Alert time (min)     " & strMinutes
                               hs.WriteLog v_logging_name, "Old Event record minutes      " & ev.rec_mins
                               hs.WriteLog v_logging_name, "Old Event record seconds      " & ev.rec_secs
                            End If
                            evOldTime = ev.rec_secs
                            If ev.rec_mins <> strMinutes Then
                               ev.rec_mins = strMinutes
                               ev.rec_secs = 0
                               AlertChange(strAlert)
                            ElseIf hs.devicestring(v_device_code) = "" Then
                               ev.rec_mins = strMinutes
                               ev.rec_secs = 0
                               AlertChange(strAlert)
                            End If
                         End If
                      End If
                   Loop
                End If   
              
                If v_logging_enable Then
                   hs.WriteLog v_logging_name, "End   " & v_script_name & " script."
                End If
              
              End Sub
              
              '------------------------------------------
              
              Private Sub AlertChange(strAlert)
              
                If v_logging_enable Then
                   hs.WriteLog v_logging_name, "Begin Alert Sub " & v_script_name & " script."
                End If
              
                select case strAlert
                  case "Low"
                    strImage = "low.gif"
                    strColor = "#008000"
              
                  case "Guarded"
                    strImage = "guarded.gif"
                    strColor = "#000080"
              
                  case "Elevated"
                    strImage = "elevated.gif"
                    strColor = "#FFCC00"
              
                  case "High"
                    strImage = "high.gif"
                    strColor = "#FF9933"
              
                  case "Severe"
                    strImage = "severe.gif"
                    strColor = "#800000"
              
                end select
              
                strHTML = "<img border='0' src='/Images/homeland/" & strImage & "' "
                strHTML = strHTML & "align='absmiddle'> "
                strHTML = strHTML & "<font color='" & strColor & "'><b>" & strAlert & "</b></font>"
                'strHTML = strHTML & strAlert
                hs.SetDeviceString v_device_code, strHTML, TRUE
                hs.SetDeviceLastChange v_device_code, now
              
                If v_logging_enable Then
                   hs.WriteLog v_logging_name, "Device Code     " & v_device_code
                   hs.WriteLog v_logging_name, "End   Alert Sub " & v_script_name & " script."
                End If
              
              End Sub
              Last edited by spknapp; January 18th, 2011, 01:08 AM. Reason: Added code
              Steve

              (System configuration is in my profile)

              Comment


              • #8
                You need more posts.

                Or use the
                Code:
                [ code ]  
                tags 
                [ / code ]
                (remove the spaces)

                Then you can post it into your post.

                --Dan
                Tasker, to a person who does Homeautomation...is like walking up to a Crack Treatment facility with a truck full of 3lb bags of crack. Then for each person that walks in and out smack them in the face with an open bag.

                Comment


                • #9
                  So maybe I wasted my time?

                  I saw this today:

                  http://www.msnbc.msn.com/id/41279335/ns/politics

                  Naw, at least it kept me busy for an afternoon researching and fixing the script...
                  Steve

                  (System configuration is in my profile)

                  Comment

                  Working...
                  X