Announcement

Collapse
No announcement yet.

Using scripting for first time

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

    Using scripting for first time

    Hi
    my first time I try to use scripts
    I want to take an average of three temperature sensors and provide value to a virtuel device

    this is my code

    Sub Main()
    Dim Temp1-Hall'
    Dim Temp2-Koket
    Dim Temp3-Vardagsrum
    Temp1-Hall = dvRef 2272
    Temp2-Koket = dvRef 2273
    Temp3-Vardagsrum = dvRef 2274
    hs.writelog Temp1-Hall
    hs.SetDeviceValueByRef 2284, CDbl(Temp1-Hall+Temp2-Koket+Temp3-Vardagsrum/3), True
    End Sub

    the log say it stops on 2 line
    Running script, script run or compile error in file: C:/HomeSeer HS3/scripts/getsolarday - kopia.vbs1025 in line 2 More info
    Last edited by Daarn; March 27, 2017, 04:38 AM.

    #2
    You appear to have an apostrophe in the variable name (after hall). Most languages I've used would complain about that....

    Comment


      #3
      I don't think the apostrophe is the problem. It is used by vbs to indicate a comment, so will just be ignored.
      First, I'd change the variable names to remove the '-'. I'm pretty sure it's being interpreted as a minus sign.
      Also these lines:
      Temp1-Hall = dvRef 2272
      Temp2-Koket = dvRef 2273
      Temp3-Vardagsrum = dvRef 2274
      will be a problem.

      I assume you want to assign the device value to your variables. That requires a function - described in the HS Help file.
      In place of dvRef nnnn, try hs.DeviceValue(nnnn)
      Mike____________________________________________________________ __________________
      HS3 Pro Edition 3.0.0.548, NUC i3

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

      Comment


        #4
        You cannot use a - in a variable

        Try this:

        PHP Code:
            Sub Main(ByVal Parm As String)
                
        Dim Temp1_Hall As Double
                Dim Temp2_Koket 
        As Double
                Dim Temp3_Vardagsrum 
        As Double
                Temp1_Hall 
        hs.DeviceValueEx(2272)
                
        Temp2_Koket hs.DeviceValueEx(2273)
                
        Temp3_Vardagsrum hs.DeviceValueEx(2274)
                
        hs.WriteLog("Test"Temp1_Hall)
                
        hs.SetDeviceValueByRef(2284Temp1_Hall Temp2_Koket Temp3_Vardagsrum 3True)
            
        End Sub 
        This is a VB.NET script so must end with the extension .vb (i.e. Runme.vb).
        Jon

        Comment


          #5
          HI
          Thx very much for the help


          Originally posted by jon00 View Post
          You cannot use a - in a variable

          Try this:

          PHP Code:
              Sub Main(ByVal Parm As String)
                  
          Dim Temp1_Hall As Double
                  Dim Temp2_Koket 
          As Double
                  Dim Temp3_Vardagsrum 
          As Double
                  Temp1_Hall 
          hs.DeviceValueEx(2272)
                  
          Temp2_Koket hs.DeviceValueEx(2273)
                  
          Temp3_Vardagsrum hs.DeviceValueEx(2274)
                  
          hs.WriteLog("Test"Temp1_Hall)
                  
          hs.SetDeviceValueByRef(2284Temp1_Hall Temp2_Koket Temp3_Vardagsrum 3True)
              
          End Sub 
          This is a VB.NET script so must end with the extension .vb (i.e. Runme.vb).

          Comment

          Working...
          X