Skip to content

Instantly share code, notes, and snippets.

@kuglee
Created February 16, 2019 11:33
Show Gist options
  • Save kuglee/d1b3c036cf5c525e40ed6f0f4123d944 to your computer and use it in GitHub Desktop.
Save kuglee/d1b3c036cf5c525e40ed6f0f4123d944 to your computer and use it in GitHub Desktop.
Homebridge disk space as Humidity Sensor with homebridge-cmd4 plugin
#!/usr/bin/env bash
# Plugin: https://github.com/ztalbot2000/homebridge-cmd4
#
# config.json
#
# ...
# {
# "platform": "Cmd4",
# "name": "Cmd4",
# "accessories":
# [
# {
# "type": "HumiditySensor",
# "name": "Disk Space",
# "currentRelativeHumidity": 1,
# "statusActive": 1,
# "statusFault": 0,
# "statusTampered": 0,
# "statusLowBattery": 0,
# "stateChangeResponseTime": 0,
# "state_cmd": "bash .homebridge/Cmd4Scripts/DiskSpaceHumiditySensor.sh"
# }
# ]
# }
# ...
if [ "$1" = "Get" ]; then
case $3 in
"StatusFault" | "StatusTampered" | "StatusLowBattery")
echo 0
exit 0
;;
"StatusActive")
echo 1
exit 0
;;
"CurrentRelativeHumidity")
diskSpace=$(df -Bm | sed '2q;d' | sed 's/.*\([0-9][0-9]\%\).*/\1/' | sed s/\%//)
echo "$diskSpace"
exit 0
;;
esac
fi
exit -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment