I'm attempting to automatize lights around the man cave, ideally i would like to have the lights to be on as long as the computer screens are on and the lights go off when screensaver kicks in, without using any additional resident software.
So far i managed to catch events 4802 (screensaver start) and 4803 (screensaver stop) and using task scheduler and curl script to fire http request to the machine that handles the lights, and it works, to an extent.
Problem is that whenever the machine enters low power state, screensaver gets killed and 4803 is logged, and i can't differentiate between screensaver being killed by user input or by the windows entering low power state.
Basically i need to catch some events that happen when the screens turn off and on. Is there anything (in generic win7 installation) i could hitch the task on to?
Thanks.
EDIT:
I apologize to people who already answered this question, my question was not worded clearly enough. The machine in question does not actually enter sleep state, hence there is no event 42(kernel-power) or event 1(power-troubleshooter) generated in event logs, the machine only enters some kind of low-power state where it consumes about 53W, instead of the usual 180W, while i could use this to track the power state of this one specific machine, i would not be able to use the same method of detection for the other 3 computers in the room, since they do not have the required hardware (UPS) connected to them.
What i am looking for, is events that occur whenever monitors of the computer are powered off and back on by windows (not by their respective power buttons) as a result of the windows power management. Basically anything that would allow me to synchronize the lights in the cave with the state of the monitors and allow the task scheduler to fire off script that manipulates the lights.
Best Answer
Hopefully you've found another solution for this task by now, either way this was an interesting problem I wanted to take a crack at, and maybe someone else will benefit. Rather than trying to monitor screensaver states, my solution uses the "idleness" monitoring options within task scheduler. While this was built on Windows 10, I believe the functions used should be the same in W7.
Overview
Basic path of events
Setup
Copy the powershell executable into your new folder folder:
Create "Idle.ps1" and paste in script. On the first line of the script, specify your folder containing scripts and copy of powershell.exe:
$mydate = Get-date echo "$mydate - PID: $nid - Last line in Idle, should not have been reached." | out-file -Append $logfile
Create "Watcher.ps1" in same folder and paste in script, again specifying the folder:
}
Open task scheduler as admin and create the "Idle" task;
Add the following arguments, replacing the file path with your own:
-ExecutionPolicy Bypass -file "C:\scripts\idle.ps1"
Go to the conditions tab and check the box to only start if idle, setting the idle time to your chosen time out.
Hope someone finds this useful!
Tim