bugfix: make zone device owners actuall work properly

bugfix:  ignoring zones now actually works properly
improve human-readable rule output
remove zownerperson[] which is never actually used
This commit is contained in:
Rob Pearce 2022-05-28 15:09:29 +10:00
parent 7a5452ddfa
commit b5dd14efdc
4 changed files with 183 additions and 59 deletions

20
a.html Normal file
View File

@ -0,0 +1,20 @@
- <font color=#000000></strong></s>Only operate the aircon in <strong><font color=#00dddd>cool<font color=#000000></strong></s> mode<font color=#000000></strong></s><br></s></strong><font color=#000000>
- <font color=#000000></strong></s><strong><font color=#bbbb00>Close<font color=#000000></strong></s> vent in <font color=#ffa500>Study<font color=#000000></strong></s> if <strong><font color=#00aa00>[<font color=#000000></strong></s><font color=#00aa00>robsphone<font color=#000000></strong></s><strong><font color=#00aa00>]<font color=#000000></strong></s> isn't online<font color=#000000></strong></s><br></s></strong><font color=#000000>
- <font color=#000000></strong></s><strong><font color=#bbbb00>Close<font color=#000000></strong></s> vent in <font color=#ffa500>Rob&Beth<font color=#000000></strong></s> if <strong><font color=#00aa00>[<font color=#000000></strong></s><font color=#00aa00>robsphone bethsphone<font color=#000000></strong></s><strong><font color=#00aa00>]<font color=#000000></strong></s> aren't online<font color=#000000></strong></s><br></s></strong><font color=#000000>
- <font color=#000000></strong></s><strong><font color=#bbbb00>Close<font color=#000000></strong></s> vent in <font color=#ffa500>Brendan<font color=#000000></strong></s> if <strong><font color=#00aa00>[<font color=#000000></strong></s><font color=#00aa00>brendansphone bethsphone<font color=#000000></strong></s><strong><font color=#00aa00>]<font color=#000000></strong></s> aren't online<font color=#000000></strong></s><br></s></strong><font color=#000000>
- <font color=#000000></strong></s><strong><font color=#bbbb00>Close<font color=#000000></strong></s> vent in <font color=#ffa500>Media<font color=#000000></strong></s> if <strong><font color=#00aa00>[<font color=#000000></strong></s><font color=#00aa00>lg-wifi<font color=#000000></strong></s><strong><font color=#00aa00>]<font color=#000000></strong></s> isn't online<font color=#000000></strong></s><br></s></strong><font color=#000000>
- <font color=#000000></strong></s><strong><font color=#bbbb00>Close<font color=#000000></strong></s> vent in <font color=#ffa500>Ben/Sewing<font color=#000000></strong></s> if <strong><font color=#00aa00>[<font color=#000000></strong></s><font color=#00aa00>bensipad<font color=#000000></strong></s><strong><font color=#00aa00>]<font color=#000000></strong></s> isn't online<font color=#000000></strong></s><br></s></strong><font color=#000000>
- <font color=#000000></strong></s><s><font color=#aaaaaa><INACTIVE> From Mon to Fri between 08:30 and 18:00, Close vent in Ben/Sewing if [brendansphone] isn't online<font color=#000000></strong></s></s><br>
- <font color=#000000></strong></s>Prevent <font color=#ffa500>Nursery<font color=#000000></strong></s> from being the MyZone<font color=#000000></strong></s><br></s></strong><font color=#000000>
- <font color=#000000></strong></s>Prevent <font color=#ffa500>Ben/Sewing<font color=#000000></strong></s> from being the MyZone<font color=#000000></strong></s><br></s></strong><font color=#000000>
- <font color=#000000></strong></s><s><font color=#aaaaaa><INACTIVE> From Mon to Tue between 08:30 and 16:30, Force the vent in Nursery to be closed<font color=#000000></strong></s></s><br>
- <font color=#000000></strong></s>Force the vent in <font color=#ffa500>Nursery<font color=#000000></strong></s> to be <strong><font color=#bbbb00>closed<font color=#000000></strong></s><font color=#000000></strong></s><br></s></strong><font color=#000000>
- <font color=#000000></strong></s><font color=#ff97c6>From <strong><font color=#ff97c6>Sat<font color=#000000></strong></s><font color=#ff97c6> to <strong><font color=#ff97c6>Sun<font color=#000000></strong></s><font color=#ff97c6><font color=#000000></strong></s>, Ignore <font color=#ffa500>Study<font color=#000000></strong></s> temperature when deciding what to do<font color=#000000></strong></s><br></s></strong><font color=#000000>
- <font color=#000000></strong></s><font color=#ff97c6>Between <strong><font color=#ff97c6>06:00<font color=#000000></strong></s><font color=#ff97c6> and <strong><font color=#ff97c6>23:59<font color=#000000></strong></s><font color=#ff97c6><font color=#000000></strong></s>, Keep temperature of <font color=#ffa500>Family<font color=#000000></strong></s> between <strong><font color=#0000dd>20<font color=#000000></strong></s>-<strong><font color=#dd0000>23<font color=#000000></strong></s> degrees<font color=#000000></strong></s><br></s></strong><font color=#000000>
- <font color=#000000></strong></s><s><font color=#aaaaaa><INACTIVE> Between 20:00 and 07:00, Keep temperature of Brendan between 20-23 degrees<font color=#000000></strong></s></s><br>
- <font color=#000000></strong></s>Keep temperature of <font color=#ffa500>Media<font color=#000000></strong></s> between <strong><font color=#0000dd>18<font color=#000000></strong></s>-<strong><font color=#dd0000>23<font color=#000000></strong></s> degrees<font color=#000000></strong></s><br></s></strong><font color=#000000>
- <font color=#000000></strong></s>Keep temperature of <font color=#ffa500>Rob&Beth<font color=#000000></strong></s> between <strong><font color=#0000dd>20<font color=#000000></strong></s>-<strong><font color=#dd0000>23<font color=#000000></strong></s> degrees<font color=#000000></strong></s><br></s></strong><font color=#000000>
- <font color=#000000></strong></s><s><font color=#aaaaaa><INACTIVE> From Mon to Fri between 08:30 and 17:30, Keep temperature of Study between 20-22 degrees<font color=#000000></strong></s></s><br>
- <font color=#000000></strong></s><s><font color=#aaaaaa><INACTIVE> Between 20:00 and 07:00, Keep temperature of Ben/Sewing between 20-23 degrees<font color=#000000></strong></s></s><br>
- <font color=#000000></strong></s><s><font color=#aaaaaa><INACTIVE> From Mon to Fri between 08:30 and 17:30, Keep temperature of Ben/Sewing between 20-23 degrees<font color=#000000></strong></s></s><br>

