Energy saving project

Forum about Domotica, home automation and saving energy.
Alexander
Global Moderator
Global Moderator
Posts: 1532
Joined: Sat Mar 10, 2007 11:19 pm
Location: Netherlands

Energy saving project

Post by Alexander »

@lempens: so using WMI?
AshaiRey
Senior Member
Senior Member
Posts: 1310
Joined: Mon Feb 02, 2009 5:27 pm
Location: Netherlands
Contact:

Energy saving project

Post by AshaiRey »

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
User avatar
Irritanterik
Member
Member
Posts: 82
Joined: Tue Apr 19, 2011 1:00 pm
Location: Amersfoort
Contact:

Re: Energy saving project

Post by Irritanterik »

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
	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
HP t5630w with Homeseer 2 > Will migrate to Homey | RFXLAN | IRTrans | Opentherm Gateway | ITHO ECO-FAN integration | Harrison Curtain | Z-wave
Post Reply

Return to “Energycontrol & Home Automation Forum”