added fan, light, and switch scripts for homeassistant

This commit is contained in:
lucca
2026-06-29 14:54:33 -04:00
parent df374337b6
commit f346c5cdf1
2 changed files with 64 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
#!/bin/bash
source ~/sh/ha/.env
entity="fan.$1"
case "$2" in
on)
curl -X POST \
-H "Authorization: Bearer $HA_APIKEY" \
-H "Content-Type: application/json" \
-d "{\"entity_id\":\"$entity\"}" \
"$HA_URL/api/services/fan/turn_on"
;;
off)
curl -X POST \
-H "Authorization: Bearer $HA_APIKEY" \
-H "Content-Type: application/json" \
-d "{\"entity_id\":\"$entity\"}" \
"$HA_URL/api/services/fan/turn_off"
;;
1) pct=17 ;;
2) pct=33 ;;
3) pct=50 ;;
4) pct=67 ;;
5) pct=83 ;;
6) pct=100 ;;
*)
echo "Usage: $0 <fan_name> {on|off|1-6}"
exit 1
;;
esac
if [[ -n "$pct" ]]; then
curl -X POST \
-H "Authorization: Bearer $HA_APIKEY" \
-H "Content-Type: application/json" \
-d "{\"entity_id\":\"$entity\",\"percentage\":$pct}" \
"$HA_URL/api/services/fan/set_percentage"
fi