Skip to content

Instantly share code, notes, and snippets.

@nov-
Forked from kuglee/DiskSpaceLightbulb.sh
Created March 26, 2021 14:35
Show Gist options
  • Save nov-/29211179721c4c40b6b73671c69ee997 to your computer and use it in GitHub Desktop.
Save nov-/29211179721c4c40b6b73671c69ee997 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