Energy saving project

Forum about Domotica, home automation and saving energy.

Energy saving project

Postby Alexander » Wed Jun 17, 2009 9:11 am

@lempens: so using WMI?
Global Moderator
Global Moderator
Posts: 1532
Joined: March 2007
Location: Netherlands

Energy saving project

Postby AshaiRey » Wed Jun 17, 2009 11:18 am

There are many roads that lead to Rome..

My domotica server is also the machine where the printer is connected at so there is no need to use WMI, which according me is a bit overkill. It will add extra patches to install and maintainance to your server. In a server farm however it is a very powerfull tool
Senior Member
Senior Member
Posts: 1301
Joined: February 2009
Location: Netherlands

Re: Energy saving project

Postby Irritanterik » Mon Aug 20, 2012 9:47 pm

Today I implemented AshaiRey's script for controlling my network printer. Although it’s a network printer, I share it as a local printer on the server, so all print jobs are placed in the spool-folder on the server.
I compressed the script a little, so now only one recurring event is necessary:
- Printer will be turned on when it's off AND there are jobs waiting.
- Printer will be turned off when it's on AND there are no jobs waiting AND it's more than 10 minutes since power was turned on.

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
      '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
HP t5630w with Homeseer 2 > Will migrate to Homey | RFXLAN | IRTrans | Opentherm Gateway | ITHO ECO-FAN integration | Harrison Curtain | Z-wave
User avatar
Posts: 82
Joined: April 2011
Location: Amersfoort


Return to Energycontrol & Home Automation Forum

Who is online

Users browsing this forum: No registered users and 1 guest