Announcement

Collapse
No announcement yet.

Script should check for various conditions

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

    Script should check for various conditions

    This is my first attempt with scripting, I have taken a script somebody did for me and I am trying to take it as a template for another script. I have changed a few things already but now am stuck.
    This is the script:

    Code:
     Sub Main(ByVal Parms As Object)
      
     Dim Temperature As Double
     Temperature = hs.DeviceValueEx(18)
     Dim Tempoutside As Double
     Tempoutside = hs.DeviceValueEx(14)
      
     Select Case Temperature
      
     Case < 20.4
     hs.TriggerEvent("AC off auto trigger")
      
     Case 22.0 To 23.5 and Tempoutside <18
     hs.TriggerEvent("open windows bedroom")
      
     Case > 23.5
     hs.TriggerEvent("close bedroom windows")
      
     End Select
      
     End Sub
    I know this is surely wrong but shows what I want to do:
    Case 22.0 To 23.5 and Tempoutside <18

    That's probably relatively easy to rectify.

    Now, the next condition I would like to incorporate I only want to trigger Case 22.0 To 23.5 and tempoutside <18 if bedroom window left and bedroom window right are closed.
    Also I only want
    Case > 23.5
    to trigger if bedroom window left and bedroom window right are open

    #2
    The first step, as you've done with Temperature, is to define variables for the state of the bedroom windows and set them equal to the value of the corresponding HS device. (I'll call them BRRight and BRLeft, and assume the device value is 100 if they are open.)

    I also believe you need to change 'Case' to 'Case Is' when you have an operator in the definition.

    To add a second condition to the Case statement, modify the action line with an If statement. So, try this:
    Code:
    Case 22.0 To 23.5 
       If Tempoutside < 18 Then hs.TriggerEvent("open windows bedroom")
    
    Case Is > 23.5
       If BRRight = 100 AND BRLeft = 100 Then hs.TriggerEvent("close bedroom windows")
    Mike____________________________________________________________ __________________
    HS3 Pro Edition 3.0.0.548, NUC i3

    HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | X10: XTB-232, -IIR | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

    Comment


      #3
      Ok thanks, I think I got it:

      Code:
       Sub Main(ByVal Parms As Object)
        
       Dim Temperature As Double
       Temperature = hs.DeviceValueEx(18)
       Dim Tempoutside As Double
       Tempoutside = hs.DeviceValueEx(14)
       Dim BedWindowR As Double
       BedWindowR = hs.DeviceValueEx(242)
       Dim BedWindowL As Double
       BedWindowL = hs.DeviceValueEx(252)
        
        
       Select Case Temperature
        
       Case < 20.4
       hs.TriggerEvent("AC off auto trigger")
        
       Case 22.0 To 23.5 
       If Tempoutside < 18 Then hs.TriggerEvent("open windows bedroom") 
       Case > 23.5
       If BedWindowR = 100 OR BedWindowL = 100 Then hs.TriggerEvent("close bedroom windows")
        
       End Select
        
       End Sub



      One more question, I have used OR in the last condition, as I want it to fire if either Bedroom Window is open, but also if both are open.
      Is OR going to be true if both are true ?

      Comment


        #4
        Originally posted by mikee123 View Post
        Is OR going to be true if both are true ?
        Yes.

        Cheers
        Al
        HS 3.0.0.548: 1990 Devices 1172 Events
        Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

        Comment


          #5
          I have added some hs.Speak actions (in blue)

          Code:
          Select Case Temperature
                       
                      Case 22.0 To 23.5 
                         If Tempoutside < 18 Then hs.TriggerEvent("AC open bedroom windows") 
                         hs.Speak("Bedroom temperature is " & hs.DeviceValueEx(18) & " Degrees")
                         hs.Speak(" and outside temperature is " & hs.DeviceValueEx(14) & " Degrees")
          I only want those spoken if Tempoutside < 18

          How do I do that, do I have to put 'If Tempoutside < 18 Then' in front of each 'hs.Speak' ?

          How do I do that, do I have to put 'If Tempoutside < 18 Then' in front of each 'hs.Speak' ?
          I have just tried that and it seems to work, but is that the best way ?

          Comment


            #6
            Code:
            Select Case Temperature
                         
                        Case 22.0 To 23.5 
                           If Tempoutside < 18 Then 
                                          hs.TriggerEvent("AC open bedroom windows") 
                                          hs.Speak("Bedroom temperature is " & hs.DeviceValueEx(18) & " Degrees")
                                          hs.Speak(" and outside temperature is " & hs.DeviceValueEx(14) & " Degrees")
                           End If
            HS 3.0.0.548: 1990 Devices 1172 Events
            Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

            Comment


              #7
              That's better. Learnt a lot today... First day scripting, a lot more left to learn.
              Are there any example scripts, a user guide or something like that where I can try and read up ? I was looking at the scripts which were already there and try to understand what they were trying to do, that's where I got the hs.Speak action from...

              Comment


                #8
                Mike. You are learning the way most of us do. There is some documentation out there, but really it's just taking what others have done and trial and error.

                I'm not a coder, but I am getting my way around VB.net on a basic level and it's opened up a lot of possibilities for me. Remember Google is your friend . And you have a lot of help here too.

                Comment


                  #9
                  Yes I am glad to have found a lot of help here.

                  Comment


                    #10
                    Just a small observation:

                    If this is a single script, then you have obtained the device values at the beginning of the script and assigned them to variables, so there is no need to get them again and you could write as:

                    hs.Speak("Bedroom temperature is " & Temperature & " Degrees")
                    hs.Speak(" and outside temperature is " & Tempoutside & " Degrees")

                    Paul..

                    Comment


                      #11
                      Ah great, I was wondering if I couldnt re-use the variables.

                      Comment


                        #12
                        I just changed it, but I am getting this error now:

                        Jul-11 19:37:43
                        Error Compiling script C:\program files (x86)\homeseer hs3\scripts\bedroom window.vb: Statement cannot appear within a method body. End of method assumed. Jul-11 19:37:43 Error Compiling script C:\program files (x86)\homeseer hs3\scripts\bedroom window.vb: Namespace or type specified in the Imports 'System.Core' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.

                        Code:
                          Sub Main(ByVal Parms As Object)
                        
                        even changing it back to what it was before and I still get that error. Maybe because I copied and edited it in Word ?
                           
                                  Dim Temperature As Double
                                  Temperature = hs.DeviceValueEx(18)
                                 Dim Tempoutside As Double
                                  Tempoutside = hs.DeviceValueEx(14)
                          Dim BedWindowR As Double
                                  BedWindowR = hs.DeviceValueEx(242)
                          Dim BedWindowL As Double
                                  BedWindowL = hs.DeviceValueEx(252)
                           
                           
                                  Select Case Temperature
                           
                                      
                                      Case 22.0 To 23.5 
                                         If Tempoutside < 18 Then 
                                         hs.TriggerEvent("AC open bedroom windows") 
                                         hs.Speak("Bedroom temperature is " & Temperature & " Degrees")
                                         hs.Speak(" and outside temperature is " & Tempoutside & " Degrees")
                                         End If
                           
                                      Case > 23.5
                                          If BedWindowR = 255 OR BedWindowL = 255 Then hs.TriggerEvent("AC close bedroom windows")
                                          hs.Speak("Bedroom temperature is " & Temperature & " Degrees")
                                          hs.Speak(" and outside temperature is " & Tempoutside & " Degrees")
                           
                           
                                  End Select
                        Last edited by mikee123; July 11, 2016, 01:41 PM.

                        Comment


                          #13
                          If that's your whole script then its missing

                          End Sub

                          Try

                          Code:
                          Sub Main(ByVal Parms As Object)
                          
                          Dim Temperature As Double
                          Temperature = hs.DeviceValueEx(18)
                          
                          Dim Tempoutside As Double
                          Tempoutside = hs.DeviceValueEx(14)
                          
                          Dim BedWindowR As Double
                          BedWindowR = hs.DeviceValueEx(242)
                          
                          Dim BedWindowL As Double
                          BedWindowL = hs.DeviceValueEx(252)
                             
                             
                          Select Case Temperature
                             
                                        Case 22.0 To 23.5 
                                           If Tempoutside < 18 Then 
                                           hs.TriggerEvent("AC open bedroom windows") 
                                           hs.Speak("Bedroom temperature is " & Temperature & " Degrees")
                                           hs.Speak(" and outside temperature is " & Tempoutside & " Degrees")
                                           End If
                             
                                        Case > 23.5
                                            If BedWindowR = 255 OR BedWindowL = 255 Then hs.TriggerEvent("AC close bedroom windows")
                                            hs.Speak("Bedroom temperature is " & Temperature & " Degrees")
                                            hs.Speak(" and outside temperature is " & Tempoutside & " Degrees")
                                
                                    End Select
                          
                          End Sub
                          Paul..

                          Comment


                            #14
                            Another suggestion for simplifying your scripts. You can combine this:

                            Code:
                            Dim Temperature As Double
                            Temperature = hs.DeviceValueEx(18)
                            Into this:

                            Code:
                            Dim Temperature As Double = hs.DeviceValueEx(18)
                            Cheers
                            Al
                            HS 3.0.0.548: 1990 Devices 1172 Events
                            Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

                            Comment


                              #15
                              It was the End Sub missing... ooops... must have lost it copying and pasting. And also now tidied up the script, looks a lot easier to read now. Thanks for the help and suggestions

                              Code:
                              Sub Main(ByVal Parms As Object)
                                 
                                        Dim Temperature As Double = hs.DeviceValueEx(18)
                                        Dim Tempoutside As Double = hs.DeviceValueEx(14)
                                        Dim BedWindowR As Double = hs.DeviceValueEx(242)
                                        Dim BedWindowL As Double = hs.DeviceValueEx(252)
                                       
                                 
                                 
                                   Select Case Temperature
                                 
                                            
                                            Case 22.0 To 23.5 
                                               If Tempoutside < 18 Then 
                                               hs.TriggerEvent("AC open bedroom windows") 
                                               hs.Speak("Bedroom temperature is " & Temperature & " Degrees")
                                               hs.Speak(" and outside temperature is " & Tempoutside & " Degrees")
                                               End If
                                 
                                            Case > 23.5
                                                If BedWindowR = 255 OR BedWindowL = 255 Then hs.TriggerEvent("AC close bedroom windows")
                                                hs.Speak("Bedroom temperature is " & Temperature & " Degrees")
                                                hs.Speak(" and outside temperature is " & Tempoutside & " Degrees")
                                 
                                 
                                 End Select
                              
                              End Sub

                              Comment

                              Working...
                              X