Sensor for computer usage?

I just followed these steps provided by @ZzetT.

and

1 Like

I used this until 2 days ago when I suddenly started getting these responses:

SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)

Anyone have any clues as to why this suddenly started happening?

Given the timing that might be related to the Lets Encrypt thingy (donā€™t know the proper term) expiring DST Root CA X3 Expiration (September 2021) - Let's Encrypt

1 Like

Yeah that seems to be itā€¦

The xprintidle solution from martokk is awesome, simple and very versatileā€¦ except for a tiny issue: getting SSH to run properly from the command_line integration seems to be a nightmare (sample complaint post from 2020).

  • You obviously canā€™t pass a password via argument to ssh
  • no clue if itā€™s ever possible to install sshpass in HA Core
  • SSH keys seem to be wiped with Core updates (reply at the same post)
    • I mean, if you ever figure out how to add a working SSH key; the SSH add-on donā€™t run at the same container which the integration will execute (reply at the same post, integration docs ā€œhintā€), so testing from the add-on and seeing it working fine makes you feel like a :clown_face:

Other solutions Iā€™m leaning towards:

  • edit [THIS ONE WORKED!!!] installing some sort of HTTP server on my computer and make it spit out xprintidle whenever a given page is requestedā€¦ so somehow HA can pick that up through, idk, curl? Nonetheless, thatā€™s a lot of work which could be simply done via SSH lol
    1. I indeed installed Apache in my computer
    2. I added a cronjob to store xprintidle output in Apacheā€™s folder: crontab -e; then add */1 * * * * DISPLAY=:0 xprintidle 2>&1 > /var/www/html/xprintidle.txt
    3. I added a command_line integration to HA which runs curl my-desktop-ip/xprintidle.txt :pray: Dirtiest solution possible, butā€¦ thatā€™s what we have to put up with sometimes around Home Assistant ā€œuser-friendlyā€ configurations? lol
  • some indirect trick with System Bridge
  • hope for something like HASS.Agent but for Linux lol

To all my fellow Linux users ending up on this thread, I published a Python package to PyPI that allows you to report idleness to Home Assistant thanks to the HTTP integration.

I donā€™t like xprintidle for a very simple reason, I donā€™t want Home Assistant to think Iā€™m idle while Iā€™m watching videos (and therefore not using mouse or keyboard). My script is based on xidlehook which listens to PulseAudio events to make sure youā€™re not considered idle if your computer outputs audio.

Check it out : GitHub - ShellCode33/HASS-Desktop-Sensor: Desktop activity sensor for Home Assistant

Other user of IOT Link here. Very simple integration, I used the idle_time sensor to turn off my external audio amplifier after 10 min of inactivity. The automation would be better with a mmWave presence sensor like the Aquara FP1, but Iā€™ve been spending too much on Home Assistant toys lately :slight_smile:

Automation:

alias: SMSL off when PC idle 
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.my_computer_idle_time
    above: 600
action:
  - service: remote.send_command
    data:
      device: smsl_ad18
      command: power
    target:
      entity_id: remote.rm4c_mini_remote
mode: single

configuration.yaml:

mqtt:
  sensor:
    - name: "My Computer - Idle Time"
      state_topic: "iotlink/workgroup/silent-desktop/windows-monitor/stats/system/idle-time"
      unit_of_measurement: "seconds"
      icon: mdi:timer
      value_template: "{{ value }}"
      availability_topic: "iotlink/workgroup/silent-desktop/lwt"
      payload_available: "ON"
      payload_not_available: "OFF"
      qos: 1
1 Like