#!/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