Skip to content
A Home Assistant interface banner overlaid on a workspace photo with monitor and lights, illustrating presence-aware lighting automation.

Turn lights on and off with Windows Hello

Sit down at the desk, Windows Hello unlocks, the monitor backlight comes on. A Task Scheduler trigger calling the Home Assistant REST API, wired through one piece of 1990s VBScript.

4 min read

The simplest lighting trigger in the house is the one I sit down to. Windows Hello unlocks the PC, the monitor backlight comes on. Walk away, the workstation locks, the lights drop. Motion sensors in the room never know about the screen; the screen is the better signal.

The room itself already had a presence-aware setup: Philips Hue, motion sensors, Home Assistant. What was missing was the monitor backlight (a 3m Hue strip behind the CRG90 ultrawide) responding to whether I was actually at the desk, rather than just whether the room had recently seen movement. The result was a backlight that kept turning off while I worked.

The trick

Task Scheduler in Windows fires events when the workstation locks and unlocks. Home Assistant exposes a REST API. The bridge between them is a PowerShell script, called by a Task Scheduler task, fronted by a single line of VBScript that hides the console flash.

The two triggers that do the work: Workstation lock and Workstation unlock.

Six moving parts, no more:

  • Two Task Scheduler tasks (one for lock, one for unlock)
  • One VBScript shim, so the PowerShell console does not flash up
  • Flemming Sørvollen Skaret’s Home Assistant PowerShell module
  • A PowerShell script that calls the Home Assistant REST API
  • A long-lived Home Assistant access token
  • A target entity in Home Assistant (a light, a scene, or an input_boolean)

Task Scheduler

Two tasks: one for Workstation lock, one for Workstation unlock. Each fires the VBScript shim with a parameter that tells the script which Home Assistant service to call.

TIP

If you are doing this on a laptop or tablet, open the task’s Conditions tab and turn off “Start the task only if the computer is on AC power”. Otherwise nothing happens once you unplug the device. Geert van Horrik flagged this one for me.

Untick the AC-power condition on a laptop or the trigger never fires off battery.

The VBScript console flash

PowerShell.exe in Task Scheduler always flashes a console window for a frame or two, even when set to hidden. I lost more time than I want to admit hunting for a clean fix.

The accepted PowerShell issue on the topic is years old and the recommended workaround is the one I used: a small VBScript launcher that invokes PowerShell with vbHide. Not elegant, but the console never appears.

The launcher is the same TaskSchedulerLauncher.vbs pattern. It takes the path to the PowerShell script and the parameters and runs them silently.

PowerShell

The PowerShell script takes the service and the entity ID as parameters (light.turn_on, scene.turn_on, input_boolean.turn_on), constructs the API call, and calls Flemming’s module. The Home Assistant URL and the long-lived token live as variables in the script.

IMPORTANT

The PowerShell script stores a long-lived Home Assistant token. Save it inside your user profile and ACL it to your account only. Treat that token like a password; do not commit the script as-is.

You generate the token in Home Assistant under Profile → Long-Lived Access Tokens at http://localhost:8123/profile. Name it for the workflow so future-you can revoke it without guessing what it is for.

Home Assistant

I started by toggling the monitor light directly, but the real value came from a dedicated input_boolean.james_desk that tracks workstation state. Once that exists, every other automation can ask “is James at his desk?” and behave accordingly.

A few of the consequences:

  • The motion automation does not turn the room lights off while I am working (no more crazy waves at the ceiling).
  • The Dyson fan stops oscillating when I sit down and aims itself at the desk; the speed comes up if the room is over a temperature threshold.
  • Text-to-speech notifications route to the desk Sonos when I am there, and to HTML5 notifications when I am not.
  • Stream Deck buttons can drop me straight into playlists, scenes, and quick actions, all gated on the same boolean.

It also opened the door to TTS reminders for chores and dinner, which deserves its own post.

I 💕 my Home Assistant. The next post in this line is on the smart-home topic page; the lock signal is the foundation a lot of the rest sits on.