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
45
aircon.sh
45
aircon.sh
|
@ -71,7 +71,6 @@ function usage() {
|
|||
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 " -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 " -s Validate config file then exit."
|
||||
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 " -w List which people 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
|
||||
}
|
||||
|
@ -700,7 +697,7 @@ function gen_aircon_command() {
|
|||
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() {
|
||||
local x idx otheridx comment db cmd jcmd
|
||||
|
||||
|
@ -1527,7 +1524,6 @@ function get_aircon_info() {
|
|||
local jsoninfo url state
|
||||
profile "query aircon"
|
||||
[[ $cronmode -eq 0 && $logmode -eq 0 ]] && echo -en "${GREEN}${BOLD}>> ${PLAIN}${GREEN}Querying aircon... ${PLAIN}"
|
||||
if [[ $JSONAPI -eq 1 ]]; then
|
||||
url="${AIRCON_URL}/getSystemData"
|
||||
jsoninfo=$(curl -s "$url" 2>/dev/null)
|
||||
zones=$(echo "$jsoninfo" | $JQ -r '.aircons.ac1.zones[] | [ .name, .state, .setTemp, .measuredTemp, .number ] | @csv' | tr -d '" ')
|
||||
|
@ -1538,11 +1534,6 @@ function get_aircon_info() {
|
|||
airconmode=$(echo "$jsoninfo" | $JQ -r '.aircons.ac1.info.mode' | tr -d '" ')
|
||||
fi
|
||||
airconmyzoneid=$(echo "$jsoninfo" | $JQ -r '.aircons.ac1.info.myZone ' | tr -d '" ')
|
||||
else
|
||||
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)
|
||||
fi
|
||||
nzones=0
|
||||
for line in $zones; do
|
||||
IFS=',' read -ra tok <<< "$line"
|
||||
|
@ -1784,13 +1775,9 @@ function run_commands() {
|
|||
#echo RUNNING myair $AIRCON_IP ${airconcmd[$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]}\""
|
||||
done
|
||||
|
||||
if [[ $JSONAPI -eq 1 ]]; then
|
||||
jurl=$(combine_commands)
|
||||
res=$(curl -s -g "$jurl" 3>/dev/null)
|
||||
jqres=$(echo "$res" | $JQ -r '.ack' 2>/dev/null)
|
||||
|
@ -1799,7 +1786,6 @@ function run_commands() {
|
|||
echo -e "$RED curl -s -g $jurl$PLAIN"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function profile() {
|
||||
|
@ -1902,7 +1888,6 @@ limit=$DEFAULTLIMIT
|
|||
profiler=0
|
||||
csvfile="$DEFAULT_CSVFILE"
|
||||
sanitycheck=0
|
||||
JSONAPI=1
|
||||
RULEFORMAT=ansi
|
||||
robtest=0
|
||||
|
||||
|
@ -1922,7 +1907,7 @@ fi
|
|||
|
||||
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
|
||||
case "$i" in
|
||||
a)
|
||||
|
@ -1972,9 +1957,6 @@ while getopts "$optstring" i $ALLARGS; do
|
|||
o)
|
||||
csvfile="$OPTARG"
|
||||
;;
|
||||
P)
|
||||
JSONAPI=0
|
||||
;;
|
||||
p)
|
||||
profiler=1
|
||||
info "Profiler mode enabled"
|
||||
|
@ -2000,9 +1982,6 @@ while getopts "$optstring" i $ALLARGS; do
|
|||
W)
|
||||
showwho=2
|
||||
;;
|
||||
x)
|
||||
MYAIR="${OPTARG}"
|
||||
;;
|
||||
y)
|
||||
DOIT=1
|
||||
;;
|
||||
|
@ -2035,31 +2014,11 @@ if [[ $makeconfig -eq 1 ]]; then
|
|||
exit $rv
|
||||
fi
|
||||
|
||||
if [[ $showwho -eq 0 ]]; then
|
||||
if [[ $JSONAPI -eq 1 ]]; then
|
||||
JQ=$(which jq 2>/dev/null)
|
||||
if [[ $? -ne 0 ]]; then
|
||||
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
|
||||
|
||||
# Must do this BEFORE parsing the config file, otherwise
|
||||
# we can't resolve zone names.
|
||||
|
|
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