Airconwithme custom component

Hello,

I use a wifi module for my airconditioning in my living room. From airconwithme.com
There are some smart people who has written a script to control the aircon.

Can somebody help me to create a component or to get it working in a climate component?

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

Or in Powershell:

$ipAddress = "192.168.3.217"

#Login
$response = Invoke-Restmethod -Uri "http://$ipAddress/api.cgi" -Method "POST" -Headers @{"Cookie"="Intesis-Webserver={%22sessionID%22:null}"; "Origin"="http://$ipAddress"; "Accept-Encoding"="gzip, deflate"; "Accept-Language"="en-US,en;q=0.9,nl;q=0.8"; "User-Agent"="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36"; "Accept"="application/json, text/javascript, */*; q=0.01"; "Referer"="http://$ipAddress/"; "X-Requested-With"="XMLHttpRequest"; "DNT"="1"} -ContentType "application/json; charset=UTF-8" -Body "{`"command`":`"login`",`"data`":{`"username`":`"admin`",`"password`":`"admin`"}}";
$sessionId = $response.data.id.sessionID

# Set mode to Heat
Invoke-Restmethod -Uri "http://$ipAddress/api.cgi" -Method "POST" -Headers @{"Cookie"="Intesis-Webserver={%22sessionID%22:%22$sessionId%22}"; "Origin"="http://$ipAddress"; "Accept-Encoding"="gzip, deflate"; "Accept"="application/json, text/javascript, */*; q=0.01"; "Referer"="http://$ipAddress/"; "X-Requested-With"="XMLHttpRequest"; "DNT"="1"} -ContentType "application/json; charset=UTF-8" -Body "{`"command`":`"setdatapointvalue`",`"data`":{`"sessionID`":`"$sessionId`",`"uid`":2,`"value`":1}}"
# Set fan speed to speed 3
Invoke-WebRequest -Uri "http://$ipAddress/api.cgi" -Method "POST" -Headers @{"Cookie"="Intesis-Webserver={%22sessionID%22:%22$sessionId%22}"; "Origin"="http://$ipAddress"; "Accept-Encoding"="gzip, deflate"; "Accept"="application/json, text/javascript, */*; q=0.01"; "Referer"="http://$ipAddress/"; "X-Requested-With"="XMLHttpRequest"; "DNT"="1"} -ContentType "application/json; charset=UTF-8" -Body "{`"command`":`"setdatapointvalue`",`"data`":{`"sessionID`":`"$sessionId`",`"uid`":4,`"value`":3}}"
# Set temperature to 23C
Invoke-WebRequest -Uri "http://$ipAddress/api.cgi" -Method "POST" -Headers @{"Cookie"="Intesis-Webserver={%22sessionID%22:%22$sessionId%22}"; "Origin"="http://$ipAddress"; "Accept-Encoding"="gzip, deflate"; "Accept"="application/json, text/javascript, */*; q=0.01"; "Referer"="http://$ipAddress/"; "X-Requested-With"="XMLHttpRequest"; "DNT"="1"} -ContentType "application/json; charset=UTF-8" -Body "{`"command`":`"setdatapointvalue`",`"data`":{`"sessionID`":`"$sessionId`",`"uid`":9,`"value`":230}}"
# Set position to Swing
Invoke-WebRequest -Uri "http://$ipAddress/api.cgi" -Method "POST" -Headers @{"Cookie"="Intesis-Webserver={%22sessionID%22:%22$sessionId%22}"; "Origin"="http://$ipAddress"; "Accept-Encoding"="gzip, deflate"; "Accept"="application/json, text/javascript, */*; q=0.01"; "Referer"="http://$ipAddress/"; "X-Requested-With"="XMLHttpRequest"; "DNT"="1"} -ContentType "application/json; charset=UTF-8" -Body "{`"command`":`"setdatapointvalue`",`"data`":{`"sessionID`":`"$sessionId`",`"uid`":5,`"value`":10}}"
# Turn on A/C
Invoke-WebRequest -Uri "http://$ipAddress/api.cgi" -Method "POST" -Headers @{"Cookie"="Intesis-Webserver={%22sessionID%22:%22$sessionId%22}"; "Origin"="http://$ipAddress"; "Accept-Encoding"="gzip, deflate"; "Accept"="application/json, text/javascript, */*; q=0.01"; "Referer"="http://$ipAddress/"; "X-Requested-With"="XMLHttpRequest"; "DNT"="1"} -ContentType "application/json; charset=UTF-8" -Body "{`"command`":`"setdatapointvalue`",`"data`":{`"sessionID`":`"$sessionId`",`"uid`":1,`"value`":1}}"

As it seems you can use command line commands, try this

That’s correct, it’s almost perfect but he doesn’t send a target temp…

Who is “he”? If you need to send a target temp you can do it in generic thermostat, see https://www.home-assistant.io/components/generic_thermostat/#target_temp

When i put my aircon on he takes the temperature wich is set in the airco by remote.
So i “lost” control when i use HA to control the aircon.

There is not much you can do about the remote and HA struggling with each other for control. Hiding the remote is probably the best way,

i have to set the temp in the aircon him self, when i set the temp in HA for example at 24 degrees and i take a look in the webinterface of the aircon it’s still the old temperature.
So i have to push the temp which set in HA to my aircon.
There is a command available in the script that i use but how can i push the temp to my aircon.
With an automation or something?