Announcement

Collapse
No announcement yet.

Script Assistance - Array

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

    Script Assistance - Array

    Hi All,

    Hoping a Script Master might be able to help me, I would like to have a script run prior to 'Arming' my W800RF Alarm System, to let me know if doors and windows are currently open. The script below has worked well (for now), but Is someone able to assist me in moving the doors / windows into some form of array,

    The problem with the below, is that whilst it works, it says Door 1 is Open, Door 3 is Open, Door 5 is Open and so on, what would be better is to have an array or string (e.g. Combined-Doors) which gets each of the statuses when they are Alert, so for example with the below, lets say the "Master Bedroom Window", and 'Guest Bathroom Window" are open, instead of saying "Master Bedroom Window is Opened, Guest Bathroom Window is Open" it would say "The Master Bedroom window, and Guest Bathroom window are open" So i guess it would feed them into a string,

    Is the easiest way to do that simply to have a string set as "" at the start, and then do String = String & ", " & Device Text Currently Open?

    Code:
    Sub Main()
     
     If hs.DeviceValueByName("Master Bedroom Window") = 1 Then
      hs.speak "ALERT Master Bedroom Window is Open"
     End If
     If hs.DeviceValueByName("Study Study Window") = 1 Then
      hs.speak "ALERT Study Window is open"
     End If
     If hs.DeviceValueByName("Guest Bathroom Window") = 1 Then
      hs.speak "ALERT Guest Bathroom Window is open"
     End If
     If hs.DeviceValueByName("Toilet Window") = 1 Then
      hs.speak "ALERT Guest Toilet Window is open"
     End If
     If hs.DeviceValueByName("Spare Room Window") = 1 Then
      hs.speak "ALERT Spare Room Window is open"
     End If
     If hs.DeviceValueByName("Guest Room Window") = 1 Then
      hs.speak "ALERT Guest Room Window is open"
     End If
     If hs.DeviceValueByName("Master Bathroom Window") = 1 Then
      hs.speak "ALERT Master Bathroom Window is open"
     End If
     If hs.DeviceValueByName("Guest Bathroom Window") = 1 Then
      hs.speak "ALERT Study Window is open"
     End If
     If hs.DeviceValueByName("Entrance Garage Internal Door") = 1 Then
      hs.speak "ALERT Internal Door to Garage is open"
     End If
     If hs.DeviceValueByName("Rumpus Room Outside Door") = 1 Then
      hs.speak "ALERT Rumpus room door is open"
     End If
     If hs.DeviceValueByName("Kitchen Door Sensor") = 1 Then
      hs.speak "ALERT Kitchen door is open"
     End If
     If hs.DeviceValueByName("Laundry Laundry Door") = 1 Then
      hs.speak "ALERT Laundry Door is open"
     End If
    End Sub
    HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

    Facebook | Twitter | Flickr | Google+ | Website | YouTube

    #2
    I think this would do what you want:
    PHP Code:
    Sub Main(ByVal Parms as Object)
         
    Dim devs() as String = {"Master Bedroom Window""Study Study Window" _
              
    ,"Guest Bathroom Window", ... (you get the idea) ... }
         
    Dim speech() as String = {"Master Bedroom Window""Study Window" _
              
    ,"Guest Bathroom Window", ... (you get the idea) ... }
         
    Dim j as Integer 0
         
    For Each dev as String in devs
               
    If hs.DeviceValueByName(dev) = 1 Then
                    hs
    .Speak("ALERT " speech(j) & " is open.")
               
    End If
               
    += 1
         Next
    End Sub 
    Is that what you mean?

    Steve

    Comment


      #3
      Thanks, that looks perfect, I will have a play around tonight and that should do the trick!

      Thanks
      HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

      Facebook | Twitter | Flickr | Google+ | Website | YouTube

      Comment


        #4
        I seem to be erroring up

        7/25/2012 3:23:42 PM Error Running script, script run or compile error in file: DoorCheck.vbs1006:Expected ')' in line 1 More info: Expected ')'
        What is likely to be causing this error?

        Thanks

        Code:
        Sub Main(ByVal Parms as Object)
             Dim devs() as String = {"Entrance Front Door", "Laundry Laundry Door", "Garage Roller Door", "Kitchen Door Sensor", "Rumpus Room Outside Door", "Study Study Window", "Master Bathroom Window", "Outside Side Gate", "Spare Room Window", "Guest Room Window", "Guest Bathroom Window", "Greenhouse Roof Vent", "Kitchen Window", "Rumpus Room Back Window", "Rumpus Room Front Window", "Formal Loungeroom Window", "Toilet Door", "Garage Outside Door", "Garage Garage Internal Door"}
             Dim speech() as String = {"Entrance Front Door", "Laundry Laundry Door", "Garage Roller Door", "Kitchen Door Sensor", "Rumpus Room Outside Door", "Study Study Window", "Master Bathroom Window", "Outside Side Gate", "Spare Room Window", "Guest Room Window", "Guest Bathroom Window", "Greenhouse Roof Vent", "Kitchen Window", "Rumpus Room Back Window", "Rumpus Room Front Window", "Formal Loungeroom Window", "Toilet Door", "Garage Outside Door", "Garage Garage Internal Door"}
             Dim j as Integer = 0
             For Each dev as String in devs
                   If hs.DeviceValueByName(dev) = 1 Then
                        hs.Speak("ALERT " & speech(j) & " is open.")
                   End If
                   j += 1
             Next
        End Sub
        HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

        Facebook | Twitter | Flickr | Google+ | Website | YouTube

        Comment


          #5
          Originally posted by travisdh View Post
          I seem to be erroring up

          7/25/2012 3:23:42 PM Error Running script, script run or compile error in file: DoorCheck.vbs1006:Expected ')' in line 1 More info: Expected ')'
          What is likely to be causing this error?

          Thanks
          This is VB.NET code, so the file should be .VB. You've named it .VBS, which implies it is VBScript. Won't work that way. Sorry, I should have mentioned that.

          Steve

          Comment


            #6
            By the way...

            I only made the separate array "speech" because it looked like what you wanted to announce was not always the same as the device name. For example, one device was "Laundry Laundry Door" and you seemed to not want to repeat the "Laundry" word twice. Using the speech array, the announcement corresponding to a particular device could be very different from the device name.

            However, I just looked again at your script, and it looks like you made the "speech" array match the "devs" array. It may be you did that initially to just get the script going. However, if you really do want to use the device name in the announcement, you can simplify the script.
            Code:
            Sub Main(ByVal Parms as Object)
                 Dim devs() as String = {"Entrance Front Door", "Laundry Laundry Door", "Garage Roller Door", "Kitchen Door Sensor", "Rumpus Room Outside Door", "Study Study Window", "Master Bathroom Window", "Outside Side Gate", "Spare Room Window", "Guest Room Window", "Guest Bathroom Window", "Greenhouse Roof Vent", "Kitchen Window", "Rumpus Room Back Window", "Rumpus Room Front Window", "Formal Loungeroom Window", "Toilet Door", "Garage Outside Door", "Garage Garage Internal Door"}
                For Each dev as String in devs
                       If hs.DeviceValueByName(dev) = 1 Then
                            hs.Speak("ALERT " & dev & " is open.")
                       End If
                 Next
            End Sub
            Again, this is VB.NET, so save it as a .VB script file, and you can run it from an event.

            Steve

            Comment


              #7
              Thanks, renaming it worked perfectly.
              I did give them the same names to get it going, but will likely change the names somewhat so it works a little bit better and reads with less duplication etc.

              Thanks for your help, works perfectly
              HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

              Facebook | Twitter | Flickr | Google+ | Website | YouTube

              Comment

              Working...
              X