Energy saving project
Posted: Wed Jun 17, 2009 10:11 am
@lempens: so using WMI?
Domotica - Home Automation Forum
https://www.domoticaforum.eu/
Code: Select all
Const LogLevel As Integer = 1 '0 = no logging, 1 = normal logging, 2 = debug logging
Const ScriptName As String = "TON_Printer"
Const cPrinterDeviceId As String = "C3"
Const cPrinterSpoolFolder as String = "C:\WINDOWS\system32\spool\PRINTERS"
Const cPrinterPowerDelayMinutes as Integer = 10
Public Sub Main(ByVal Parms As String)
Log("Check Printer", 2)
Dim oFS, oFolder
Dim oEvent
Dim dLastChange
oFS = CreateObject("Scripting.FileSystemObject")
oFolder = oFS.GetFolder(cPrinterSpoolFolder)
dLastChange = hs.DeviceLastChange(cPrinterDeviceId)
' Check and see if there are files to print
Log("File count in folder " & cPrinterSpoolFolder & " = " & oFolder.Files.Count, 2)
If oFolder.Files.Count > 0 Then
'If printer is off and spool contains files
If hs.IsOff(cPrinterDeviceId) Then
Log("Switch printer on")
hs.ExecX10(cPrinterDeviceId, "on", 0, 0)
End If
Else
'If printer is on, spool not containing files and too long on
If NOT(hs.IsOff(cPrinterDeviceId)) And DateTime.Now.Subtract(dLastChange).TotalMinutes >= cPrinterPowerDelayMinutes Then
Log("Switch printer off")
hs.ExecX10(cPrinterDeviceId, "off", 0, 0)
End if
End If
End Sub
Private Sub Log(Message As String, Optional MessageLevel As Integer = 1)
If LogLevel >= MessageLevel Then
hs.WriteLog(ScriptName, Message)
End if
End Sub