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-WmiObject -Namespace root/WMI -Class WmiMonitorBrightnessMethods).WmiSetBrightness(1, 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.
Related reading
total 1
More projects
total 14