I have a script to control my airconditioner:
#!/usr/bin/env bash
#Airconwithme script (airconwithme.com)
#Written by KingOfDois. BSD 3-clause license.
USAGE="usage: ${0} ip set|get option [value]"
#pseudo: login credentials.
#security note: wget leaks user/password in process list
if [ -z "${AIRCO_PASSWORD}" ]; then
AIRCO_PASSWORD=operator
fi
if [ -z "${AIRCO_USER}" ]; then
AIRCO_USER=operator
fi
#pseudo: 1st argument is IP
if [ -z "${1}" ]; then
echo ${USAGE}
exit 1
else
AIRCO_IP="${1}"
fi
#pseudo: 2nd argument is set|get
if [ "${2}" != "set" ] && [ "${2}" != "get" ]; then
echo ${USAGE}
exit 1
fi
DIRECTION=${2}
#pseudo: more variables
ACTION=${3}
DO=${4}
VALUE=0
EXIT=0
#-------------------------------------
#pseudo: functions
function stderr () {
cat - 1>&2
}
#-------------------------------------
#pseudo: action table
ACTIONS=(power mode speed vane setpoint return alarm)
UIDS=(1 2 4 5 9 10 14)
#pseudo: select uid from action
FOUND=0
for i in "${!ACTIONS[@]}"
do
if [ "${ACTIONS[${i}]}" == "${ACTION}" ]; then
FOUND=1
WORK_UID=${UIDS[${i}]}
fi
done
if [ ${FOUND} -eq 0 ]; then
echo "available actions: ${ACTIONS[@]}"
exit 1
fi
#-------------------------------------
#pseudo: work the $ACTION / $VALUE with $uid available
if [[ "${DIRECTION}" == "set" ]]; then
if [[ "${ACTION}" == "power" ]]; then OPTIONS=(on off); VALUES=(1 0); fi
if [[ "${ACTION}" == "mode" ]]; then OPTIONS=(auto heat dry fan cool); VALUES=(0 1 2 3 4); fi
if [[ "${ACTION}" == "speed" ]]; then OPTIONS=(1 2 3 4); VALUES=(1 2 3 4); fi
if [[ "${ACTION}" == "vane" ]]; then OPTIONS=(1 2 3 4 swing); VALUES=(1 2 3 4 10); fi
if [[ "${ACTION}" == "setpoint" ]]; then
if [ "${DO}" == "" ]; then
echo "value: 180 till 300 (18.0 till 30.0 degree C)"
exit 1
else
VALUE=$DO;
fi
fi
fi
#pseudo: now select the proper value based on the action
if [ "${OPTIONS}" != "" ]; then
FOUND=0
for i in "${!OPTIONS[@]}"
do
if [ "${OPTIONS[${i}]}" == "${DO}" ]; then
FOUND=1
VALUE=${VALUES[${i}]}
fi
done
if [ ${FOUND} -eq 0 ]; then
echo "available [${ACTION}] options: ${OPTIONS[@]}"
exit 1
fi
fi
#-------------------------------------
COOKIE=$(mktemp)
#pseudo: login
LOGIN_RESPONSE=$(mktemp)
LOGIN_ERROR=$(mktemp)
wget --save-cookies=${COOKIE} \
--keep-session-cookies \
--post-data="{\"command\":\"login\",\"data\":{\"username\":\"${AIRCO_USER}\",\"password\":\"${AIRCO_PASSWORD}\"}}" \
--output-document=${LOGIN_RESPONSE} \
--header="Content-Type: application/json" \
--header="Accept: application/json" \
--tries=3 \
--timeout=30 \
http://${AIRCO_IP}/api.cgi 2> ${LOGIN_ERROR}
LOGIN_RC=$?
if [ "${LOGIN_RC}" -ne 0 ]; then
cat ${LOGIN_ERROR}|stderr
EXIT=1
fi
if [ "$(grep -c '"success":true' ${LOGIN_RESPONSE})" -ne 1 ]; then
echo "something went wrong while logging in"|stderr
echo "response: $(cat ${LOGIN_RESPONSE})"|stderr
EXIT=1
fi
#pseudo: get sessionID from login
SESSION_ID=$(awk -F '"sessionID":"' '{print $2}' ${LOGIN_RESPONSE}|awk -F '"' '{print $1}')
#---------------------------------
if [ "${SESSION_ID}" != "" ]; then
ACTION_RESPONSE=$(mktemp)
ACTION_ERROR=$(mktemp)
if [ "${DIRECTION}" == "set" ]; then
POST_DATA="{\"command\":\"setdatapointvalue\",\"data\":{\"sessionID\":\"${SESSION_ID}\",\"uid\":${WORK_UID},\"value\":${VALUE}}}"
else
POST_DATA="{\"command\":\"getdatapointvalue\",\"data\":{\"sessionID\":\"${SESSION_ID}\",\"uid\":${WORK_UID}}}"
fi
wget --load-cookies=${COOKIE} \
--post-data="${POST_DATA}" \
--output-document=${ACTION_RESPONSE} \
--header="Content-Type: application/json" \
--header="Accept: application/json" \
--tries=3 \
--timeout=30 \
http://${AIRCO_IP}/api.cgi 2> ${ACTION_ERROR}
ACTION_RC=$?
if [ "${ACTION_RC}" -ne 0 ]; then
cat ${ACTION_ERROR}|stderr
EXIT=1
fi
if [ "$(grep -c '"success":true' ${ACTION_RESPONSE})" -eq 1 ]; then
if [ "${DIRECTION}" == "set" ]; then
echo "saved";
else
RESPONSE_VALUE=$(awk -F ',"value":' '{print $2}' ${ACTION_RESPONSE}|awk -F ',"status"' '{print $1}')
#sed 's/\"//g'
echo "${RESPONSE_VALUE}"
fi
else
echo "${DIRECTION} failed"|stderr
echo "response: $(cat ${ACTION_RESPONSE})"|stderr
EXIT=1
fi
#end if SESSION_ID
fi
#---------------------------------------------
#cleanup
if [ -f "${COOKIE}" ]; then rm ${COOKIE}; fi
if [ -f "${LOGIN_RESPONSE}" ]; then rm ${LOGIN_RESPONSE}; fi
if [ -f "${LOGIN_ERROR}" ]; then rm ${LOGIN_ERROR}; fi
if [ -f "${ACTION_RESPONSE}" ]; then rm ${ACTION_RESPONSE}; fi
if [ -f "${ACTION_ERROR}" ]; then rm ${ACTION_ERROR}; fi
exit ${EXIT}
My shell command is:
airco_aan: 'bash /config/scripts/airco.sh IPADDRESS set power on'
script:
airco_aan:
alias: Airco aan
sequence:
- service: shell_command.airco_aan
When i use it in my docker setup it works fine, but when i use it in HASSIO i get the error:
Error running command: `bash /config/scripts/airco.sh 10.73.31.68 set power on`, return code: 1
NoneType: None
When i start my script in telnet in hassio i get the error:
core-ssh:/config/scripts# ./airco.sh 10.73.31.68 set power off
wget: unrecognized option: save-cookies=/tmp/tmp.BPdDfl
BusyBox v1.29.3 (2019-01-24 07:45:07 UTC) multi-call binary.
Usage: wget [-c|--continue] [--spider] [-q|--quiet] [-O|--output-document FILE]
[--header 'header: value'] [-Y|--proxy on/off] [-P DIR]
[-S|--server-response] [-U|--user-agent AGENT] [-T SEC] URL...
Retrieve files via HTTP or FTP
--spider Only check URL existence: $? is 0 if exists
-c Continue retrieval of aborted transfer
-q Quiet
-P DIR Save to DIR (default .)
-S Show server response
-T SEC Network read timeout is SEC seconds
-O FILE Save to FILE ('-' for stdout)
-U STR Use STR for User-Agent header
-Y on/off Use proxy
something went wrong while logging in
response:
How can i fix this problem?