Turning on my office lights when I unlock my computer
I love messing with smart home tech and in my home office, I've had my lights connected to my Home Assistant setup for years. When I walk in, I either hit the light switch which triggers the overhead lights and a few other lights to toggle or I ask Alexa to turn on my office lights. But I wanted more. Beyond putting in a motion sensor, I wanted to just sit down and unlock my computer and have my office come to life.
Enter Task Scheduler and Home Assistant Automations.
Home Assistant
To start, I created a simple automation to turn on all lights in my Office area:
alias: Turn on Office Lights
description: "Turn on all the lights in the office when a webhook is triggered"
triggers:
- trigger: webhook
allowed_methods:
- POST
- PUT
local_only: true
webhook_id: turn-on-office-lights
conditions: []
actions:
- action: light.turn_on
metadata: {}
data: {}
target:
area_id: office
mode: single
Task Scheduler
With the automation created, I next created a new task in Task Scheduler named "Turn on Office Lights"
Then I added a new Trigger to the task to begin the task "On workstation unlock"
Finally, I added an Action to execute a line of Powershell code:
The arguments being password to the powershell command are:
-NoProfile -WindowStyle Hidden -NonInteractive -NoLogo -Command "Invoke-RestMethod -Uri 'https://my-home-assistant-url/api/webhook/turn-on-office-lights' -Method POST"
That's it. Now whenever I unlock my computer, my office lights will turn on automatically for me. You can also follow a similar process creating an automation to turn off the lights using the "On Workstation Lock" trigger in Task Scheduler.