Announcement

Collapse
No announcement yet.

How to Parse device string and create device values

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

    How to Parse device string and create device values

    Using Homeseer for 10 years now but yet my scripting ability is still weak.

    I have a device that the output is saved as device string. This is what the device string reads 40.909,-74.384 which I am able to retrieve via hs.devicestring command.

    Can someone write me the script to break this string into 2 device values. So basically looking for a script that could output the that string into device values:

    40.909 = long
    -74.384 = lat

    Appreciate any assistance you can give.

    Thank you

    #2
    Just typed this and it's untested but should get you going.

    Sub Main(parm as object)

    ' Here you can use something like
    'dim sVal as string = hs.deviceString("A1")

    ' Testing string
    dim sVal as string = "40.909,-74.384"

    dim splitVal() as string

    splitVal = sVal.split(",")

    hs.writelog("data",splitVal(0))
    hs.writelog("data",splitVal(1))

    'here you can assign the above data to you device values ...
    'hs.setDeviceValue("A1", splitVal(0))
    '...

    End Sub
    💁‍♂️ Support & Customer Service 🙋‍♂️ Sales Questions 🛒 Shop HomeSeer Products

    Comment


      #3
      Thanks Rupp but I cant get it to work based on script you gave me which I tried to tweak without success. Please help more.

      Here is the basic script so far:

      Sub Main
      Dim sVal
      sVal = hs.devicestring("%1")
      dim splitVal() as string
      splitVal = sVal.split(",")
      hs.WriteLog "Info", splitVal(0)
      hs.WriteLog "Info", splitVal(1)

      End Sub


      Error - Running script, script run or compile error in file: check string location1025:Expected end of statement in line 4 More info: Expected end of statement

      Comment


        #4
        Try saving Rupp's original as .vb
        It's a vb .net script, and I don't think Split will work with VB6.
        Real courage is not securing your Wi-Fi network.

        Comment


          #5
          Worked perfectly now. Thanks a ton.

          Told you I was bad at scripting!

          Comment


            #6
            Hate to bother you again but

            How do I add script code to now check if each of the values is less than or greater than a range of numbers and then trigger an event if the values fall outside that.

            Using numbers I gave in my example, I want to check if:

            splitVal(0) falls between range of 40.901 and 40.911

            and if

            splitVal(1) falls between range of -74.378 and -74.386

            and if BOTH values DO NOT fall in those ranges - trigger an event or set a device to ON.

            and if BOTH values DO fall in those ranges - trigger another event or etc.

            Please help again - much appreciated.

            Comment


              #7
              Got this figured out and will post it soon for those who may want this.

              Comment

              Working...
              X