Announcement

Collapse
No announcement yet.

where do all the decimal places come from :)

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

    where do all the decimal places come from :)

    in the next release it would be nice to round to 2dp or have the option. i'm not sure these decimal places really exist given the rfxcom plugin dose not show beyond 1 dp when I interrogate the variable. Nice plugin by the way I also store data but I have no need for this now i have your plugin is it possible to query the sql light database from other vb programs whilst your plugin is running. I currently use sql queries but store and retrieve in MSAccess format. Any help with code to open an sql light db would be appreciated as i'm not a proper programmer and find all the set up stuff hard as i don't do it enough......

    Thanks Phill
    Attached Files

    #2
    Originally posted by phillb View Post
    in the next release it would be nice to round to 2dp or have the option. i'm not sure these decimal places really exist given the rfxcom plugin dose not show beyond 1 dp when I interrogate the variable. Nice plugin by the way I also store data but I have no need for this now i have your plugin is it possible to query the sql light database from other vb programs whilst your plugin is running. I currently use sql queries but store and retrieve in MSAccess format. Any help with code to open an sql light db would be appreciated as i'm not a proper programmer and find all the set up stuff hard as i don't do it enough......

    Thanks Phill
    I've noted the decimal point as a feature request. I'll probably put it as an overall default and a per-device setting override. (For all the gory details on why this happens, see https://en.wikipedia.org/wiki/IEEE_754 - HS uses "Double" instead of "Decimal", so the values are imprecise.)

    As far as querying, mostly you'll just need to change your data type objects to be SQLite specific:

    Code:
    Public Sub RunQuery(parms As String)
    
    	hs.WriteLog("TEST", "Starting...")
    	
    	Dim db As New SQLite.SQLiteConnection("Data Source=C:\Program Files (x86)\HomeSeer HS3\Data\skWare\DeviceHistory\HSPI_SKWARE_DEVICE_HISTORY.db3")
    	db.Open()
    
    	Dim q As New SQLite.SQLiteCommand("SELECT DEVICE_REF, CHANGE_DATE, NEW_VALUE, NEW_STRING FROM DEVICE_VALUE_HISTORY WHERE Device_Ref=@ref AND CHANGE_DATE>=@from AND CHANGE_DATE<=@to", db)
    	q.Parameters.Add("@ref", DbType.Int32)
    	q.Parameters.Add("@from", DbType.String)
    	q.Parameters.Add("@to", DbType.String)
    	q.Prepare()
    
    	q.Parameters("@ref").Value = 100
    	q.Parameters("@from").Value = "2017-12-01 00:00:00" 'easiest way to get this format is 'mydatevar.ToString("u").Replace("Z","")'
    	q.Parameters("@to").Value = "2017-12-31 23:59:59"
    	
    	Dim dr As SQLite.SQLiteDataReader = q.ExecuteReader()
    	If dr.HasRows Then
    		While dr.Read()
    			hs.WriteLog("TEST", dr("CHANGE_DATE") & "=" & dr("NEW_VALUE"))
    		End While
    	Else
    		hs.WriteLog("TEST", "No values found.")
    	End If
    
    	Try
    		dr.Close()
    		db.Close()
    	Catch ex As Exception
    	
    	End Try
    	
    	hs.WriteLog("TEST", "Finished.")
    	
    End Sub
    Note that in order for this to work, you'll have to stop HS3, add the SQLite assembly to your HS3\Config\settings.ini file's list of references, then restart it. The line should look like this:

    ScriptingReferences=<WHATEVER WAS ALREADY HERE>,System.Data.SQLite;C:\Program Files (x86)\HomeSeer HS3\Bin\System.Data.SQLite.dll

    Comment


      #3
      Thanks Very Much

      code snippet much appreciated thanks for the plug in

      Phill

      Comment

      Working...
      X