Announcement

Collapse
No announcement yet.

log file access?

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

    log file access?

    is there a way to access the log file, or better yet the database, so i can track each and every device change?

    i'd like to put together a database to capture each state change, for use down the road. (for example, the fridge has opened xxx times since xxxx date) and trend the data


    tanks

    #2
    I wouldn't mess in the log for this, look here http://homeseer.com/support/homeseer...uschangecb.htm for how I would do it, register for status change and then when you process the return log it to a database. The database AFAIK only stores the devices current value and personally I am not sure I would start to mess with it myself in a script.

    Comment


      #3
      I wasn't thinking a script, I was thinking an external program that would run periodically. Or a plug in


      Sent from my iPhone using Tapatalk

      Comment


        #4
        I've got to agree with mrhappy here, use the status change callback and then work from there, mcsXap uses it to great success.


        Sent from my iPad using Tapatalk HD
        Author of Highpeak Plugins | SMS-Gateway Plugin | Blue Iris Plugin | Paradox (Beta) Plugin | Modbus Plugin | Yamaha Plugin

        Comment


          #5
          Originally posted by fischb22 View Post
          I wasn't thinking a script, I was thinking an external program that would run periodically. Or a plug in


          Sent from my iPhone using Tapatalk
          Not sure I have seen a HS3 plugin for this, there was a HS2 one though written to log to an SQL DB. You could not run a program periodically because I don't believe as I say there is any history with the data in the HS database and you would need to capture everything live as it changed. Is there a reason you don't want to use a script? It is likely to be just as reliable as a plugin and they would use the same method.

          Comment


            #6
            I'm not too comfortable with scripting, where as a standalone program I am. I guess I could learn, just need to be sure I can write to a database from inside the script.


            Sent from my iPhone using Tapatalk

            Comment


              #7
              Originally posted by fischb22 View Post
              I'm not too comfortable with scripting, where as a standalone program I am. I guess I could learn, just need to be sure I can write to a database from inside the script.


              Sent from my iPhone using Tapatalk
              Fair enough, this is a script I wrote some time ago (I don't use it any more as I was not actually doing anything with the data) which might get you in the right direction. This is set up as I said (the "Callback" sub was run when HS started) and logs the data into an SQLite DB.

              This is for HS2 so it would be slightly different for HS3 but the principle is the same and would need some changes in a couple of places.

              Code:
              Imports System.Data.SQLite
              Imports System.Text
              
              Const DataPath As String = "\data\generaldata.db3"
              Const L As String = "DevLogging"
              
              Sub Main(ByVal Parms As Object)
              
              Try
              
              Dim SQLconnect As New System.Data.SQLite.SQLiteConnection()
              Dim SQLcommand As System.Data.SQLite.SQLiteCommand
              
              SQLconnect.ConnectionString = "Data Source=" & hs.getapppath & datapath & ";"
              SQLconnect.Open()
              SQLcommand = SQLconnect.CreateCommand
              
              Dim DSt As String = Nothing
              
              If Parms(2) <> 17 Then
              
              Select Case Parms(0)
              Case "]", "`", "Y"
              'hs.writelog(L, "Ignore - " & Parms(0))
              
              Case Else
              
              DSt = "INSERT INTO DevStatusData (DateAdded, UC, Status) VALUES ('" & DateTime.Now.ToString("yyyy-MM-dd HH:mm") & "','" & Parms(0) & Parms(1) & "','" & Parms(2) & "');"
              
              'hs.writelog(L,DSt)
              
              SQLcommand.CommandText = DSt
              SQLcommand.ExecuteNonQuery()
              
              End Select
              
              SQLcommand.Dispose()
              SQLconnect.Close()
              
              End If
              
              Catch ex as Exception
              
              hs.writelog(L, "Error: " & ex.Message)
              
              End Try
              
              End Sub
              
              Sub CallBack(ByVal Parms As Object)
              
              hs.RegisterStatusChangeCB("logdevices.vb","Main")
              
              End Sub
              
              Sub CDB(ByVal Parms As Object)
              
              Try
              
              Dim SQLconnect As New System.Data.SQLite.SQLiteConnection()
              Dim SQLcommand As System.Data.SQLite.SQLiteCommand
              
              SQLconnect.ConnectionString = "Data Source=" & hs.getapppath & datapath & ";"
              SQLconnect.Open()
              SQLcommand = SQLconnect.CreateCommand
              
              SQLcommand.CommandText = "CREATE TABLE IF NOT EXISTS DevStatusData (DateAdded DATE, UC TEXT, Status INTEGER);"
              SQLcommand.ExecuteNonQuery()
              
              SQLcommand.Dispose()
              SQLconnect.Close()
              
              hs.writelog(L, "Database Created")
              
              Catch ex as Exception
              
              hs.writelog(L, "Error: " & ex.Message)
              
                  End Try
              
              
              End Sub
              
              Sub WeedDB(ByVal Parms As Object)
              
                  hs.writelog(L, "Weeding Old DB Records")
              
                  Dim SQLconnect As New System.Data.SQLite.SQLiteConnection()
                  Dim SQLcommand As System.Data.SQLite.SQLiteCommand
              
                  SQLconnect.ConnectionString = "Data Source=" & hs.getapppath & "\data\generaldata.db3;"
                  SQLconnect.Open()
                  SQLcommand = SQLconnect.CreateCommand
              
                  SQLcommand.CommandText = "DELETE FROM DevStatusData WHERE DateAdded BETWEEN '" & DateTime.Now().AddMonths(-1).ToString("yyyy-MM-dd") & "' AND '" & DateTime.Now().AddMonths(-6).ToString("yyyy-MM-dd") & "'"
              
                  hs.writelog(L, SQLCommand.CommandText)
                  SQLcommand.ExecuteNonQuery()
              
              End Sub

              Comment


                #8
                Why reinvent the wheel. Ultralog already does this. Have a read here:
                http://board.homeseer.com/showthread.php?t=169575
                💁‍♂️ Support & Customer Service 🙋‍♂️ Sales Questions 🛒 Shop HomeSeer Products

                Comment


                  #9
                  Thanks Rupp, I'll give that a gander


                  Sent from my iPhone using Tapatalk

                  Comment

                  Working...
                  X