laser-progs/fan

43 lines
734 B
Bash
Executable File

#!/bin/sh
set -e
TOKEN=...
usage() {
echo "usage: $0 {on|off}" >&2
exit 2
}
api() {
endpoint=$1
shift
curl -s http://iot.waw.hackerspace.pl/api"$endpoint" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
"$@"
}
on() { api /services/fan/turn_on -d '{"entity_id": "fan.exhaust"}'; }
off() { api /services/fan/turn_off -d '{"entity_id": "fan.exhaust"}'; }
query() { api /states/fan.exhaust | jq -r .state; }
api_test() { api /; }
if test $# -eq 0
then
case "$0" in
*-on) on;;
*-off) off;;
*) query;;
esac
elif test $# -eq 1
then
case "$1" in
on|off|query) "$1";;
test) api_test;;
*) usage;;
esac
else
usage
fi