| device Newbie
 
  
 
 Joined: May 26 2009
 Online Status: Offline
 Posts: 33
 | 
          For various reasons over time the PH database became out of sync with the actual devices. So this morning I wrote a VBScript to synchronize the two. There may be easier ways I am unaware of to do this. I use VbsEdit for writing and basic "out of PH" debugging so the Include procedure and "phstub.vbs" script establish a stubbed PH execution environment to facilitate debugging. Anyway thought someone might find it useful / interesting.
           | Posted: October 06 2013 at 11:59 | IP Logged |   |  
           | 
 |  
 D
 
 Option Explicit
 
 Sub Include(sInstFile)
 On Error Resume Next
 
 Dim oFSO, f, s
 
 Set oFSO = CreateObject("Scripting.FileSystemObject")
 If oFSO.FileExists(sInstFile) Then
 Set f = oFSO.OpenTextFile(sInstFile)
 s = f.ReadAll
 f.Close
 ExecuteGlobal s
 Else
 MsgBox sInstFile & " does not exist", 0
 End If
 
 Set oFSO = Nothing
 Set f = Nothing
 End Sub
 
 Sub getdevices()
 Dim sql, sqlstat, rows, cid, index, doupdate, id, iengine, usexaldb, realiengine
 sql = "SELECT id, iengine, usexaldb FROM insteondevices where address <> '00.00.00'"
 sqlstat = ph.sqlselect(1, sql)
 rows = ph.getsqlrows(1)
 cid = ph.getglobal_s("CONTROLLER ID")
 For index = 1 To rows
 doupdate = 0
 id = UCase(ph.getdata(1, CLng(index), CLng(1)))
 If (id <> cid) Then
 iengine  = CLng(ph.getdata(1, CLng(index), CLng(2)))
 usexaldb  = CLng(ph.getdata(1, CLng(index), CLng(3)))
 realiengine  = CLng(ph.insteonwithret(id, 13, 0))
 If (realiengine < 0 Or realiengine > 2) Then
 Call ph.usermessage("Get Iengine for " & id & " failed with return code " & realiengine)
 Else
 If (iengine >= 0 And iengine <= 2 And usexaldb >= 0 And usexaldb <= 1)  Then         &n bsp;
 If (realiengine <> iengine) Then
 Call ph.usermessage(id & " update iengine from " & iengine & " to " & realiengine)
 doupdate = 1
 End  If
 If (realiengine > 0 And usexaldb <> 1) Then
 Call ph.usermessage(id & " update usexal dbfrom " & usexaldb & " to 1")
 usexaldb  = 1
 doupdate = 1
 End  If
 If (doupdate = 1) Then
 sql = "UPDATE insteondevices SET iengine = " & realiengine & ", usexaldb = " & usexaldb & " WHERE id = '" & id & "'"
 Call ph.usermessage(sql)
 Call ph.directsql(sql)
 End  If
 Else
 Call ph.usermessage(id & " unknown database values iengine = " & iengine & " usexaldb = " & usexaldb)
 End  If
 End  If
 End If
 Next
 ph.sqldestroy(1)
 End Sub
 
 'Call Include("phstub.vbs")
 
 'Call getdevices()
 
 
 |