#!/bin/bash # Load environment variables from .env file source .env # Query Home Assistant API for battery level battery_level=$(curl -s -X GET "$HA_URL/api/states/$BATTERY_SENSOR_ENTITY" -H "Authorization: Bearer $HA_TOKEN" | jq '.state' | tr -d '"') # Check if battery is sufficiently charged if [ "$battery_level" -ge "$MIN_BATTERY_LEVEL" ]; then echo "Battery level is sufficient: $battery_level%" exit 0 else echo "Battery level is too low: $battery_level%" exit 1 fi