220
aircon.sh
View File

@ -70,7 +70,7 @@ function usage() {
echo " -S[H] Show configured rules in human-readable format" echo " -S[H] Show configured rules in human-readable format"
echo " (HTML if -H given, otherwise ANSI)." echo " (HTML if -H given, otherwise ANSI)."
echo " -w List which people are available then exit." echo " -w List which people are available then exit."
echo " -W List zone owners' devices are available then exit." echo " -W List zone-owning devices are available then exit."
echo " -t num Specify degrees below min temperature before taking action." echo " -t num Specify degrees below min temperature before taking action."
echo " -T num Specify degrees above max temperature before taking action." echo " -T num Specify degrees above max temperature before taking action."
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."
@ -117,7 +117,7 @@ function getzoneaction() { # populates zproblem[] and zaction[]
else else
if [[ -z ${zowner[$idx]} ]]; then if [[ -z ${zowner[$idx]} ]]; then
pingok=1 pingok=1
elif canping "${zowner[$idx]}"; then elif canping ${zowner[$idx]}; then
pingok=1 pingok=1
else else
pingok=0 pingok=0
@ -151,6 +151,7 @@ function getzoneaction() { # populates zproblem[] and zaction[]
#info "${zname[$idx]} priority is $priority" #info "${zname[$idx]} priority is $priority"
zproblem[$idx]="$problem" zproblem[$idx]="$problem"
zpri[$idx]="$priority" zpri[$idx]="$priority"
zownerhome[$idx]="$pingok"
if [[ $problem == "owner_not_home" ]]; then if [[ $problem == "owner_not_home" ]]; then
# turn the zone off # turn the zone off
@ -337,6 +338,7 @@ function generate_actions() { # populates global: nairconcommands & airconcmd
for x in ${!zname[@]}; do for x in ${!zname[@]}; do
getzoneaction $x getzoneaction $x
#echo "zoneignore for ${zname[$x]} is ${zignore[$x]}" >/dev/stderr
done done
# pass 1 # pass 1
@ -637,6 +639,7 @@ function add_aircon_command() {
airconcmdzone[$nairconcommands]="${zname[$idx]}" airconcmdzone[$nairconcommands]="${zname[$idx]}"
airconcmdotherzone[$nairconcommands]="${zname[$otheridx]}" airconcmdotherzone[$nairconcommands]="${zname[$otheridx]}"
airconproblem[$nairconcommands]="${zname[$idx]} is ${zproblem[$idx]/_/ }" airconproblem[$nairconcommands]="${zname[$idx]} is ${zproblem[$idx]/_/ }"
ooooooooooo
#if [[ $otheridx -ne -1 ]]; then #if [[ $otheridx -ne -1 ]]; then
# airconcomment[$nairconcommands]="${airconcomment[$nairconcommands]}, update nearby zone ${zname[$otheridx]}" # airconcomment[$nairconcommands]="${airconcomment[$nairconcommands]}, update nearby zone ${zname[$otheridx]}"
#fi #fi
@ -672,8 +675,12 @@ function addforcevent() {
[[ $idx == $nforcevents ]] && nforcevents=$((nforcevents + 1)) [[ $idx == $nforcevents ]] && nforcevents=$((nforcevents + 1))
} }
function addtemprange() { function addtemprange() { # [-s] idx min-max -s means 'set zwanttemp+zwantmin+zwantmax too'
local x idx local x idx doset=0
if [[ $1 == "-s" ]]; then
doset=1
shift
fi
idx=$ntempranges idx=$ntempranges
for x in ${!tr_zonename[@]}; do for x in ${!tr_zonename[@]}; do
if [[ ${tr_zonename[$x]} == "$1" ]]; then if [[ ${tr_zonename[$x]} == "$1" ]]; then
@ -681,9 +688,36 @@ function addtemprange() {
break; break;
fi fi
done done
tr_zonename[$idx]="$1" tr_zonename[$idx]="$1"
tr_range[$idx]="$2" tr_range[$idx]="$2"
if [[ $doset -eq 1 ]]; then
local wanttemp zidx
wanttemp=$(gettemprange "$1")
zidx=$(getidxfromname "$1")
if [[ $wanttemp == "n/a" ]]; then
zwanttemp[$zidx]="n/a"
zwantmin[$zidx]="-99"
zwantmax[$zidx]="99"
else
zwanttemp[$zidx]="$wanttemp"
zwantmin[$zidx]="${wanttemp%-*}"
zwantmax[$zidx]="${wanttemp#*-}"
fi
fi
[[ $idx == $ntempranges ]] && ntempranges=$((ntempranges + 1)) [[ $idx == $ntempranges ]] && ntempranges=$((ntempranges + 1))
} }
function addadj() { function addadj() {
@ -721,9 +755,13 @@ function addperson() {
[[ $idx == $npeople ]] && npeople=$((npeople + 1)) [[ $idx == $npeople ]] && npeople=$((npeople + 1))
} }
function addowner() { function addowner() { # zone "host1 host2 ..."
local z h local x idx db local z h local x idx db doset=0
db=0 db=0
if [[ $1 == "-s" ]]; then
doset=1
shift
fi
z="$1" z="$1"
shift shift
@ -745,21 +783,28 @@ function addowner() {
fi fi
[[ $db -eq 1 ]] && info " hosts val is: ${ownerhost[$idx]}" [[ $db -eq 1 ]] && info " hosts val is: ${ownerhost[$idx]}"
[[ $idx == $nowners ]] && nowners=$((nowners + 1)) [[ $idx == $nowners ]] && nowners=$((nowners + 1))
if [[ $doset -eq 1 ]]; then
local zidx
zidx=$(getidxfromname "$z")
zowner[$zidx]="${ownerhost[$idx]}";
#zownerperson[$zidx]=$(getownerperson "$z"); # may be overwritten later
fi
} }
# getownerperson zone_name # getownerperson zone_name
# returns name of person who owns zone # returns name of person who owns zone
function getownerperson() { #function getownerperson() {
local x retval # local x retval
retval="" # retval=""
for x in ${!ownerzone[@]}; do # for x in ${!ownerzone[@]}; do
if [[ ${ownerzone[$x]} == "$1" ]]; then # if [[ ${ownerzone[$x]} == "$1" ]]; then
retval="${ownerperson[$x]}" # retval="${ownerperson[$x]}"
break # break
fi # fi
done # done
echo "$retval" # echo "$retval"
} #}
# getowner zone_name # getowner zone_name
# returns devices associated woth zone # returns devices associated woth zone
@ -832,6 +877,7 @@ function load_config() {
db=0 db=0
rv=0 rv=0
while read line; do while read line; do
ok=1 # default to okay
line=${line%%#*} # remove comments line=${line%%#*} # remove comments
if [[ -n ${line// } ]]; then if [[ -n ${line// } ]]; then
# time based options # time based options
@ -847,7 +893,7 @@ function load_config() {
if [[ $ok -eq 1 ]]; then if [[ $ok -eq 1 ]]; then
IFS=' ' read -ra tok <<< "$line" IFS=' ' read -ra tok <<< "$line"
if [[ ${tok[0]} == "temp" ]]; then if [[ ${tok[0]} == "temp" ]]; then
addtemprange ${tok[1]} ${tok[2]} addtemprange -s ${tok[1]} ${tok[2]}
elif [[ ${tok[0]} == "constant" ]]; then elif [[ ${tok[0]} == "constant" ]]; then
constant=${tok[1]} constant=${tok[1]}
elif [[ ${tok[0]} == "adj" ]]; then elif [[ ${tok[0]} == "adj" ]]; then
@ -859,7 +905,7 @@ function load_config() {
elif [[ ${tok[0]} == "force" ]]; then elif [[ ${tok[0]} == "force" ]]; then
addforcevent ${tok[1]} ${tok[2]} addforcevent ${tok[1]} ${tok[2]}
elif [[ ${tok[0]} == "owner" ]]; then elif [[ ${tok[0]} == "owner" ]]; then
addowner ${tok[1]} ${tok[@]:2} addowner -s ${tok[1]} ${tok[@]:2}
elif [[ ${tok[0]} == "person" ]]; then elif [[ ${tok[0]} == "person" ]]; then
addperson ${tok[1]} ${tok[@]:2} addperson ${tok[1]} ${tok[@]:2}
elif [[ ${tok[0]} == "modelock" ]]; then elif [[ ${tok[0]} == "modelock" ]]; then
@ -975,11 +1021,14 @@ function processtimeconditions() {
fi fi
done done
[[ $db -eq 1 ]] && info " ok=$ok nonmatches=$nonmatches"
if [[ $ok -eq 0 || $nonmatches -gt 0 ]]; then if [[ $ok -eq 0 || $nonmatches -gt 0 ]]; then
rv=1 rv=1
else else
rv=0 rv=0
fi fi
[[ $db -eq 1 ]] && info " returning $rv"
return $rv return $rv
} }
@ -1052,6 +1101,7 @@ function parse_config() {
local cond allconds x local cond allconds x
local db fileok=1 linenum show=0 local db fileok=1 linenum show=0
local config_human line_human errstr local config_human line_human errstr
local ign="" thisignored=0 oneof
if [[ -n $1 ]]; then if [[ -n $1 ]]; then
show=$1 show=$1
@ -1065,6 +1115,7 @@ function parse_config() {
ok=1 ok=1
active_cols active_cols
line=${line%%#*} # remove comments line=${line%%#*} # remove comments
thisignored=0
line_human="" line_human=""
if [[ ! -z ${line// } ]]; then if [[ ! -z ${line// } ]]; then
# time based options # time based options
@ -1081,11 +1132,14 @@ function parse_config() {
fi fi
fi fi
IFS=' ' read -ra tok <<< "$line" IFS=' ' read -ra tok <<< "$line"
if [[ ${tok[0]} == "temp" ]]; then if [[ ${tok[0]} == "temp" ]]; then
local min max local min max
min=${tok[2]%-*} min=${tok[2]%-*}
max=${tok[2]#*-} max=${tok[2]#*-}
[[ $ign == *\ ${tok[1]}* ]] && thisignored=1 # zone is being ignored
[[ $thisignored -eq 1 ]] && inactive_cols
line_human="${line_human}Keep temperature of ${roomc}${tok[1]}${linec} between ${minc}${min}${linec}-${maxc}${max}${linec} degrees" line_human="${line_human}Keep temperature of ${roomc}${tok[1]}${linec} between ${minc}${min}${linec}-${maxc}${max}${linec} degrees"
elif [[ ${tok[0]} == "constant" ]]; then elif [[ ${tok[0]} == "constant" ]]; then
true true
@ -1097,6 +1151,7 @@ function parse_config() {
line_human="${line_human}Prevent ${roomc}${tok[1]}${linec} from being the MyZone" line_human="${line_human}Prevent ${roomc}${tok[1]}${linec} from being the MyZone"
elif [[ ${tok[0]} == "noop" || ${tok[0]} == "ignore" ]]; then elif [[ ${tok[0]} == "noop" || ${tok[0]} == "ignore" ]]; then
line_human="${line_human}Ignore ${roomc}${tok[1]}${linec} temperature when deciding what to do" line_human="${line_human}Ignore ${roomc}${tok[1]}${linec} temperature when deciding what to do"
ign="${ign} ${tok[1]}"
elif [[ ${tok[0]} == "force" ]]; then elif [[ ${tok[0]} == "force" ]]; then
if [[ $VALID_ZONE_STATES == *\ ${tok[2]}\ * ]]; then if [[ $VALID_ZONE_STATES == *\ ${tok[2]}\ * ]]; then
local adj local adj
@ -1110,13 +1165,16 @@ function parse_config() {
elif [[ ${tok[0]} == "owner" ]]; then elif [[ ${tok[0]} == "owner" ]]; then
local devices verb local devices verb
devices="${devc}${tok[@]:2}${linec}" devices="${devc}${tok[@]:2}${linec}"
devices="${devbc}[${linec}${devices}${devbc}]${linec}"
if [[ ${#tok[@]} -eq 3 ]]; then if [[ ${#tok[@]} -eq 3 ]]; then
verb="isn't" verb="isn't"
oneof=""
devices="${devbc}${linec}${devices}${devbc}${linec}"
else else
verb="aren't" verb="aren't"
oneof=" one of"
devices="${devbc}(${linec}${devices}${devbc})${linec}"
fi fi
line_human="${line_human}${statec}Close${linec} vent in ${roomc}${tok[1]}${linec} if $devices $verb online" line_human="${line_human}${statec}Close${linec} vent in ${roomc}${tok[1]}${linec} if${oneof} $devices $verb online"
elif [[ ${tok[0]} == "modelock" ]]; then elif [[ ${tok[0]} == "modelock" ]]; then
if [[ $VALID_MODES == *\ ${tok[1]}\ * ]]; then if [[ $VALID_MODES == *\ ${tok[1]}\ * ]]; then
local col local col
@ -1136,7 +1194,9 @@ function parse_config() {
fi fi
if [[ -n $line_human ]]; then if [[ -n $line_human ]]; then
if [[ $ok -eq 0 ]]; then if [[ $ok -eq 0 ]]; then
line_human="${plainc}${inactc}<INACTIVE> ${linec}${line_human}" line_human="${plainc}${inactc}[out-of-hours] ${linec}${line_human}"
elif [[ $thisignored -eq 1 ]]; then
line_human="${plainc}${inactc}[ignored] ${linec}${line_human}"
fi fi
config_human="${config_human}- ${linec}${line_human}${plainc}$nl" config_human="${config_human}- ${linec}${line_human}${plainc}$nl"
fi fi
@ -1175,7 +1235,8 @@ function canping() {
thisrv=1 thisrv=1
else else
arp -d $ip >/dev/null 2>&1 arp -d $ip >/dev/null 2>&1
ping -c1 -w1 -n -q $ip >/dev/null 2>&1 & #ping -c1 -w1 -n -q $ip >/dev/null 2>&1 &
arping -c10 -W0.1 -w2 -C1 -q ${ip} 2>/dev/null
sleep 0.3 sleep 0.3
mac=$(arp -n $ip) mac=$(arp -n $ip)
mac=$(echo "$mac" | egrep -v "Host|xpired" | awk '{print $2}') mac=$(echo "$mac" | egrep -v "Host|xpired" | awk '{print $2}')
@ -1205,17 +1266,18 @@ function addzone() {
zproblem[$nzones]="n/a" zproblem[$nzones]="n/a"
zaction[$nzones]="n/a" zaction[$nzones]="n/a"
zactionfail[$nzones]=0 zactionfail[$nzones]=0
zowner[$nzones]=$(getowner "$name") zowner[$nzones]=$(getowner "$name") # devices which 'own' the zone - may be overwritten later
zownerperson[$nzones]=$(getownerperson "$name") #zownerperson[$nzones]=$(getownerperson "$name") # may be overwritten later
zownerhome[$nzones]=1
#info "zone $name owner is [${zowner[$nzones]}]" #info "zone $name owner is [${zowner[$nzones]}]"
zignore[$nzones]=0 zignore[$nzones]=0
znomyzone[$nzones]=0 znomyzone[$nzones]=0
zpri[$nzones]=0 zpri[$nzones]=0
wanttemp=$(gettemprange "$name") wanttemp=$(gettemprange "$name")
if [[ $wanttemp == "n/a" ]]; then if [[ $wanttemp == "n/a" ]]; then
zwanttemp[$nzones]="n/a" zwanttemp[$nzones]="n/a" # default - this will be overridden in load_config
zwantmin[$nzones]="-99" zwantmin[$nzones]="-99" # default - this will be overridden in load_config
zwantmax[$nzones]="99" zwantmax[$nzones]="99" # default - this will be overridden in load_config
else else
zwanttemp[$nzones]="$wanttemp" zwanttemp[$nzones]="$wanttemp"
zwantmin[$nzones]="${wanttemp%-*}" zwantmin[$nzones]="${wanttemp%-*}"
@ -1288,6 +1350,7 @@ function gen_config() {
function get_aircon_info() { function get_aircon_info() {
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}"
zones=$(myair $AIRCON_IP zones | jq -r '.[] | [ .name, .state, .setTemp, .measuredTemp, .number ] | @csv' | tr -d '" ') zones=$(myair $AIRCON_IP zones | jq -r '.[] | [ .name, .state, .setTemp, .measuredTemp, .number ] | @csv' | tr -d '" ')
airconmode=$(myair $AIRCON_IP mode) airconmode=$(myair $AIRCON_IP mode)
nzones=0 nzones=0
@ -1303,10 +1366,11 @@ function get_aircon_info() {
function show_aircon_status() { function show_aircon_status() {
local zonestr zonecol settempcol actioncol thiswantcol thisstate thisstateform local zonestr zonecol settempcol actioncol thiswantcol thisstate thisstateform
local thisformat x powercol lockcol local actualtempformat x powercol lockcol actionstr
local FORMAT1 FORMAT2 FORMATHOT FORMATCOLD FORMATOK CLOSEDFORM OPENFORM local FORMAT1 FORMAT2 FORMATHOT FORMATCOLD FORMATOK CLOSEDFORM OPENFORM
local ownercol ownerform
FORMAT1="${BOLD}%-16s%-7s%-8s%-7s%-7s%s${PLAIN}" FORMAT1="${BOLD}%-16s%-9s%-8s%-7s%-7s%-7s%s${PLAIN}"
FORMAT2="${UNDERLINE}${FORMAT1}${PLAIN}" FORMAT2="${UNDERLINE}${FORMAT1}${PLAIN}"
FORMATHOT="${RED}%-7s${PLAIN}" FORMATHOT="${RED}%-7s${PLAIN}"
FORMATCOLD="${CYAN}%-7s${PLAIN}" FORMATCOLD="${CYAN}%-7s${PLAIN}"
@ -1327,15 +1391,15 @@ function show_aircon_status() {
echo echo
printf "$FORMAT1\n" "" "Valid" "" "Set" "Actual" "Proposed " printf "$FORMAT1\n" "" "Valid" "" "Set" "Actual" "Owner" "Proposed "
printf "$FORMAT2\n" "Zone" "Temp" "State" "Temp" "Temp" "Action " printf "$FORMAT2\n" "Zone" "Temp" "State" "Temp" "Temp" "Home" "Action "
for x in ${!zname[@]}; do for x in ${!zname[@]}; do
if [[ ${zproblem[$x]} == "too_hot" ]]; then if [[ ${zproblem[$x]} == "too_hot" ]]; then
thisformat="${FORMATHOT}" actualtempformat="${FORMATHOT}"
elif [[ ${zproblem[$x]} == "too_cold" ]]; then elif [[ ${zproblem[$x]} == "too_cold" ]]; then
thisformat="${FORMATCOLD}" actualtempformat="${FORMATCOLD}"
else else
thisformat="${FORMATOK}" actualtempformat="${FORMATOK}"
fi fi
if [[ ${airconmode} == "off" ]]; then if [[ ${airconmode} == "off" ]]; then
thisstateform="${CLOSEDFORM}" thisstateform="${CLOSEDFORM}"
@ -1353,6 +1417,13 @@ function show_aircon_status() {
else else
thiswantcol="$PLAIN" thiswantcol="$PLAIN"
fi fi
# override
if [[ ${zignore[$x]} -eq 1 ]]; then
thiswant="ignore"
thiswantcol="$GREY"
fi
if [[ ${zactionfail[$x]} -eq 1 || ${zaction[$x]} == "n/a" ]]; then if [[ ${zactionfail[$x]} -eq 1 || ${zaction[$x]} == "n/a" ]]; then
actioncol="$GREY" actioncol="$GREY"
else else
@ -1376,7 +1447,23 @@ function show_aircon_status() {
zonestr="${zname[$x]} (C)" zonestr="${zname[$x]} (C)"
fi fi
printf "$zonecol%-16s$PLAIN$thiswantcol%-7s$PLAIN$thisstateform$settempcol%-7s$PLAIN$thisformat$actioncol%s$PLAIN\n" "${zonestr}" "${thiswant}" "${thisstate}" "${zsettemp[$x]}" "${ztemp[$x]}" "${zaction[$x]}" if [[ -z ${zowner[$x]} ]]; then
ownercol="$GREY"
ownerstr="n/a"
elif [[ ${zownerhome[$x]} -eq 1 ]]; then
ownercol="$PLAIN"
ownerstr="yes"
else
ownercol="$GREY"
ownerstr="no"
fi
actionstr="${zaction[$x]}"
#if [[ ${zaction[$x]} == "n/a" && ${zignore[$x]} -eq 1 ]]; then
# actionstr="${actionstr} (zone ignored)"
#fi
printf "$zonecol%-16s$PLAIN$thiswantcol%-9s$PLAIN$thisstateform$settempcol%-7s$PLAIN${actualtempformat}${ownercol}%-7s${PLAIN}$actioncol%s$PLAIN\n" "${zonestr}" "${thiswant}" "${thisstate}" "${zsettemp[$x]}" "${ztemp[$x]}" "$ownerstr" "${actionstr}"
done done
} }
@ -1399,12 +1486,21 @@ function show_analysis() {
[[ $what == "close" ]] && what="${what}d" [[ $what == "close" ]] && what="${what}d"
echo "- ${zname[$x]} is forced $what" echo "- ${zname[$x]} is forced $what"
else else
if [[ $constant == ${zname[$x]} ]]; then if [[ ${zownerhome[$x]} -ne 1 ]]; then
append=" (constant zone)" if [[ ${zowner[$x]} == *\ * ]]; then
append1=", but (${zowner[$x]}) aren't online"
else
append1=", but ${zowner[$x]} isn't online"
fi
else else
append="" append1=""
fi fi
echo "- ${zname[$x]} is ${zproblem[$x]/_/ }${append}" if [[ $constant == ${zname[$x]} ]]; then
append2=" (constant zone)"
else
append2=""
fi
echo "- ${zname[$x]} is ${zproblem[$x]/_/ }${append1}${append2}"
fi fi
count=$((count + 1)) count=$((count + 1))
fi fi
@ -1558,7 +1654,6 @@ csvfile="$DEFAULT_CSVFILE"
sanitycheck=0 sanitycheck=0
RULEFORMAT=ansi RULEFORMAT=ansi
# check for config file option first # check for config file option first
if [[ $* == *-f\ * ]]; then if [[ $* == *-f\ * ]]; then
cf=$(echo "$*" | sed -e 's/.*-f //;s/ .*//') cf=$(echo "$*" | sed -e 's/.*-f //;s/ .*//')
@ -1670,18 +1765,9 @@ if [[ $makeconfig -eq 1 ]]; then
exit $rv exit $rv
fi fi
if [[ -e $CONFIGFILE ]]; then
if [[ $sanitycheck -ge 1 ]]; then
parse_config $sanitycheck
exit $?
elif ! load_config; then
error "Config load failed"
exit 1
fi
else
error "Config file $CONFIGFILE doesn't exist."
exit 1
fi
if [[ $showwho -eq 0 ]]; then if [[ $showwho -eq 0 ]]; then
if [[ -z $MYAIR ]]; then if [[ -z $MYAIR ]]; then
@ -1698,6 +1784,25 @@ if [[ $showwho -eq 0 ]]; then
fi fi
fi fi
# Must do this BEFORE parsing the config file, otherwise
# we can't resolve zone names.
get_aircon_info
if [[ -e $CONFIGFILE ]]; then
if [[ $sanitycheck -ge 1 ]]; then
parse_config $sanitycheck
exit $?
elif ! load_config; then
error "Config load failed"
exit 1
fi
else
error "Config file $CONFIGFILE doesn't exist."
exit 1
fi
# ping all hosts in background to populate arp table # ping all hosts in background to populate arp table
for x in ${devices}; do for x in ${devices}; do
ping -c1 -w1 -n -q $ip >/dev/null 2>&1 & ping -c1 -w1 -n -q $ip >/dev/null 2>&1 &
@ -1717,7 +1822,7 @@ if [[ $showwho -eq 1 ]]; then
echo echo
printf "$TFORMAT" "Person" "Availability" printf "$TFORMAT" "Person" "Availability"
for x in ${!pname[@]}; do for x in ${!pname[@]}; do
if canping "${pdev[$x]}"; then if canping ${pdev[$x]}; then
thisform="$HFORMAT" thisform="$HFORMAT"
str="At home" str="At home"
else else
@ -1742,7 +1847,7 @@ elif [[ $showwho -eq 2 ]]; then
echo echo
printf "$TFORMAT" "Devices" "Availability" printf "$TFORMAT" "Devices" "Availability"
for x in $alldevs; do for x in $alldevs; do
if canping "${x}"; then if canping ${x}; then
thisform="$HFORMAT" thisform="$HFORMAT"
str="Available" str="Available"
else else
@ -1756,9 +1861,6 @@ elif [[ $showwho -eq 2 ]]; then
fi fi
get_aircon_info
if [[ $logmode -eq 1 ]]; then if [[ $logmode -eq 1 ]]; then
now=$(date +'%d/%m/%Y %H:%M:%S') now=$(date +'%d/%m/%Y %H:%M:%S')
if [[ ! -e $csvfile ]]; then if [[ ! -e $csvfile ]]; then
@ -1786,7 +1888,7 @@ elif [[ $logmode -eq 2 ]]; then
done done
for x in ${!pname[@]}; do for x in ${!pname[@]}; do
canping "${pdev[$x]}" && ishome=1 || ishome=0 canping ${pdev[$x]} && ishome=1 || ishome=0
influx_insert "INSERT attendance,person=${pname[$x]} value=$ishome" influx_insert "INSERT attendance,person=${pname[$x]} value=$ishome"
done done
[[ $airconmode == "off" ]] && pw=0 || pw=1 [[ $airconmode == "off" ]] && pw=0 || pw=1

BIN
aircon_grafana.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 193 KiB

2
b.html Normal file
View File

@ -0,0 +1,2 @@
<s>striked<s>still striked</s><br>
what about now