Announcement

Collapse
No announcement yet.

VB.NET Syntax

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

  • VB.NET Syntax

    I am having a problem with executing the following immediate script command:

    &if hs.deviceValue (434) > 45 then hs.setDeviceValueByRef (434, 45, True) elseif hs.deviceValue (434) < 25 then hs.setDeviceValueByRef (434, 25, True)

    The log displays the following error:

    Error Compiling script /tmp/K37.vb: Expected '('.

    Can someone help me with what I'm doing wrong?

    Basically I'm trying to clamp the value of device 434 between 25 and 45 (% Relative Humidity set point calculated in another script command).

    Thanks,

  • #2
    Al,

    I do not think this is the right copy of the command. Your error (Error Compiling script /tmp/K37.vb: Expected '('.) points to a direct .net script command wich starts with "&n" and that is not what I see in the command you are posting? Or could this error maybe coming from another command that triggers because of the command you are posting?

    Wim
    -- Wim

    Plugins:RFXCOM, HSTouch Server, Squeezebox, BLGData, Restart, Jon00's Perfmon and Network monitor, WeatherXML, BLBackup, TenScripting, BC4, Pushover, PHLocation, JowiHue, Zwave, Sonos
    650 devices ---- 336 events ----- 40 scripts

    Comment


    • #3
      I don't believe that is the case.

      Here are the log entries after running the script command from the control panel as a test:

      Oct-10 07:19:46 Error Compiling script /tmp/K37.vb: Expected '('.
      Oct-10 07:19:45 Info Running immediate script: /tmp/K37.vb
      Oct-10 07:19:45 System Control Panel Immediate Script: &if hs.deviceValue(434)>45 then hs.setDeviceValueByRef(434, 45, True) else if hs.deviceValue(434)<25 then hs.setDeviceValueByRef(434, 25, True)


      Maybe something to do with nesting of my If then else if statement....?

      Also, I am on a Linux system (HomeTroller SEL). I read somewhere in the docs that since Linux only runs VB.NET that the "&n" and "&" preceding a script statement are interpreted the same by the .NET compiler.

      Comment


      • #4
        If you have access to the file system, can you grab a copy of the K37.vb file that was generated and post it? You might be better of creating a .vb file yourself that does what you need and call it, rather than trying to make an immediate script statement work.

        Cheers
        Al
        HS 3.0.0.548: 1965 Devices 1146 Events
        Z-Wave 3.0.1.262: 122 Nodes on one Z-Net

        Comment


        • #5
          I'm not a scripting expert by any means, but post #1 has spaces between deviceValue and the parentheses, whereas post #3 does not.

          Comment


          • #6
            I wasn't aware that this was even possible with a immediate script command.

            I thought immediate script commands what just that: Commands.
            I.e. calls to functions or subs, and does not handle any statement you throw at it.

            Let's take a very basic if statement:
            Code:
            &if True then hs.Writelog("Test", "True")
            Well, that didn't work.

            But this, which is a sub call, does:
            Code:
            &hs.Writelog("Test", "True")
            You could try VB's own inline if stateement, "iif":
            Code:
            &iif(true, hs.Writelog("Test", "True"), hs.Writelog("Test", "False"))
            But that actually executes both statements: You'll get both "True" and "False" in the log.


            Conclusion:
            If you need to validate conditions then use a script file.

            Somescript.vb:
            Code:
            Sub Main(params as Object)
                If hs.deviceValue(434) > 45 Then hs.setDeviceValueByRef (434, 45, True)
                If hs.deviceValue(434) < 25 Then hs.setDeviceValueByRef (434, 25, True)
            End Sub
            You could use elseif here, but why bother?

            ooor, to fetch the value only once (and as a double in case the value has decimals), let's do this instead:
            Somescript.vb:
            Code:
            Sub Main(params as Object)
                Dim value as Double = hs.DeviceValueEx(434)
                If value > 45 Then hs.setDeviceValueByRef (434, 45, True)
                If value < 25 Then hs.setDeviceValueByRef (434, 25, True)
            End Sub
            HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
            Running on Windows 10 (64) virtualized
            on ESXi (Fujitsu Primergy TX150 S8).
            WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

            Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

            Comment


            • #7
              Originally posted by epimetheus View Post
              I'm not a scripting expert by any means, but post #1 has spaces between deviceValue and the parentheses, whereas post #3 does not.
              Yes. I thought that might be the issue, but it seemed to not make any difference.
              As might be evident, I am no expert either.

              Comment


              • #8
                Originally posted by sparkman View Post
                If you have access to the file system, can you grab a copy of the K37.vb file that was generated and post it? You might be better of creating a .vb file yourself that does what you need and call it, rather than trying to make an immediate script statement work.

                Cheers
                Al
                I was under the impression that an immediate script command does not have an actual .vb file associated with it. I do have access to the file system (via FileZilla or SSH), but don't know where to find the .vb file. Could you point me to the path where I might find the file?

                Comment


                • #9
                  Originally posted by Moskus View Post
                  I wasn't aware that this was even possible with a immediate script command.

                  I thought immediate script commands what just that: Commands.
                  I.e. calls to functions or subs, and does not handle any statement you throw at it.
                  Moskus, you may be right, but I am taking an example from the homeseer help files (http://homeseer.com/support/homeseer...lp/default.htm) under Scripting > About Scripts > Executing Single Script Commands :
                  In the Advanced section of the Run Script action, you can add a single script statement. This allows you to execute script commands without creating a file. Statements are preceded with an ampersand (&) so HomeSeer knows to treat it as a statement. For example, the following if then else logic could be typed into the "OR Script Statement" field of the Run Script action:

                  For VBScripts and VB.Net scripting:
                  &if hs.ison(1234) then hs.SetDeviceValue 1234,0 Else hs.SetDeviceValue 1234, 100
                  or
                  &hs.SetDeviceString 5678,"Garage Open",false

                  Multiple statements may be added to the "OR Script Statement" field. Separate each statement with a colon [:].

                  I am not opposed to creating a script file and calling it via trigger, but I have no experience with VB or VB.NET scripting. I have done a minute amount of Python scripting before. Examples are most welcome, so thank you for posting some examples of what my code should look like. I will give it a try.

                  Comment


                  • #10
                    Originally posted by Al_M View Post
                    I was under the impression that an immediate script command does not have an actual .vb file associated with it. I do have access to the file system (via FileZilla or SSH), but don't know where to find the .vb file. Could you point me to the path where I might find the file?
                    HS generates a file for vb.net immediate script commands on the fly. The error message shows /tmp/K37.vb so check that directory. It might be a subdirectory under the main HS one.

                    Cheers
                    Al
                    HS 3.0.0.548: 1965 Devices 1146 Events
                    Z-Wave 3.0.1.262: 122 Nodes on one Z-Net

                    Comment


                    • #11
                      Sparkman,

                      Here is the contents of the K37.vb file:

                      Code:
                      Function Main(parm as object)
                      dim result as object
                      result=if hs.deviceValue(434)>45 then hs.setDeviceValueByRef(434, 45, True) else if hs.deviceValue(434)<25 then hs.setDeviceValueByRef(434, 25, True)
                      return(result)
                      End Function

                      Comment


                      • #12
                        Well that syntax won't work and I don't see a way of making it work. The HS documentation shows vbscript examples and it looks like the complex statements won't work using vb.net. Create the vb file you need using the examples provided by Moskus and put it in the /scripts sub folder and select it in the event.

                        Cheers
                        Al
                        Last edited by sparkman; October 10th, 2016, 10:12 AM.
                        HS 3.0.0.548: 1965 Devices 1146 Events
                        Z-Wave 3.0.1.262: 122 Nodes on one Z-Net

                        Comment


                        • #13
                          Originally posted by Moskus View Post
                          Code:
                          &iif(true, hs.Writelog("Test", "True"), hs.Writelog("Test", "False"))
                          But that actually executes both statements: You'll get both "True" and "False" in the log.
                          Found a way to make it work using the vb If operator
                          Code:
                          &nif(true, hs.Writelog("Test", "True"), hs.Writelog("Test", "False"))
                          Cheers
                          Al
                          HS 3.0.0.548: 1965 Devices 1146 Events
                          Z-Wave 3.0.1.262: 122 Nodes on one Z-Net

                          Comment


                          • #14
                            Wow. It works with "IF" but not "IIF". Didn't see that comming.
                            HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
                            Running on Windows 10 (64) virtualized
                            on ESXi (Fujitsu Primergy TX150 S8).
                            WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

                            Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

                            Comment

                            Working...
                            X