PC in use detection

I’ve added a PIR sensor to my bedroom at the doorway and use it to turn on the lights.
When to turn off the lights is the bit tricky as if I sit down and use the PC then I won’t trigger the PIR again to keep the lights on.

I could tie it to a network binding and allow the light to turn off if the PC goes to sleep - but depending on what I’m doing I may have the PC set to not sleep as it crunches away on something.

My idea is to have a Windows service that hooks into mouse activity - if there has been mouse activity in the last minute then throw out an MQTT (or maybe start a server for the network binding to ping a port on).

Is there any prior art / existing binding that would help do this?

Just an idea (I have no clue how you’d implied it)

Can you tie in the Screen saver activation to an item in OH?

By adding a Curl command to the start and stop process of the screen saver?

In much the same way as you can add apps / commands to the Startup / login / logout / shutdown routine.

I’d look at adding two items to OH, to store the state of the machine and the state of the screen saver.


To connect your WIndows-PC to openHAB you could try https://iotlink.gitlab.io/

I have not tested this myself, yet.
And I am not sure if you can trigger on “mouse activity”.
But maybe check if the Screen got into standby.

1 Like

Thanks for the suggestions. The IotLink looks interesting but I don’t think it has a sensor for what I was thinking.

After some more thought I think the easiest solution is to put another PIR sensor under the desk to detect my legs (and avoid person-in-bed tripping it)

Instead of a PIR at the door why not use a break beam switch.They can turn lights on as you enter room and off as you leave. Or place it on your desk, seating area etc. You could make one using RPi

You could use a combination of both the network binding and PIR, That should cover it, (unless you fall asleep in front of the computer. On the other hand, then you dont need the light turned ON anyway :rofl:).

1 Like

Most simple one is to use a website which detects activity and then sends it to an item in OH via REST. However this requires you to use a website and at some point always clicking on something there…

The other option would be to use OS tools to detect mouse movement (–> I bet e.g. Windows has some built in functions for that --> found it via quick Google search http://dataerror.blogspot.com/2005/02/detect-windows-idle-time.html) and write some code to compile an executeable. Within this executable just also add that something is sent to the OH REST interface, if something changes. Should be all that complicated, but still takes some hours unfortunately. That’s at least how I would solve it

You may have a look at AHK ( AutoHotKey ).
Should be possible to detect idle time like e.g. https://autohotkey.com/board/topic/82735-idle-then-do-this/
You can define actions and execute scripts.

I use AHK on my work PC already for shortcuts to type out long strings - this is an excellent solution that I didn’t know AHK was capable of :+1:. Will implement and post script.

re: beam sensor - that’s an interesting sensor I hadn’t thought of. The advantage of the PIR is its it’s such a cheap self contained little package using 2xAAA - broadcasting 433MHz coupled with a Sonoff bridge. I figure the AAA is going to last ages as the 433MHz must be a lot less power hungry than a device connected to wifi. Will keep it in mind though. Connecting it to an ESPY would be even better - a Pi is a huge amount of compute for a simple beam sensor.

1 Like

AutoHotKey script works like a charm!

; Periodically report PC activity as a dead mans switch

; if PC goes to sleep, we won't be executing so set an expiry on the openhab item to turn off with an item defined like
; Switch myWindowsPC_inuse  "myWindowsPC Activity"          {expire="5m,command=OFF"}

; Hit the dead mans switch a bit more frequently than every 5 minutes (the expiry of the openhab item)
SetTimer, CheckForActivity, 290000


; if someone typed or moved the mouse more recently than the timeout then tell openhab we are still here

inactivityTimeoutMs := 290000
if (A_TimeIdle < inactivityTimeoutMs)


; Ctrl+Alt+1 - debug the ping to openhab

	url := "http://openhab:8080/rest/items/myWindowsPC_inuse"
	whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
	;whr.SetProxy(2, "")	; Fiddler debug

	whr.Open("POST", url, true)	
	whr.SetRequestHeader("Content-Type", "text/plain")

re Pi… its just an example and I thought maybe you have OH already running on a pi. There are other complete break beam sensors available eg using wireless to an alarm unit. You need to google what’s available and see if any fit better with your situation.

1 Like