Announcement

Collapse
No announcement yet.

Confusion with values

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

  • Confusion with values

    Trying to use values in a script to set Boolean. I have a virtual device that is armed, arming or disarmed. 0 for disarmed, 50 for arming and 100 for armed.
    my test is

    PHP Code:
    If hs.DeviceValue(hs.GetDeviceRefByName("Virtual Security System")) = 0 Then Away True 
    However when this is set to disarmed (0), the above always is true.

    What am I doing wrong?
    Thanks
    Attached Files
    Don

  • #2
    Show a bit more of the code so we can see if we can spot anything.
    -Rupp
    sigpic

    Comment


    • #3
      Right, specifically, what are you "Dim"ming Away, Wake and Armed to? Should be "As Boolean"
      Also, grammatically, You're setting "Away" = True when the system is Disarmed?? You'd think Disarming would be Not Away (ie Home)?

      Z

      Comment


      • #4
        Here is my code:

        PHP Code:
        Public ID As String "Security.vb"
        Public Armed As Boolean False
        Public Away As Boolean False
        Public Wake As Boolean False
        Public myDebug As Boolean False
        Public HSTouchOn As Boolean True


        Sub Main
        (ByVal msg As String)

            If 
        hs.DeviceValue(hs.GetDeviceRefByName("Virtual Security System")) = 0 Then Away True
            
        If hs.DeviceValue(hs.GetDeviceRefByName("Virtual Wake_Sleep")) = 100 Then Wake True
            
        If hs.DeviceValue(hs.GetDeviceRefByName("Virtual Home/Away")) = 100 Then Armed True

            hs
        .Writelog("TEST""Armed is " Armed.toString " and Away is " Away.toString)


            Try
                
        Dim dv As Scheduler.Classes.DeviceClass
                Dim EN 
        As Scheduler.Classes.clsDeviceEnumeration
                Dim devLastOpen 
        As String " Virtual Last Open"
                
        Dim devRef As Integer hs.GetDeviceRefByName(devLastOpen)

                If 
        devRef = -1 Then
                    hs
        .WriteLog("Error"ID " Can't find reference number for device " devLastOpen)
                Else
                    
        'hs.WriteLog(ID,devLastOpen & "'s ref is " & devRef.toString)
                End If


                EN = hs.GetDeviceEnumerator
                If EN Is Nothing Then
                    hs.writelog(ID, "
        Error getting Enumerator")
                    Exit Sub
                End If
                Do
                    dv = EN.GetNext
                    If dv Is Nothing Then Continue Do
                    'hs.Writelog("
        TEST",dv.name(hs) & " With Type of " & dv.Device_Type_String(hs))
                    If dv.Device_Type_String(hs) = "
        xAP" Then
                        If dv.devValue(hs) > 0 Then

                            hs.SetDeviceString(devRef, dv.location(hs) & " " & dv.name(hs), True)
                            hs.SetDeviceValueByRef(devRef, 0, True)

                            If Armed And Not Away Then
                                Warning(dv.location(hs) & " " & dv.name(hs))
                                hs.WriteLog("
        Warning", "The " & dv.location(hs) & " " & dv.name(hs) & " is Open")
                            End If
                        End If
                    End If
                    'hs.writelog("
        Script", "Device name" & dv.Name(hs))
                Loop Until EN.Finished
            Catch ex As Exception
                hs.WriteLog("
        Error", "Exception in script" & ex.Message)
            End Try

        End Sub 

        My thinking is that if we are awake but gone, the alarm should be routed to a phone or something like that.

        If we are awake but home the alarm should be spoken locally. At any rate, the values returned from the hs.DeviceValue doesn't seem to reflect the actual value of the device.

        Sorry to be unclear. And remember I'm pretty lame at programming. :-)

        **** EDIT ***

        Outch! I misplaced the variables in the statements
        PHP Code:
        If hs.DeviceValue(hs.GetDeviceRefByName("Virtual Security System")) = 0 Then Away True
            
        If hs.DeviceValue(hs.GetDeviceRefByName("Virtual Wake_Sleep")) = 100 Then Wake True
            
        If hs.DeviceValue(hs.GetDeviceRefByName("Virtual Home/Away")) = 100 Then Armed True 
        Virtual Security System and Virtual Home/Away were mixed up.
        Last edited by donstephens; July 21st, 2014, 12:01 PM. Reason: Dumber than a rock
        Don

        Comment


        • #5
          Sorry, I got distracted by the "Away is 28" It's not a Dim issue..

          Rupp??

          Z

          Comment


          • #6
            So it works now?

            Z

            Comment


            • #7
              Yeah. I managed to confuse myself my over thinking it. I think.

              Thanks for the help.
              Don

              Comment


              • #8
                As I always tell my daughter, I didn't fix it you did, I just provided you with someone to explain it to

                Z

                Comment

                Working...
                X