Sensor to see if a Windows 10 computer is locked

I have a home office with an IP phone powered over PoE via a 48 port Unifi switch. I also have a 3 year old that likes to play telephone. To prevent my 3 year old from making business calls I want HA to turn off the phone when my computer is locked. I know I can turn it off with my Unifi integration but I haven’t found a way to tell if my Windows 10 machine (separate from my HA server) is locked. I did try IoTLink and, while it works well, it doesn’t include a lock sensor. It can tell me what user is signed in, but I’d have to log out of my Windows 10 machine in order to get the state to change. Logging out closes all my apps on the Windows machine, so that’s not an option.

Does anyone know how I can get my Windows 10 desktop lock/unlock state in HA?

UserNotificationState

This sensor watches the UserNotificationState. This is normally used in applications to determine if it is appropriate to send a notification but we can use it to expose this state. Notice that this status does not watch Focus Assist. It has the following possible states:

State Explanation
NotPresent A screen saver is displayed, the machine is locked, or a nonactive Fast User Switching session is in progress.

and

SessionState

This sensor returns the current session state. It has the following possible states:

State Explanation
Locked All user sessions are locked.
LoggedOff No users are logged in.
InUse A user is currently logged in.
Unknown Something went wrong while getting the status.
2 Likes

That works perfectly. Thank you!!

maybe overkill…but had a look at IOT Link - Windows Management using MQTT ?

Yep, I looked at that and it wouldn’t work. It doesn’t sense the lock/unlock status.

This worked perfectly for me as well! Thanks!