Remive pymyair mode - just use direct JSON API.
Remove -P and -x args always require jq
This commit is contained in:
parent
0a8d0f8e3e
commit
2255525436
83
aircon.sh
83
aircon.sh
|
@ -71,7 +71,6 @@ function usage() {
|
||||||
echo " -L Log all zone temperatures to CSV file, then exit (see -o)."
|
echo " -L Log all zone temperatures to CSV file, then exit (see -o)."
|
||||||
echo " -m Generate a config file based on current aircon setup."
|
echo " -m Generate a config file based on current aircon setup."
|
||||||
echo " -o file Specify CSV output file. Default: $DEFAULT_CSVFILE"
|
echo " -o file Specify CSV output file. Default: $DEFAULT_CSVFILE"
|
||||||
echo " -P Use pymyair instead of direct JSON API calls (also see -x)."
|
|
||||||
echo " -p Profiler mode."
|
echo " -p Profiler mode."
|
||||||
echo " -s Validate config file then exit."
|
echo " -s Validate config file then exit."
|
||||||
echo " -S[H] Show configured rules in human-readable format"
|
echo " -S[H] Show configured rules in human-readable format"
|
||||||
|
@ -80,8 +79,6 @@ function usage() {
|
||||||
echo " -T num Specify degrees above max temperature before taking action."
|
echo " -T num Specify degrees above max temperature before taking action."
|
||||||
echo " -w List which people are available then exit."
|
echo " -w List which people are available then exit."
|
||||||
echo " -W List zone-owning devices are available then exit."
|
echo " -W List zone-owning devices are available then exit."
|
||||||
echo " -x path Specify location of 'pymyair' (from https://github.com/smallsam/pymyair)"
|
|
||||||
echo " (only used if -P specified)"
|
|
||||||
echo " -y Actually run commands/db inserts. By default, commands are just displayed."
|
echo " -y Actually run commands/db inserts. By default, commands are just displayed."
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
@ -700,7 +697,7 @@ function gen_aircon_command() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# add_aircon_command zone_idx "comment goes here" " pymyair command to run"
|
# add_aircon_command zone_idx zone_idx2 "comment goes here" "textual version of command to run" "json command"
|
||||||
function add_aircon_command() {
|
function add_aircon_command() {
|
||||||
local x idx otheridx comment db cmd jcmd
|
local x idx otheridx comment db cmd jcmd
|
||||||
|
|
||||||
|
@ -1527,22 +1524,16 @@ function get_aircon_info() {
|
||||||
local jsoninfo url state
|
local jsoninfo url state
|
||||||
profile "query aircon"
|
profile "query aircon"
|
||||||
[[ $cronmode -eq 0 && $logmode -eq 0 ]] && echo -en "${GREEN}${BOLD}>> ${PLAIN}${GREEN}Querying aircon... ${PLAIN}"
|
[[ $cronmode -eq 0 && $logmode -eq 0 ]] && echo -en "${GREEN}${BOLD}>> ${PLAIN}${GREEN}Querying aircon... ${PLAIN}"
|
||||||
if [[ $JSONAPI -eq 1 ]]; then
|
url="${AIRCON_URL}/getSystemData"
|
||||||
url="${AIRCON_URL}/getSystemData"
|
jsoninfo=$(curl -s "$url" 2>/dev/null)
|
||||||
jsoninfo=$(curl -s "$url" 2>/dev/null)
|
zones=$(echo "$jsoninfo" | $JQ -r '.aircons.ac1.zones[] | [ .name, .state, .setTemp, .measuredTemp, .number ] | @csv' | tr -d '" ')
|
||||||
zones=$(echo "$jsoninfo" | $JQ -r '.aircons.ac1.zones[] | [ .name, .state, .setTemp, .measuredTemp, .number ] | @csv' | tr -d '" ')
|
state=$(echo "$jsoninfo" | $JQ -r '.aircons.ac1.info.state' | tr -d '" ')
|
||||||
state=$(echo "$jsoninfo" | $JQ -r '.aircons.ac1.info.state' | tr -d '" ')
|
if [[ $state == "off" ]]; then
|
||||||
if [[ $state == "off" ]]; then
|
airconmode="off"
|
||||||
airconmode="off"
|
|
||||||
else
|
|
||||||
airconmode=$(echo "$jsoninfo" | $JQ -r '.aircons.ac1.info.mode' | tr -d '" ')
|
|
||||||
fi
|
|
||||||
airconmyzoneid=$(echo "$jsoninfo" | $JQ -r '.aircons.ac1.info.myZone ' | tr -d '" ')
|
|
||||||
else
|
else
|
||||||
zones=$($MYAIR $AIRCON_IP zones | $JQ -r '.[] | [ .name, .state, .setTemp, .measuredTemp, .number ] | @csv' | tr -d '" ')
|
airconmode=$(echo "$jsoninfo" | $JQ -r '.aircons.ac1.info.mode' | tr -d '" ')
|
||||||
airconmode=$($MYAIR $AIRCON_IP mode)
|
|
||||||
airconmyzoneid=$($MYAIR $AIRCON_IP myzone)
|
|
||||||
fi
|
fi
|
||||||
|
airconmyzoneid=$(echo "$jsoninfo" | $JQ -r '.aircons.ac1.info.myZone ' | tr -d '" ')
|
||||||
nzones=0
|
nzones=0
|
||||||
for line in $zones; do
|
for line in $zones; do
|
||||||
IFS=',' read -ra tok <<< "$line"
|
IFS=',' read -ra tok <<< "$line"
|
||||||
|
@ -1784,21 +1775,16 @@ function run_commands() {
|
||||||
#echo RUNNING myair $AIRCON_IP ${airconcmd[$x]}
|
#echo RUNNING myair $AIRCON_IP ${airconcmd[$x]}
|
||||||
|
|
||||||
[[ -n ${airconcomment[$x]} ]] && action "${airconcomment[$x]}"
|
[[ -n ${airconcomment[$x]} ]] && action "${airconcomment[$x]}"
|
||||||
if [[ $JSONAPI -eq 1 ]]; then
|
|
||||||
$MYAIR $AIRCON_IP ${airconcmd[$x]} >/dev/null 2>&1
|
|
||||||
fi
|
|
||||||
influx_insert "INSERT aircon action=\"${airconcomment[$x]}\",comment=\"${airconproblem[$x]}\""
|
influx_insert "INSERT aircon action=\"${airconcomment[$x]}\",comment=\"${airconproblem[$x]}\""
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ $JSONAPI -eq 1 ]]; then
|
jurl=$(combine_commands)
|
||||||
jurl=$(combine_commands)
|
res=$(curl -s -g "$jurl" 3>/dev/null)
|
||||||
res=$(curl -s -g "$jurl" 3>/dev/null)
|
jqres=$(echo "$res" | $JQ -r '.ack' 2>/dev/null)
|
||||||
jqres=$(echo "$res" | $JQ -r '.ack' 2>/dev/null)
|
if [[ $jqres != "true" ]]; then
|
||||||
if [[ $jqres != "true" ]]; then
|
error "Myair API call failed:"
|
||||||
error "Myair API call failed:"
|
echo -e "$RED curl -s -g $jurl$PLAIN"
|
||||||
echo -e "$RED curl -s -g $jurl$PLAIN"
|
return 1
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1902,7 +1888,6 @@ limit=$DEFAULTLIMIT
|
||||||
profiler=0
|
profiler=0
|
||||||
csvfile="$DEFAULT_CSVFILE"
|
csvfile="$DEFAULT_CSVFILE"
|
||||||
sanitycheck=0
|
sanitycheck=0
|
||||||
JSONAPI=1
|
|
||||||
RULEFORMAT=ansi
|
RULEFORMAT=ansi
|
||||||
robtest=0
|
robtest=0
|
||||||
|
|
||||||
|
@ -1922,7 +1907,7 @@ fi
|
||||||
|
|
||||||
ALLARGS="$ALLARGS $*"
|
ALLARGS="$ALLARGS $*"
|
||||||
|
|
||||||
optstring="aA:bcD:f:hHi:I:k:l:Lo:pPmRsSt:T:wWx:y"
|
optstring="aA:bcD:f:hHi:I:k:l:Lo:pmRsSt:T:wWy"
|
||||||
while getopts "$optstring" i $ALLARGS; do
|
while getopts "$optstring" i $ALLARGS; do
|
||||||
case "$i" in
|
case "$i" in
|
||||||
a)
|
a)
|
||||||
|
@ -1972,9 +1957,6 @@ while getopts "$optstring" i $ALLARGS; do
|
||||||
o)
|
o)
|
||||||
csvfile="$OPTARG"
|
csvfile="$OPTARG"
|
||||||
;;
|
;;
|
||||||
P)
|
|
||||||
JSONAPI=0
|
|
||||||
;;
|
|
||||||
p)
|
p)
|
||||||
profiler=1
|
profiler=1
|
||||||
info "Profiler mode enabled"
|
info "Profiler mode enabled"
|
||||||
|
@ -2000,9 +1982,6 @@ while getopts "$optstring" i $ALLARGS; do
|
||||||
W)
|
W)
|
||||||
showwho=2
|
showwho=2
|
||||||
;;
|
;;
|
||||||
x)
|
|
||||||
MYAIR="${OPTARG}"
|
|
||||||
;;
|
|
||||||
y)
|
y)
|
||||||
DOIT=1
|
DOIT=1
|
||||||
;;
|
;;
|
||||||
|
@ -2035,30 +2014,10 @@ if [[ $makeconfig -eq 1 ]]; then
|
||||||
exit $rv
|
exit $rv
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $showwho -eq 0 ]]; then
|
JQ=$(which jq 2>/dev/null)
|
||||||
if [[ $JSONAPI -eq 1 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
JQ=$(which jq 2>/dev/null)
|
error "Can't find jq executable in path."
|
||||||
if [[ $? -ne 0 ]]; then
|
exit 1
|
||||||
error "Can't find jq executable in path."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
if [[ -n $MYAIR ]]; then
|
|
||||||
warn "-x option ignored as -P not used."
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
if [[ -z $MYAIR ]]; then
|
|
||||||
MYAIR=$(which myair 2>/dev/null)
|
|
||||||
if [[ $? -ne 0 ]]; then
|
|
||||||
error "Can't find pymyair executable 'myair' in path. Install it from here: https://github.com/smallsam/pymyair"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
if [[ ! -x "$MYAIR" ]]; then
|
|
||||||
error "Specified pymyair executable '$MYAIR' not found."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Must do this BEFORE parsing the config file, otherwise
|
# Must do this BEFORE parsing the config file, otherwise
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 61 KiB |
|
@ -0,0 +1,88 @@
|
||||||
|
get_aircon_info:
|
||||||
|
|
||||||
|
zones=$(myair $AIRCON_IP zones | jq -r '.[] | [ .name, .state, .setTemp, .measuredTemp, .number ] | @csv' | tr -d '" ')
|
||||||
|
airconmode=$(myair $AIRCON_IP mode)
|
||||||
|
airconmyzoneid=$(myair $AIRCON_IP myzone)
|
||||||
|
|
||||||
|
curl http://10.99.99.1:2025/getSystemData
|
||||||
|
|
||||||
|
| jq '.aircons.ac1.zones[] | [ .name, .state, .setTemp, .measuredTemp, .number ]'
|
||||||
|
| jq .aircons.ac1.info.mode
|
||||||
|
| jq .aircons.ac1.info.myZone
|
||||||
|
|
||||||
|
|
||||||
|
from show_proposed_commands:
|
||||||
|
for x in ${!airconcmd[@]}; do
|
||||||
|
fullcmd="myair $AIRCON_IP ${airconcmd[$x]}"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
add_aircon_command $idx -1 "Power on system" "on"
|
||||||
|
/setAircon?json={"ac1":{"info":{"state":"on"}}}
|
||||||
|
|
||||||
|
add_aircon_command $idx -1 "Power off system" "off"
|
||||||
|
/setAircon?json={"ac1":{"info":{"state":"off"}}}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
example:::: http://10.0.0.10:2025/setAircon?json={ac1:{"info":{"state":"on","mode":"cool"},"zones":{"z10":{"value":80}}}}}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
add_aircon_command $idx -1 "Set MyZone to ${zname[$idx]}" "myzone --zone ${zid[$idx]}"
|
||||||
|
setAircon?json={ac1:{"info":{"myZone":xxxxxxx}}}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
add_aircon_command $idx $otheridx "Open vent in ${zname[$otheridx]}" "set --zone ${otherid} --state on --temp ${zsettemp[$otheridx]}"
|
||||||
|
|
||||||
|
setAircon?json={ac1:{"zones":{"z00":{"state":"open","setTemp",xxx}}}}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
add_aircon_command $idx $otheridx "Close vent in ${zname[$otheridx]}" "set --zone ${otherid} --state off --temp ${zsettemp[$otheridx]}"
|
||||||
|
setAircon?json={ac1:{"zones":{"z00":{"state":"close","setTemp",xxx}}}}
|
||||||
|
|
||||||
|
add_aircon_command $idx -1 "Set system mode to '$str'" "$str"
|
||||||
|
setAircon?json={ac1:{"info":{"mode":"heat"}}}
|
||||||
|
|
||||||
|
add_aircon_command $idx -1 "In zone ${zname[$idx]}, $comm" "set --zone ${zid[$idx]}$toadd"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# add_aircon_command zone_idx "comment goes here" "actual pymyair command to run"
|
||||||
|
function add_aircon_command() {
|
||||||
|
|
||||||
|
pass a json to add_aircon_cmd
|
||||||
|
wrap in:
|
||||||
|
{
|
||||||
|
"ac1":{
|
||||||
|
xxxxxxx
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
merge all jsons with:
|
||||||
|
jq -s '.[0] * .[1] * .[2] * .[3]' base 1 2 3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
pass to aircon in a single call
|
||||||
|
|
||||||
|
|
||||||
|
from run_commands:
|
||||||
|
for x in ${!airconcmd[@]}; do
|
||||||
|
[[ -n ${airconcomment[$x]} ]] && action "${airconcomment[$x]}"
|
||||||
|
echo RUNNING myair $AIRCON_IP ${airconcmd[$x]}
|
||||||
|
|
||||||
|
|
||||||
|
from base:
|
||||||
|
|
||||||
|
if [[ $showwho -eq 0 ]]; then
|
||||||
|
if [[ -z $MYAIR ]]; then
|
||||||
|
MYAIR=$(which myair)
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
error "Can't find pymyair executable 'myair' in path. Install it from here: https://github.com/smallsam/pymyair"
|
||||||
|
exit 1
|
Loading…
Reference in New Issue