From f346c5cdf1238a3bc14505a9b42075fd4af285a8 Mon Sep 17 00:00:00 2001 From: lucca Date: Mon, 29 Jun 2026 14:54:33 -0400 Subject: [PATCH] added fan, light, and switch scripts for homeassistant --- homeassistant/fan.sh | 40 ++++++++++++++++++++++++++++++++++++++++ homeassistant/switch.sh | 24 ++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100755 homeassistant/fan.sh create mode 100755 homeassistant/switch.sh diff --git a/homeassistant/fan.sh b/homeassistant/fan.sh new file mode 100755 index 0000000..375e79f --- /dev/null +++ b/homeassistant/fan.sh @@ -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 {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 diff --git a/homeassistant/switch.sh b/homeassistant/switch.sh new file mode 100755 index 0000000..2c426f3 --- /dev/null +++ b/homeassistant/switch.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +source ~/sh/ha/.env + +entity="switch.$1" + +case "$2" in + on) + service="turn_on" + ;; + off) + service="turn_off" + ;; + *) + echo "Usage: $0 {on|off}" + exit 1 + ;; +esac + +curl -X POST \ + -H "Authorization: Bearer $HA_APIKEY" \ + -H "Content-Type: application/json" \ + -d "{\"entity_id\":\"$entity\"}" \ + "$HA_URL/api/services/switch/$service"