Intesis wifi unit to controll airco units

All kinds of 'OS' scripts
Post Reply
User avatar
mvveelen
Posts: 684
Joined: Friday 31 October 2014 11:22
Target OS: NAS (Synology & others)
Domoticz version: Beta
Location: Hoorn, The Netherlands
Contact:

Intesis wifi unit to controll airco units

Post by mvveelen » Friday 27 July 2018 17:41

Hi,

I have 2 airco units and for both I added a Intesis wifi unit. These units have a webserver and you can also control the units using this webserver.
A Tweaker on the Dutch Tweakers.net board made a script which I can use to control the units AND get the status when I control the units with the iPhone app (very buggy !!) or the IR remote (easy for the wife).

link to the source: https://gathering.tweakers.net/forum/li ... 7#55811907

Script:

Code: Select all

#!/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}
Now, I tried to PM Gizmocuz 2 times, just to ask if he could add this to Domoticz as new hardware, but no reply. I know he is very busy and I should make a pull request or something like that on Github, but I don't know how or where to start.
Someone can help me out? Hey, and a "no" is an answer too, right ;-)
RPi3 + RFXCOM rfxtrx433E + Xiaomi Gateway + Philips HUE Lights + Nefit Easy + Dashticz v2 + Domoticz latest Beta

User avatar
EdwinK
Posts: 1394
Joined: Sunday 22 January 2017 22:46
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Intesis wifi unit to controll airco units

Post by EdwinK » Friday 27 July 2018 18:17

Sorry, can't help you with that.

Would be cool (pun intended) if this could be implemented in the source. Now I also need some airco's that could work with it
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | RFxcom | Dashticz V2

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests