Announcement

Collapse
No announcement yet.

Any idea what is wrong with this script?

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

    Any idea what is wrong with this script?

    I created this years ago (HS2 and XP at the time, still HS2 but Win 7 now) and at some point it stopped working and I just never got around to looking at it. The ini file is updating fine but I the on/off status for the cirtual device z95 is no longer changing. Any idea how to fix this?

    '*********************************************************** *****************************
    '
    ' The purpose of this script is to take the value stored in the HVAC.ini file
    ' add it to whatever value exists in HVAC.ini.
    '
    '*********************************************************** *****************************

    sub main()

    dim TotalTime

    SoFarTime =hs.GetIniSetting("Downstairs","Minutes_Today",0,"HVAC.ini")
    TempTime = hs.GetIniSetting("Downstairs","Minutes_This_Session",0,"HVAC .ini")
    TotalTime= CDbl(SoFarTime) + CDbl(TempTime)
    hs.SaveINISetting "Downstairs","Minutes_Today",TotalTime,"HVAC.ini"
    hs.SaveINISetting "Downstairs","Minutes_This_Session",0,"HVAC.ini"

    '*********************************************************** *****************************
    ' If the total time the fan has run is > 20000 minutes turn on the virtual
    ' device which to indicate the filter needs changing. at 8:00 each morning
    ' an email will be sent to me if this virtualdevice is set to on. If the fan
    ' runtime is <20000, and the virtual device is already ON then I have reset
    ' the ini file and the device should be turned off
    '*********************************************************** *****************************

    if CDbl(TotalTime)>20000 then
    if hs.IsOff ("z95") then
    hs.ExecX10 "z95","On",0
    end if
    end if

    if CDbl(TotalTime)<20000 then
    if hs.IsON ("z95") then
    hs.ExecX10 "z95","Off",0
    end if
    end if

    end sub

    #2
    I would troubleshoot by first seeing if these commands work properly from the control panel:
    hs.ExecX10 "z95","On",0
    hs.ExecX10 "z95","Off",0

    Then I would add some logging in the script to see where the code is stepping, this would indicate where the problem is.

    Code:
    [COLOR=darkred]hs.writelog("test","TotalTime = " & TotalTime)[/COLOR]
     
    if CDbl(TotalTime)>20000 then
    [COLOR=darkred]hs.writelog("test","here1")
    [/COLOR]if hs.IsOff ("z95") then
    [COLOR=darkred]hs.writelog("test","here2")
    [/COLOR]hs.ExecX10 "z95","On",0
    end if
    end if
    
    if CDbl(TotalTime)<20000 then
    [COLOR=darkred]hs.writelog("test","here3")
    [/COLOR]if hs.IsON ("z95") then
    [COLOR=darkred]hs.writelog("test","here4")
    [/COLOR]hs.ExecX10 "z95","Off",0
    end if
    end if
    Mike

    Comment


      #3
      Hmmm... good tips. The devices are BOT toggling when I execute from control panel. Log shows sent:

      2/1/2015 1:25:13 PM System Control Panel Immediate Script: &hs.ExecX10 "z95","Off",0

      But status does not change. A quick look at help says I have the syntax right. I'll have to look more at that I guess

      Comment


        #4
        Well I have narrowed it down. The commands DO work from the control panel (long story). The test code does not execute though. So I took it our and commented out the CDbl line and then it executes. So the issue is that for some reason CDbl is not working. I'll ask Google but is there another syntax for that?

        Originally posted by mwaite View Post
        I would troubleshoot by first seeing if these commands work properly from the control panel:
        hs.ExecX10 "z95","On",0
        hs.ExecX10 "z95","Off",0

        Then I would add some logging in the script to see where the code is stepping, this would indicate where the problem is.

        Code:
        [COLOR=darkred]hs.writelog("test","TotalTime = " & TotalTime)[/COLOR]
         
        if CDbl(TotalTime)>20000 then
        [COLOR=darkred]hs.writelog("test","here1")
        [/COLOR]if hs.IsOff ("z95") then
        [COLOR=darkred]hs.writelog("test","here2")
        [/COLOR]hs.ExecX10 "z95","On",0
        end if
        end if
        
        if CDbl(TotalTime)<20000 then
        [COLOR=darkred]hs.writelog("test","here3")
        [/COLOR]if hs.IsON ("z95") then
        [COLOR=darkred]hs.writelog("test","here4")
        [/COLOR]hs.ExecX10 "z95","Off",0
        end if
        end if

        Comment


          #5
          Originally posted by Msekelsky View Post
          Well I have narrowed it down. The commands DO work from the control panel (long story). The test code does not execute though. So I took it our and commented out the CDbl line and then it executes. So the issue is that for some reason CDbl is not working. I'll ask Google but is there another syntax for that?
          Syntax is ok I think, but perhaps the value inside TotalTime may not be convertible. Maybe write that value to the log to confirm what it contains.

          Cheers
          Al
          HS 4.2.8.0: 2134 Devices 1252 Events
          Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

          Comment


            #6
            Well I am not 100% sure i did it correctly. I think I have created six whole scripts in my life, all years ago and all from stealing from other scripts but as best I can tell CDbl (TotalTime) is not holding a value or not convertible in your words. Is there something I can do about this or just life in the big city?

            Originally posted by sparkman View Post
            Syntax is ok I think, but perhaps the value inside TotalTime may not be convertible. Maybe write that value to the log to confirm what it contains.

            Cheers
            Al

            Comment


              #7
              You could use the IsNumeric function first to see if TotalTime can be converted.

              Something like:

              Code:
              If IsNumeric(TotalValue) Then
              	if CDbl(TotalTime)<20000 then
              		hs.writelog("test","here3")
              		if hs.IsON ("z95") then
              			hs.writelog("test","here4")
              			hs.ExecX10 "z95","Off",0
              		end if
              	end if
              end if
              Cheers
              Al
              HS 4.2.8.0: 2134 Devices 1252 Events
              Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

              Comment


                #8
                Originally posted by sparkman View Post
                You could use the IsNumeric function first to see if TotalTime can be converted.

                Something like:

                Code:
                If IsNumeric(TotalValue) Then
                    if CDbl(TotalTime)<20000 then
                        hs.writelog("test","here3")
                        if hs.IsON ("z95") then
                            hs.writelog("test","here4")
                            hs.ExecX10 "z95","Off",0
                        end if
                    end if
                end if
                Cheers
                Al
                Why not just write the TotalValue variable to the log to inspect it? (as Sparkman already suggested)

                Code:
                 
                 hs.writelog("test",TotalTime)

                Comment


                  #9
                  I inserted what you wrote (thanks!) and I get an error when running the script:

                  Running script, script run or compile error in file: HVAC_timer_down_temp.txt1044:Cannot use parentheses when calling a Sub in line 27 More info: Cannot use parentheses when calling a Sub

                  Line 27 is the line hs.writelog("test","here3")

                  Entire script now looks like this:

                  sub main()

                  dim TotalTime

                  SoFarTime =hs.GetIniSetting("Downstairs","Minutes_Today",0,"HVAC.ini")
                  TempTime = hs.GetIniSetting("Downstairs","Minutes_This_Session",0,"HVAC .ini")
                  TotalTime= CDbl(SoFarTime) + CDbl(TempTime)
                  hs.SaveINISetting "Downstairs","Minutes_Today",TotalTime,"HVAC.ini"
                  hs.SaveINISetting "Downstairs","Minutes_This_Session",0,"HVAC.ini"

                  '*********************************************************** *****************************
                  ' If the total time the fan has run is > 20000 minutes turn on the virtual
                  ' device which to indicate the filter needs changing. at 8:00 each morning
                  ' an email will be sent to me if this virtualdevice is set to on. If the fan
                  ' runtime is <20000, and the virtual device is already ON then I have reset
                  ' the ini file and the device should be turned off
                  '*********************************************************** *****************************
                  If IsNumeric(TotalValue) Then
                  if CDbl(TotalTime)<20000 then
                  hs.writelog("test","here3")
                  if hs.IsON ("z95") then
                  hs.writelog("test","here4")
                  hs.ExecX10 "z95","Off",0
                  end if
                  end if
                  end if


                  'if CDbl(TotalTime)>20000 then
                  'if hs.IsOff ("z95") then
                  'hs.ExecX10 "z95","On",0
                  'end if
                  'end if

                  'if CDbl(TotalTime)<20000 then
                  'if hs.IsON ("z95") then
                  'hs.ExecX10 "z95","Off",0
                  'end if
                  'end if

                  end sub

                  Originally posted by sparkman View Post
                  You could use the IsNumeric function first to see if TotalTime can be converted.

                  Something like:

                  Code:
                  If IsNumeric(TotalValue) Then
                  	if CDbl(TotalTime)<20000 then
                  		hs.writelog("test","here3")
                  		if hs.IsON ("z95") then
                  			hs.writelog("test","here4")
                  			hs.ExecX10 "z95","Off",0
                  		end if
                  	end if
                  end if
                  Cheers
                  Al

                  Comment


                    #10
                    Originally posted by UltimateInternet View Post
                    Why not just write the TotalValue variable to the log to inspect it? (as Sparkman already suggested)

                    Code:
                     
                     hs.writelog("test",TotalTime)
                    I think that is what I did I am not really a script writer and usually just try stuff until something seems like it worked

                    Comment


                      #11
                      Lose the brackets for VB Script.

                      hs.writelog "test","here3"
                      Real courage is not securing your Wi-Fi network.

                      Comment


                        #12
                        Badda bing badda boom! IsNumeric did the trick, thanks!

                        Originally posted by sparkman View Post
                        You could use the IsNumeric function first to see if TotalTime can be converted.

                        Something like:

                        Code:
                        If IsNumeric(TotalValue) Then
                        	if CDbl(TotalTime)<20000 then
                        		hs.writelog("test","here3")
                        		if hs.IsON ("z95") then
                        			hs.writelog("test","here4")
                        			hs.ExecX10 "z95","Off",0
                        		end if
                        	end if
                        end if
                        Cheers
                        Al

                        Comment

                        Working...
                        X