Announcement

Collapse
No announcement yet.

HS2 script not running in HS3

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

  • HS2 script not running in HS3

    I have a HS2 script that imports analog value from a text file and updates 21 devices in HS. I'am trying to run the same script on my HS3 with no luck.

    I get the following error.

    Running script C: \Program Files (x86)\HomeSeerHS3\scripts\TacImport.vb: An exception occurred in the case of a activation. Could not find part of the path I:\tacvista\out.txt.

    I: is a mapped device and I can see the file in the correct location.

    I'am running windows 8.1 on my HS3

    Is there any command used in my script that HS3 does not support ?



    Imports System.IO

    Sub Main(byVal Parm As Object)
    Dim Filereader As Streamreader
    Dim Path As String = "I:\tacvista\out.txt"
    Dim Data As String
    Dim Value As String
    Dim ct As Integer = 0
    Filereader = New StreamReader(Path)
    Do While FileReader.Peek >= 0
    Data=Filereader.ReadLine()
    If Data.Length > 0 then
    ct +=1
    If ct > 21 then exit do
    Value=hs.stringitem (Data,1,";")
    hs.setdevicestring ("R" & ct.ToString,Value)
    end if
    Loop
    Filereader.Close()

    End Sub

  • #2
    Two lines jump out on me (which may be causing the error that the file is not creating)

    Value=hs.stringitem (Data,1,";")
    hs.setdevicestring ("R" & ct.ToString,Value)

    1) hs.stringitem is gone, you will need to find an alternative, I think Jon00 posted a function that is a good replacement
    2) setdevicestring accepts a parameter of the device reference whereas it looks like you are trying to set it with a device code,
    My Plugins:

    Pushover 3P | DoorBird 3P | Current Cost 3P | Velleman K8055 3P | LAMetric 3P | Garadget 3P | Hive 3P |
    Yeelight 3P | Nanoleaf 3P

    Comment


    • #3
      hs.Stringitem replacement function is here.
      Jon

      Comment


      • #4
        Thanks,

        Comment


        • #5
          I'am getting a error that I can't figure out.

          Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\TacImport.vb: an argument has not been provided for parameter Sep in Public Function Stringitem(Str As String, Index As Integer, Sep As String) As String.


          Imports System.IO
          Function Stringitem(ByVal Str As String, ByVal Index As Integer, Byval Sep As String) As String
          Try
          Dim Result() As String = System.Text.RegularExpressions.Regex.Split(Str, System.Text.RegularExpressions.Regex.Escape(Sep))
          Return Result(Index-1)
          Catch
          Return ""
          End Try
          End Function

          Sub Main(byVal Parm As Object)
          Dim Filereader As Streamreader
          Dim Path As String = "I:\tacvista\out.txt"
          Dim Data As String
          Dim Value As String
          Dim ct As Integer = 0
          Filereader = New StreamReader(Path)
          Do While FileReader.Peek >= 0
          Data=Filereader.ReadLine()
          If Data.Length > 0 then
          ct +=1
          If ct > 21 then exit do
          Value=Stringitem(Data,1,";")
          Stringitem ("R" & ct.ToString,Value)
          end if
          Loop
          Filereader.Close()

          End Sub

          Comment


          • #6
            Value=Stringitem(Data,1,";")
            Stringitem ("R" & ct.ToString,Value)

            Not sure what you are trying to do here but this is why the error is coming up in that there are only two parameters going to stringitem whereas it needs three.
            My Plugins:

            Pushover 3P | DoorBird 3P | Current Cost 3P | Velleman K8055 3P | LAMetric 3P | Garadget 3P | Hive 3P |
            Yeelight 3P | Nanoleaf 3P

            Comment


            • #7
              I'am trying to read temp values stored on separate rows in a text file that is generated by the "PLC" controlling the heat.

              The script reads one row and then updates device "R1" and then reads the second row and then updates device R2 and so on. until R21

              I have just figured out that I cant be using the address with hs.setdevicestring. As I understand you have to use reference ID that HS3 creates.

              This is a problem as this devices reference id are not in sequence numbers.

              I have to do this different in HS3.....

              mrhappy, se now that you pointed this out..

              Comment


              • #8
                Originally posted by jonas.hellgren View Post
                I'am trying to read temp values stored on separate rows in a text file that is generated by the "PLC" controlling the heat.

                The script reads one row and then updates device "R1" and then reads the second row and then updates device R2 and so on. until R21

                I have just figured out that I cant be using the address with hs.setdevicestring. As I understand you have to use reference ID that HS3 creates.

                This is a problem as this devices reference id are not in sequence numbers.

                I have to do this different in HS3.....

                mrhappy, se now that you pointed this out..
                If you just wanted to update the value (you could set some value pairs up manually to have the temperature units displayed) then confusingly setdevicevalue accepts a code rather than a reference and may be easier to use.

                Edit: Alternatively as these new devices are not going to change their references you could have an array of the values (you would have to fill it manually) so it would be something like

                Dim dvReferences(20) as integer = {2345,2451,1245,1265,1253} 'need to fill this up at the start of the script will all the references

                hs.setdevicestring(dvReferences(ct.ToString),Value) 'gets the reference from the array
                Last edited by mrhappy; May 31st, 2014, 12:31 PM.
                My Plugins:

                Pushover 3P | DoorBird 3P | Current Cost 3P | Velleman K8055 3P | LAMetric 3P | Garadget 3P | Hive 3P |
                Yeelight 3P | Nanoleaf 3P

                Comment


                • #9
                  Thanks, now everything is working.
                  This is the final vb script file.
                  I had to use UNC path to the server, mapped drive did not work.


                  Imports System.IO
                  Function Stringitem(ByVal Str As String, ByVal Index As Integer, Byval Sep As String) As String
                  Try
                  Dim Result() As String = System.Text.RegularExpressions.Regex.Split(Str, System.Text.RegularExpressions.Regex.Escape(Sep))
                  Return Result(Index-1)
                  Catch
                  Return ""
                  End Try
                  End Function

                  Sub Main(byVal Parm As Object)
                  Dim Filereader As Streamreader
                  Dim Path As String = "
                  \\hjpfs1\install\TacVista\out.txt"
                  Dim Data As String
                  Dim Value As String
                  Dim IValue as Double
                  Dim ct As Integer = 0
                  Filereader = New StreamReader(Path)
                  Do While FileReader.Peek >= 0
                  Data=Filereader.ReadLine()
                  If Data.Length > 0 then
                  ct +=1
                  If ct > 21 then exit do
                  Value=Stringitem(Data,1,";")
                  Value = Replace(Value,”,”,””)
                  Value = Replace(Value,”.”,”,”)
                  IValue = CDbl(Value)
                  hs.SetDeviceValue ("R" & ct.ToString,IValue)
                  end if
                  Loop
                  Filereader.Close()

                  End Sub
                  Attached Files

                  Comment

                  Working...
                  X