Announcement

Collapse
No announcement yet.

Create Virtual Device From Text File

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

    Create Virtual Device From Text File

    I am going to display speedtest information on my HSTouch. I have a script which leverages speedtest-cli --simple (https://pypi.org/project/speedtest-cli/) and outputs that to a file called speed.txt. I am able to run this through HS without any issues.

    I want to take the contents of speed.txt and create a virtual device which I can then display in HSTouch. The content of the txt file looks like this:

    Ping: 6.237 ms
    Download: 990.55 Mbit/s
    Upload: 24.33 Mbit/s

    I've trying to leverage the script written by Rupp and CJVann (https://forums.homeseer.com/forum/le...ay-a-text-file) but when I go to run the script I get a number of errors (see attached compiling error).

    Any assistance would be appreciated
    Attached Files

    #2
    The code you are trying to use is a very old Visual Basic method to read/write files. There are also several issues including a mix between VB.NET and VBScript formatting, code examples which came from HS2 and End SubSub rather than End Sub.

    Try this more modern VB.NET example:

    Code:
        Sub Main(Parm As Object)
    
            Dim Filename As String = "C:\Users\Todd\speed.txt"
            Dim Data As String = ""
            For Each Line As String In System.IO.File.ReadLines(Filename)
                Data &= Line & "<br />"
            Next
            hs.SetDeviceStringByName("V101", Data, True)
    
        End Sub
    I've assumed V101 is the name of the virtual device. If you want to use its device reference number, example 1234, you can use:

    hs.SetDeviceString(1234, Data, True) instead.

    To get the data on separate lines in the virtual device, you need to use HTML code (<BR /> break ) rather than a newline character which will not work in this instance.

    BTW, you don't need to clear the device string first as it will be overwritten anyway with the speed.txt contents.
    Jon

    Comment


      #3
      Thanks Jon, quick noob question but in HS4, where did the string value go in advanced settings for a Virtual Device?
      In the above case I'm going to go by device reference as you mentions so I've changed it to hs.SetDeviceString(1508, Data, True)
      Attached Files

      Comment


        #4
        It would show on the Status line.

        You may need to change your virtual device to be status only. You may need to use the old HS3 interface to do that. Call /deviceutility rather than /devices.html

        To check it is reading the file correctly, add:

        hs.writelog("Test",Data) at the bottom of the routine and check the HS Log.

        Jon

        Comment


          #5
          Thanks Jon, I really appreciate you taking the time to look at this and find a solution.
          Attached Files

          Comment

          Working...
          X