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?
Announcement
Collapse
No announcement yet.
String vs. value from device?
Collapse
X
-
Originally posted by mlevin77 View PostWhat 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?
-
Originally posted by mrhappy View Postthe only real option is to set another device with the value from that string (see .net convert.todouble methods or double.tryparse)
Comment
-
Originally posted by mlevin77 View Postsorry, 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.
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
-
Originally posted by mrhappy View Postcould 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
-
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
Comment