LastActive Sensor Inconsistent
I am trying to use the lastactive sensor in order to turn off my busy light when away from my PC.
I have found this works, but only sometimes. It is very inconsistent and I am making no changes to config between when it works and doesn't.
I assume there is something on my PC that may run on occasion, making the system think it is active.
How does the last active sensor actually calculate this? I am trying to figure out how to troubleshoot this and whether the issue is my system, or if there is a bug.
Solution:Jump to solution
@Subjunctive @Amadeo you may find this of interest.
I wrote some, definitely not ChatGPT authored code... And I managed to figure out what was causing it. Essentially using the RawInput API and then logging the Vendor and Product IDs. I then used USBTreeView to check which device had that ID.
Its a custom control board for my sim pedals spamming like crazy....
30 Replies
Help us Help Others!
To help others find answers, you can mark your question as solved via
Right click solution message -> Apps -> ✅ Mark Solution
Help us Help You!
Please don't delete messages or posts because it makes it impossible to understand what happened. If you don't want your messages to be seen then don't post here.
Please provide us with the version number of your app.
You can find it by clicking the ? at the bottom of the main page and checking under the logo that shows.We will help as soon as possible. While you're waiting you can try the following:
- Checkout the documentation. - Search here in discord for previously solved similar issues.
@Amadeo
genetic-orangeOP•3w ago
v2.1.0 of the HASS Agent
is your machine possibly going to sleep before the sensor updates? the LastActive sensor is using https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getlastinputinfo
GetLastInputInfo function (winuser.h) - Win32 apps
Retrieves the time of the last input event.
but there is some code related to sleep and wake that I haven't quite figured out. it might be that if your machine goes to sleep and then wakes up over and over, the sensor calculation gets confused
As far as I remember the last active sensor is the last mouse/kayboard input
genetic-orangeOP•3w ago
@Amadeo @Subjunctive
So I do not have sleep or display sleeping enabled on my machine. I do have a few peripherals, but I am confident that none of them are being interacted with when I am testing this, which is why I assumed it was software related.
Is there any testing I can do to break this down and pinpoint the issue?
the tricky part is that any other software can inject kb/mouse events
genetic-orangeOP•3w ago
Is there a way to report the Device ID of the last device to do so?
or Hardware ID
only timestamp unfortunately
I assume you step away from pc but the sensors is still updated with new values correct?
genetic-orangeOP•3w ago
Correct, I step away and the sensor updates every 10 seconds with the current date and time, despite no mouse input. There are some exceptions, but I havent been able to pin point why it stops updating some times and keeps updating other times.
Perhaps there is a tool to monitor HID inputs?
Perhaps not as I suppose what I may be looking for would essentially be a keylogger...?
stupid question
but you don't have any mouse mover of caffeine stuff installed :D?
genetic-orangeOP•3w ago
No lol - I love sneaking off from work as much as the next person, but don't use that kind of stuff lol
it's not necessarily even HID input, I think anything can send a key event through the Windows event loop and cause this to get updated, including "null" key events
do you use AutoHotKey or similar for anything?
genetic-orangeOP•3w ago
I do not, the closest equivalent is a Stream deck.
hmm, the Stream Deck uses HID messages to communicate with the controller software, I think, or maybe only the other way around
genetic-orangeOP•3w ago
So the Stream Deck software is running, and as I said it is inconsistent.
For example, the lastactive sensor is updating when I am idle, but if I bring USB Device Tree Viewer up and leave the window in focus, the last active sensor stops updating when idle.
This is not the only time the lastactive sensor begins working as expected, but one such example.
This might be silly but have you tried only with the mouse or only with the keyboard? I.e unplug one & test, then test with the other. I'm wondering if the mouse or keyboard somehow send events. At one point I had a mouse that kinda jittered at times and woke up my monitors from sleep randomly
genetic-orangeOP•3w ago
hmm I could certainly try that. I can't say that I have noticed any issues with them, but can't hurt to rule it out.
this is messed up
like the USB Device Tree Viewer thing affecting it
I think you need a young priest and an old priest, your computer is possessed
genetic-orangeOP•2w ago
haha agreed. Perhaps I just have to accept I can't rely on the lastactive sensor and find an alternate way to do presence detection for my use case.
I am essentially using it to determine whether I am at my desk or racing sim rig, and if not to make a light turn off. It turns green if I am there but not busy, and red if my webcam or microphone is in use.
I have mine set to auto-lock after a while idle, and use the session state, FWIW
but if you have a racing sim rig, you should really have ESP32 sensors in your chairs to tell if you're sitting
or mm-wave presence detectors
let's not have half measures
genetic-orangeOP•2w ago
Yeah I am using session states lock for that same thing. How are you auto-locking, I can't remember if there is a Windows native way.
All for ESP32s, perhaps mm Wave is best, as my Herman Miller at my desk doesnt have a great way to integrate a weight sensor or similar
IIRC there was a way of doing it with Screensaver?
yeah Windows has an autolock timer you can set. I forget where they moved it to in Windows 11, probably Disk Management or something
I hope you have your racing sim reporting your current virtual speed and race position and lap count to HA
genetic-orangeOP•2w ago
haha that would require learning the iRacing SDK and making a client app. I am tracking when the process is open though to set my busy light to red
Solution
genetic-orange•2w ago
@Subjunctive @Amadeo you may find this of interest.
I wrote some, definitely not ChatGPT authored code... And I managed to figure out what was causing it. Essentially using the RawInput API and then logging the Vendor and Product IDs. I then used USBTreeView to check which device had that ID.
Its a custom control board for my sim pedals spamming like crazy.
Happy to share the code if you are interested, written in C++
genetic-orangeOP•2w ago
great debugging work, that’s awesome
genetic-orangeOP•2w ago
lastactive now meets my needs perfect, with session state as a backup. Thanks for the help!