Desktop activity sensor for Home Assistant
Project description
HASS Desktop Sensor
Desktop activity sensor for Home Assistant
Features
- Tracks idleness thanks to xidlehook
- Reports system resources usage
By default you'll be considered idle if you don't use the mouse and keyboard for 5 minutes. Note that if you're playing some audio, you won't be considered idle. This is to prevent false positives while watching videos.
The Desktop Sensor will report status to Home Assistant every 5 seconds by default.
Requirements
- Install xidlehook
- Enable the API integration of Home Assistant (just add
api:
to yourconfiguration.yaml
). - Create a long-lived access token (go to your profile in Home Assistant, scroll to the bottom, and click "Create Token")
Installation
As simple as :
$ pip install --user hass-desktop-sensor
To make sure it's working, try to run the script manually like so :
$ HASS_ACCESS_TOKEN=[YOUR ACCESS TOKEN HERE] hass_desktop_sensor --hass-url 'http://homeassistant.local:8123' --hass-device-name 'My Laptop'
To test your automations, you can pass --idle-delay 1
and --report-interval 1
to the command line.
You will be considered idle after 1 second, and your idleness status will be reported every second.
This is useful for debug purposes but I don't recommend doing that in real world scenarios.
Note: You can increase log verbosity by setting LOGLEVEL=DEBUG
at the beginning of your command line.
Automatic startup
Chances are you are using systemd, if you're not, you're on your own. But I'm pretty sure if you're not using systemd you'll figure out by yourself how to automatically start this script :)
So... For systemd users, create ~/.config/systemd/user/hass-desktop-sensor.service
with the following content :
[Unit]
Description=Home Assistant Desktop Sensor
After=network-online.target pulseaudio.service
[Service]
Type=simple
Environment=DISPLAY=:0
Environment=HASS_ACCESS_TOKEN=[YOUR ACCESS TOKEN HERE]
ExecStart=%h/.local/bin/hass_desktop_sensor --hass-url 'http://homeassistant.local:8123' --hass-device-name 'My Laptop'
[Install]
WantedBy=default.target
Then run systemctl --user start hass-desktop-sensor
to make sure the service starts properly.
If it does, enable the service using systemctl --user enable hass-desktop-sensor
.
Improved resilience
If for whatever reason the desktop sensor is not able to report idleness (power failure, network issues, etc.) some of your automations might not trigger. This is why additionnaly to this desktop sensor, I suggest you setup the ping integration of Home Assistant to turn off what is usually turned on by your automations based on the Desktop Sensor.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file hass-desktop-sensor-1.0.1.tar.gz
.
File metadata
- Download URL: hass-desktop-sensor-1.0.1.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1652daf72341cd803e45bd5d89542b1c04b0780b8ef5d1d5cebc8f02c6763ecc |
|
MD5 | 5e3f845eb9e1eea77beceb758c50dc2e |
|
BLAKE2b-256 | af7c67fea617409c9bf6b570b3e61ad4be2bf861af9837d86d18006c7311b937 |