|
- #!/usr/bin/env bash
-
- # homeassistant_access_token=""
- homeassistant_url="http://homeassistant.natrinicle.com:8123/api/states"
- homeassistant_screensaver_binary_sensor="${homeassistant_url}/binary_sensor.$(hostname | tr -s '-' '_' | tr '[:upper:]' '[:lower:]')_screen_locked"
-
- ps -e -o stat,command,pid | grep '^T' | grep -P "(firefox|atom)" | awk '{print $NF}' | xargs -P0 -I {} kill -CONT {}
-
- # Update Homeassistant
- if [ -n "${homeassistant_access_token}" ] && [ -n "${homeassistant_screensaver_binary_sensor}" ]; then
- curl -X POST -H "Authorization: Bearer ${homeassistant_access_token}" -H "Content-Type: application/json" -d "{\"state\": \"off\", \"attributes\": {\"friendly_name\": \"$(hostname) Screensaver\"}}" "${homeassistant_screensaver_binary_sensor}"
- fi
|