27 lines
614 B
Bash
27 lines
614 B
Bash
#!/bin/bash
|
|
# Home Assistant API helper script
|
|
# Usage: ./ha-api.sh <endpoint> [method] [body]
|
|
|
|
HA_URL="${HA_URL:-http://localhost:8123}"
|
|
HA_TOKEN="${HA_TOKEN:-}"
|
|
|
|
if [ -z "$HA_TOKEN" ]; then
|
|
echo "Error: HA_TOKEN not set. Export HA_TOKEN first."
|
|
exit 1
|
|
fi
|
|
|
|
ENDPOINT="$1"
|
|
METHOD="${2:-GET}"
|
|
BODY="${3:-}"
|
|
|
|
if [ -n "$BODY" ]; then
|
|
curl -s -X "$METHOD" \
|
|
-H "Authorization: Bearer $HA_TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
-d "$BODY" \
|
|
"$HA_URL$ENDPOINT"
|
|
else
|
|
curl -s -X "$METHOD" \
|
|
-H "Authorization: Bearer $HA_TOKEN" \
|
|
"$HA_URL$ENDPOINT"
|
|
fi |