Not every project works out, and I think the ones that donāt are worth writing up too. This is one of those.
In my cabin office thereās a Home Assistant dashboard on the wall, running on a Microsoft Surface Book 2 with the screen detached and used as a tablet. I wanted it to behave like a phone: dark when nobodyās there, and lit up the moment I look at it.
The idea: wake it with my face
Most people would use a motion or presence sensor for this. I went a different way, for three reasons:
- No extra hardware. The Surface already has cameras built in, so why add a sensor?
- Only when Iām looking. A motion sensor wakes the screen every time someone walks past. I only wanted it on when someone was actually at the dashboard.
- It was a fun experiment. I wanted to see if it could be done.
So I wrote a small Python script, with Claude helping me build it, that runs on the tablet itself. Everything is local: no cloud, no network calls.
How it works
Every 0.4 seconds the script grabs a frame from the camera and runs OpenCVās built in face detector (a Haar cascade) over it.
- Face found: the screen comes back to full brightness, and Windows is told not to go idle.
- No face for five minutes: the screen goes dark.
The Surface has an infrared camera (the one Windows Hello uses), which can see in the dark, so I pointed the script at that rather than the normal webcam. The script has a scan mode that saves a snapshot from each camera so you can tell which is which.
Keeping Windows awake is a single call:
import ctypes
ES_CONTINUOUS = 0x80000000
ES_SYSTEM_REQUIRED = 0x00000001
ES_DISPLAY_REQUIRED = 0x00000002
ctypes.windll.kernel32.SetThreadExecutionState(
ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED
)
Where it went wrong
The obvious way to turn the screen off in Windows is to tell the monitor to power down. That works, and then the screen never comes back on.
On the Surface, the camera and the screen appear to share power. Turn the display off and the camera loses power with it, and it doesnāt recover on its own. So the script was now watching for faces through a camera that was switched off. The dashboard would go dark and stay dark until I woke it by hand, which defeated the whole point.
The workaround
Instead of switching the screen off, the script dims it to 0% brightness. The panel stays powered, so the camera stays alive, but the screen looks off.
Get-CimInstance -Namespace root/WMI -ClassName WmiMonitorBrightnessMethods | Invoke-CimMethod -MethodName WmiSetBrightness -Arguments @{ Timeout = 1; Brightness = 0 }
I also had to make the script a lot more defensive. Reading a frame from a camera in OpenCV has no timeout, so if the driver stalls, that call can hang forever. The camera now runs in its own child process, and the main script watches it. If it stops reporting, or keeps returning the same frozen frame, it gets killed and restarted.
Why itās still rubbish
Technically, it works. In practice, I donāt like using it:
- Itās slow to wake. I walk up, and Iām standing there waiting for it. A dashboard you have to wait for isnāt much use. One reason is that every brightness change starts a PowerShell process to make the WMI call, which takes a moment on its own.
- It misses faces. The face detector is fast but simple. If Iām at an angle, or the light isnāt right, it doesnāt see me.
- Itās not really off. At 0% brightness the screen is still lit, just very dimly. Itās not the same as a screen thatās actually off.
What I learned
- Check what shares power with what. Turning the display off also killing the camera was the one detail that sank the whole design.
- Clever isnāt the same as good. Face detection was a fun way to solve the problem, but a dashboard needs to be instant, and this never was.
- Dependencies change under you. Newer versions of the opencv-python package stopped including the face detection model files, so I now ship that file alongside the script.
Whatās next
Iām going to swap the Surface for an Android tablet. On Android, kiosk apps can turn the screen on and off properly, and Home Assistant can control that directly. That means I can wake it from a presence sensor or an automation, rather than trying to do everything on the tablet.
When thatās up and running, Iāll write it up too. If youāve built a wall dashboard that wakes well, Iād love to hear how you did it: get in touch.
If you want to know more about the office itself, Iāve written about how I made the cabin smart with Zigbee2MQTT.
What to read next
3 pages
This is part of my smart home: see how it all fits together. Got a question about this, or built something similar? Get in touch. New write-ups go out on the RSS feed and LinkedIn, everything I've built is on the projects page, and my free calculators and guides are on the tools page.