Skip to content

Instantly share code, notes, and snippets.

@kuglee
Created February 16, 2019 11:33
Show Gist options
  • Save kuglee/20f514830762439b74bbea8c36948f82 to your computer and use it in GitHub Desktop.
Save kuglee/20f514830762439b74bbea8c36948f82 to your computer and use it in GitHub Desktop.
Homebridge disk space as Lightbulb with homebridge-cmd4 plugin
#!/usr/bin/env bash
# Plugin: https://github.com/ztalbot2000/homebridge-cmd4
#
# config.json
#
# ...
# {
# "platform": "Cmd4",
# "name": "Cmd4",
# "accessories":
# [
# {
# "type": "Lightbulb",
# "name": "Disk Space",
# "brightness":100,
# "polling": true,
# "interval": 5,
# "stateChangeResponseTime": 0,
# "state_cmd": "bash .homebridge/Cmd4Scripts/DiskSpaceLightbulb.sh"
# }
# ]
# }
# ...
if [ "$1" = "Get" ]; then
if [ "$3" == "On" ]; then
echo 1
exit 0
elif [ "$3" == "Brightness" ]; then
diskSpace=$(df -Bm | sed '2q;d' | sed 's/.*\([0-9][0-9]\%\).*/\1/' | sed s/\%//)
echo "$diskSpace"
exit 0
fi
fi
if [ "$1" = "Set" ]; then
echo 1
exit 0
fi
exit -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment