Announcement

Collapse
No announcement yet.

String vs. value from device?

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

    String vs. value from device?

    What is the relationship between a device's string and its value? I have a virtual device (made by the Web Scraper plugin) and the string is correct but the value is not - what's the difference and how do I get them to match?

    #2
    Originally posted by mlevin77 View Post
    What is the relationship between a device's string and its value? I have a virtual device (made by the Web Scraper plugin) and the string is correct but the value is not - what's the difference and how do I get them to match?
    I would imagine the plugin does not know that piece of data you are extracting is a numeric value and could as well just be a load of text for all it knows. If the plugin does not have the option to attempt to convert the string then I would imagine the only real option is to set another device with the value from that string (see .net convert.todouble methods or double.tryparse) - I think I would avoid setting the plugins own device as that value may be used for some other purpose.

    Comment


      #3
      Originally posted by mrhappy View Post
      the only real option is to set another device with the value from that string (see .net convert.todouble methods or double.tryparse)
      sorry, I'm not sure how to use .net or how to incorporate code into a new virtual device: is there a basic tutorial for this somewhere? And, the device does have a value (it's just wrong), so it's getting it somehow; I wonder what it's doing to get that value.

      Comment


        #4
        Originally posted by mlevin77 View Post
        sorry, I'm not sure how to use .net or how to incorporate code into a new virtual device: is there a basic tutorial for this somewhere? And, the device does have a value (it's just wrong), so it's getting it somehow; I wonder what it's doing to get that value.
        The plugin could be using the value for some other reason, if the value was similar to the data then that might point to a formatting issue but if it is very different then it could be using it as some sort of status indicator (value 1 is OK data, value 2 is incorrect patter, value 3 is a web error...that sort of thing) which is an additional use for values. HS2 you could have totally independent values and strings, HS3 tried to get away from that and have strings which were dependent on values but in some cases that is impossible if you are holding string data that do not fit a fixed set of values.

        Regardless, could you give me the reference of your device you wish to read the string of, the minimum/maximum set of values and any decimal places. I will write a short script to create the device and do what you are after.

        Comment


          #5
          Originally posted by mrhappy View Post
          could you give me the reference of your device you wish to read the string of, the minimum/maximum set of values and any decimal places. I will write a short script to create the device and do what you are after.
          that's very kind!! At the moment, all the strings come back with values as a floating point number with two places before the decimal point and one after. So a 4 would be 04.0. The field is a fixed length and always uses 4 characters, hence values like 00.0, 04.0, 09.5 or 10.5. The reference ID is "101". Is this the info you need, or should I send you sample text from the web page it's scraping and the REGEX I use to get the string out - would that be useful? And, after you write the script, please tell me how to use/implement it. Thank you very much - I appreciate your effort.

          Comment


            #6
            This is a bit quick and ugly but worth a go, copy all of this into notepad and save it to your scripts directory as something like HS3DeviceValue.vb

            Go into the HS control panel and enter:

            hs.RunScriptFunc("HS3DeviceValue.vb","CreateDevices",Nothing ,False,False)

            This should then create the device under the room "Value Device", take a look and see if the device is there. In the HS log you should get the reference of this new device (should look like "Device Created *** Take Note: 232 *** ")

            Open the script back up and in the top of the script you will see "Dim dvRef As Integer = 224" - change that 224 value to the value of the new device. Save the script.

            Run the script from an event and see what it does, it should update this new device with the value. Whether or not it actually does this I don't know and it will depend on a couple of things, if it fails then look in the log and paste the results here.

            You are going to have to run the script at the same interval that you scrape the page and I would suggest a slight delay (to cater for any download delays) if you can before running this.

            Code:
            Sub Main(ByVal Parm As Object)
            
                Try
            
                    Dim dvRef As Integer = 224 'Change this to the reference you get from the log entry on the first script run
                    Dim OriginString As String = hs.deviceString(110)
                    Dim DoubleResult As Double
            
                    hs.writelog("Device", "Raw String Value: " & OriginString)
            
                    If Double.TryParse(OriginString, DoubleResult) Then
                        'we have success
                        hs.setdevicevaluebyref(dvRef, DoubleResult, True)
                    Else : hs.writelog("Device", "I Cannot Parse The String")
                    End If
            
                Catch ex As Exception : hs.writelog("TestCheck", "Error: " & ex.Message.ToString)
                End Try
            
            End Sub
            
            
            Sub CreateDevices(ByVal Parms As Object)
            
                Try
            
                    Dim dv As Scheduler.Classes.DeviceClass = Nothing
                    dv = hs.GetDeviceByRef(hs.NewDeviceRef("Test Value Device"))
                    dv.Location(hs) = "Value Device"
            
                    Dim Pair As VSPair
            
                    Pair = New VSPair(HomeSeerAPI.ePairStatusControl.status)
                    Pair.PairType = VSVGPairType.Range
                    Pair.RangeStart = 0
                    Pair.RangeEnd = 100
                    Pair.RangeStatusDecimals = 1
                    hs.DeviceVSP_AddPair(dv.Ref(hs), Pair)
                    dv.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES)
            
                    hs.setdevicevaluebyref(dv.Ref(hs), 0, True)
                    hs.saveeventsdevices()
                    hs.writelog("Device Created", "*** Take Note: " & dv.ref(Nothing) & " ***")
            
                Catch ex As Exception : hs.writeLog("DeviceCreation", "Create Devices Exception: " & ex.message.tostring)
                End Try
            
            End Sub

            Comment

            Working...
            X