Allow Sharptools/Smartthings to know when I'm logged into my computer

I’m trying to come up with an automation that turns off a smart switch at my desk that has my monitor and a bunch of other little things plugged into it when I’m not around. My PC is bypassed so it always remains charged but everything else will turn off.

I have an automation on my iPad through Shortcuts that will ping a webhook when the battery level dips below 20% to trigger it to turn the switch back on so it can charge and turn back off when it hits 90%. I can manually trigger things to turn off with a button or something but the ideal trigger would be if I’m not logged into my PC so I was thinking of setting up a virtual device and controlling it with a webhook. I can create a little script in Windows Task Automator for “When I log on” to ping a webhook and turn on the virtual switch but I can’t figure out a way to trigger it off when I log off. Any ideas? I’ve looked at Power Automate and Task Scheduler but can’t seem to find anything. Appreciate any ideas.


Have you tried the Logoff scripts from gpedit.msc? (I haven’t personally tried it, but found it from a quick search)

It looks like you might also be able to do it in Task Scheduler by using a specific ‘Security’ Event ID 4647 which appears to be the ‘User Initiated Logoff’ event.

I’ll leave it open to the community in case anyone else has done this in the past? I personally don’t ever logoff my PC and instead just lock it. :smiley:

You’re a genius - I guess I was searching for the wrong thing I didn’t find any of that at first but thank you! And yes, I meant lock or unlock, not log on or off :slight_smile:

For anyone interested, I was able to achieve this with Windows Task Scheduler
-Create Task
-Triggers: Begin the Task: On Workstation Unlock (and another for unlock that’s the same)
-Actions: Start a Program > powershell (with argument of the file path)
-Then I just have a couple of powershell programs that run (one for lock and one for unlock

“Invoke-WebRequest -Uri -Method Post”

In Sharptools, when that webhook is received with parameter either “on” or “off”, it turns on or off a virtual switch in Smartthings. Now I can trigger any number of automations when I log in our out of my PC.

Thanks again!

1 Like