Files
linux-scripts/switchcontrol
2023-08-02 01:11:58 -05:00

28 lines
603 B
Bash
Executable File

#!/bin/bash
# A program that maps the paramaters [1 -> length - 1] to a variable P[1 -> length - 1] and then sends it in a HTTP post requset to HomeAssistant web hook automation.
WEBHOOK_ID="3Rvdb4qZDgcKD2EiZgV328xdhWLVkjn8dVgSKr13JkIb5eP0RFNPQjgYDey16R64"
WEBHOOK_URL="http://0.hassio.local/api/webhook/$WEBHOOK_ID"
CURL_REQ="curl -X POST $WEBHOOK_URL"
#CURL_REQ=("curl" "-X" "POST" "$WEBHOOK_URL")
declare -a params_array
i=0
j=0
for var in "$@"
do
params_array[$i]='-d'
((i++))
params_array[$((i))]="P$((i-1+j))=$var"
((i++))
((j-=1))
done
$CURL_REQ "${params_array[@]}"