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"