-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gethue.sh
executable file
·79 lines (77 loc) · 2.46 KB
/
gethue.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
#
# gethue - Get the Philips Hue hub user name, info, lights, etc
#
# To get started with instructions on retrieving a user id to use, see:
# https://developers.meethue.com/develop/get-started-2/
# and
# https://developers.meethue.com/develop/get-started-2/core-concepts/
#
# Currently, The seven available Hue resources to interact with are:
#
# /lights resource which contains all the light resources
# /groups resource which contains all the groups
# /config resource which contains all the configuration items
# /schedules which contains all the schedules
# /scenes which contains all the scenes
# /sensors which contains all the sensors
# /rules which contains all the rules
#
# Set the IP and User to use (see instructions in URL above to retrieve this info)
IP="xxxxxxxxxx_Hue-Hub-IP_xxxxxxxxxxxxxxxx"
USER="xxxxxxxxxx_Hue-Hub-User_xxxxxxxxxxxxxxxx"
usage() {
printf "\nUsage: gethue [lights|groups|config|schedules|scenes|sensors|rules]"
printf "\nWhere no argument will retrieve all hub info"
printf "\nand one of the following arguments can be given to retrieve info on:"
printf "\n\tlights - all the light resources"
printf "\n\tgroups - all the groups"
printf "\n\tconfig - all the configuration items"
printf "\n\tschedules - all the schedules"
printf "\n\tscenes - all the scenes"
printf "\n\tsensors - all the sensors"
printf "\n\trules - all the rules\n"
exit 1
}
# Check the argument
if [ "$1" ]
then
case "$1" in
lights|groups|config|schedules|scenes|sensors|rules)
usejq=`type -p jq`
if [ "$usejq" ]
then
curl -X "GET" "http://${IP}/api/${USER}/$1" 2> /dev/null | jq .
else
curl -X "GET" "http://${IP}/api/${USER}/$1"
echo ""
fi
;;
*)
usage
;;
esac
else
usejq=`type -p jq`
if [ "$usejq" ]
then
curl -X "GET" "http://${IP}/api/${USER}" 2> /dev/null | jq .
else
curl -X "GET" "http://${IP}/api/${USER}"
echo ""
fi
fi
#
# TODO: convert to getopts arg processing
#while getopts lgcsru flag; do
# case $flag in
# u)
# usage
# ;;
# esac
#done
#
# TODO: provide support for actions on lights/groups/etc
# To turn light id 1 on/off with hue saturation etc:
# curl -X "PUT" "http://${IP}/api/${USER}/lights/1/state" \
# -d {"on":true, "sat":254, "bri":254,"hue":10000}