add 'nomyzone' config option to prevent a zone from ever becoming the "myzone".
This commit is contained in:
parent
407af3f3e6
commit
6ff51f038e
72
aircon.sh
72
aircon.sh
|
@ -1,6 +1,6 @@
|
|||
#!/bin/bash
|
||||
#!/bin/bash
|
||||
|
||||
# TODO: comparison to previous reading
|
||||
# TODO: comparison to previous reading
|
||||
# TODO: gnuplot of given time range
|
||||
# TODO: ditch pymyair
|
||||
# TODO: manual controls
|
||||
|
@ -84,7 +84,7 @@ function get_midrange() { # outputs midpoint of temperature range for given zon
|
|||
local min max
|
||||
min=${zwantmin[$idx]}
|
||||
max=${zwantmax[$idx]}
|
||||
echo "($min + $max) / 2" | bc
|
||||
echo "($min + $max) / 2" | bc
|
||||
}
|
||||
|
||||
function getoppositestate() {
|
||||
|
@ -342,7 +342,7 @@ function generate_actions() { # populates global: nairconcommands & airconcmd
|
|||
zaction[$x]="power_off"
|
||||
if [[ -z $powerchange ]]; then
|
||||
powerchange="power_off"
|
||||
elif [[ ${zaction[$x]} != $powerchange ]]; then
|
||||
elif [[ ${zaction[$x]} != $powerchange ]]; then
|
||||
zactionfail[$x]=1
|
||||
fi
|
||||
else
|
||||
|
@ -385,7 +385,7 @@ function generate_actions() { # populates global: nairconcommands & airconcmd
|
|||
fi
|
||||
fi
|
||||
[[ ! -z $globsetmode ]] && globaction="power_on"
|
||||
else
|
||||
else
|
||||
if [[ $airconmode == "heat" && $nhot -ge 2 ]]; then
|
||||
globprob="too_hot"
|
||||
elif [[ $airconmode == "cool" && $ncold -ge 2 ]]; then
|
||||
|
@ -432,40 +432,48 @@ function generate_actions() { # populates global: nairconcommands & airconcmd
|
|||
if [[ -z $powerchange ]]; then
|
||||
if [[ $airconmode != "off" ]]; then
|
||||
mzmustmove=0
|
||||
# get list of all zones which can't be myzone
|
||||
nomyzone=""
|
||||
for x in ${!zname[@]}; do
|
||||
if [[ ${znomyzone[$x]} -eq 1 ]]; then
|
||||
nomyzone="$nomyzone ${zname[$x]} "
|
||||
fi
|
||||
done
|
||||
for x in ${!zname[@]}; do
|
||||
if [[ $airconmyzoneid == ${zid[$x]} || ${zaction[$x]} == *set_myzone* ]]; then
|
||||
if [[ ${zstate[$x]} == "close" || ${zaction[$x]} == *close_vent* ]]; then
|
||||
mzmustmove=1
|
||||
elif [[ ${zaction[@]} == *close:${zname[$x]}* ]]; then
|
||||
mzmustmove=1
|
||||
elif [[ ${znomyzone[$x]} -eq 1 ]]; then
|
||||
mzmustmove=1
|
||||
fi
|
||||
if [[ $mzmustmove -eq 1 ]]; then
|
||||
[[ $db -eq 1 ]] && info "myzone must move away from ${zname[$x]}"
|
||||
[[ $db -eq 1 ]] && info "myzone must move away from ${zname[$x]}"
|
||||
#info "myzone must move away from ${zname[$x]}"
|
||||
zaction[$x]="${zaction[$x]/set_myzone/}"
|
||||
nomyzone="$nomyzone ${zname[$x]} "
|
||||
[[ $db -eq 1 ]] && info "zaction[${zname[$z]} is '${zaction[$x]}'"
|
||||
[[ $db -eq 1 ]] && info "nomyzone is '$nomyzone}'"
|
||||
[[ $db -eq 1 ]] && info "zaction[${zname[$z]} is '${zaction[$x]}'"
|
||||
[[ $db -eq 1 ]] && info "nomyzone is '$nomyzone}'"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
if [[ $mzmustmove -eq 1 ]]; then
|
||||
[[ $db -eq 1 ]] && info "got mzmustmove == 1"
|
||||
[[ $db -eq 1 ]] && info "FINAL nomyzone is '$nomyzone}'"
|
||||
[[ $db -eq 1 ]] && info "got mzmustmove == 1"
|
||||
[[ $db -eq 1 ]] && info "FINAL nomyzone is '$nomyzone}'"
|
||||
# find an alternative
|
||||
for x in ${!zname[@]}; do
|
||||
# open or opening? set myzone. we'll resolve
|
||||
# duplicates in the next step.
|
||||
[[ $db -eq 1 ]] && info " checking if we can move mz to ${zname[$x]}"
|
||||
[[ $db -eq 1 ]] && info " checking if we can move mz to ${zname[$x]}"
|
||||
poss=0
|
||||
if [[ ${zaction[$x]} != *set_myzone* && $nomyzone != *\ ${zname[$x]}\ * ]]; then
|
||||
[[ $db -eq 1 ]] && info " not already moving mz here + not in nomyzone list"
|
||||
[[ $db -eq 1 ]] && info " not already moving mz here + not in nomyzone list"
|
||||
if [[ ${zstate[$x]} == "open" || ${zaction[$x]} == *open_vent* ]]; then
|
||||
[[ $db -eq 1 ]] && info " is open or opening -> OK"
|
||||
[[ $db -eq 1 ]] && info " is open or opening -> OK"
|
||||
poss=1
|
||||
elif [[ ${zaction[@]} == *open:${zname[$x]}* ]]; then
|
||||
[[ $db -eq 1 ]] && info " is opening via adjacency-> OK"
|
||||
[[ $db -eq 1 ]] && info " is opening via adjacency-> OK"
|
||||
poss=1
|
||||
fi
|
||||
if [[ $poss -eq 1 ]]; then
|
||||
|
@ -525,7 +533,7 @@ function generate_actions() { # populates global: nairconcommands & airconcmd
|
|||
|
||||
|
||||
# gen_aircon_command zone_idx "command1 command2 etc"
|
||||
function gen_aircon_command() {
|
||||
function gen_aircon_command() {
|
||||
local idx allactions this toadd num doneset othername otherid otheridx db donemode str
|
||||
idx=$1
|
||||
shift
|
||||
|
@ -633,6 +641,13 @@ function addnoop() {
|
|||
zignore[$idx]=1
|
||||
}
|
||||
|
||||
|
||||
function addnomyzone() {
|
||||
local idx
|
||||
idx=$(getidxfromname "$1")
|
||||
znomyzone[$idx]=1
|
||||
}
|
||||
|
||||
function addforcevent() {
|
||||
local x idx
|
||||
idx=$nforcevents
|
||||
|
@ -798,7 +813,7 @@ function conderror() {
|
|||
echo -e "${RED} Start: $2"
|
||||
echo -e "${RED} End: $3"
|
||||
}
|
||||
|
||||
|
||||
function load_config() {
|
||||
local line rv timestr ttok stype ok starth endh nowh
|
||||
local cond allconds x
|
||||
|
@ -905,8 +920,10 @@ function load_config() {
|
|||
fi
|
||||
elif [[ ${tok[0]} == "adj" ]]; then
|
||||
addadj ${tok[1]} ${tok[@]:2}
|
||||
elif [[ ${tok[0]} == "nomyzone" || ${tok[0]} == "nomy" ]]; then
|
||||
addnnomyzone ${tok[1]}
|
||||
elif [[ ${tok[0]} == "noop" || ${tok[0]} == "ignore" ]]; then
|
||||
addnoop ${tok[1]}
|
||||
addnoop ${tok[1]}
|
||||
elif [[ ${tok[0]} == "force" ]]; then
|
||||
if [[ $VALID_ZONE_STATES == *\ ${tok[2]}\ * ]]; then
|
||||
addforcevent ${tok[1]} ${tok[2]}
|
||||
|
@ -945,7 +962,7 @@ function canping() {
|
|||
ip=${ip%% *}
|
||||
if [[ -z $ip ]]; then
|
||||
thisrv=1
|
||||
else
|
||||
else
|
||||
#arp -d $ip >/dev/null 2>&1
|
||||
#ping -c1 -w1 -n -q $ip >/dev/null 2>&1 &
|
||||
#sleep 0.3
|
||||
|
@ -981,6 +998,7 @@ function addzone() {
|
|||
zownerperson[$nzones]=$(getownerperson "$name")
|
||||
#info "zone $name owner is [${zowner[$nzones]}]"
|
||||
zignore[$nzones]=0
|
||||
znomyzone[$nzones]=0
|
||||
zpri[$nzones]=0
|
||||
wanttemp=$(gettemprange "$name")
|
||||
if [[ $wanttemp == "n/a" ]]; then
|
||||
|
@ -992,13 +1010,13 @@ function addzone() {
|
|||
zwantmin[$nzones]="${wanttemp%-*}"
|
||||
zwantmax[$nzones]="${wanttemp#*-}"
|
||||
fi
|
||||
|
||||
|
||||
nzones=$((nzones + 1))
|
||||
}
|
||||
|
||||
function getcol() {
|
||||
local col
|
||||
case $1 in
|
||||
case $1 in
|
||||
"off") col="$GREY";;
|
||||
"cool") col="$CYAN";;
|
||||
"heat") col="$RED";;
|
||||
|
@ -1045,7 +1063,7 @@ function gen_config() {
|
|||
echo "# @hhmm-hhmm Restrict between certain 24 hour times" >> $CONFIGFILE
|
||||
echo "# @Mon-Wed Restrict between certain weekdays" >> $CONFIGFILE
|
||||
echo "# @Mon Restrict to one weekdays only" >> $CONFIGFILE
|
||||
|
||||
|
||||
echo "# @Mon;hhmm-hhmm Restrict both day and time" >> $CONFIGFILE
|
||||
echo "# For example:" >> $CONFIGFILE
|
||||
echo "# Keep zone closed on Tuesdays and Wednesdays" >> $CONFIGFILE
|
||||
|
@ -1210,7 +1228,7 @@ function show_proposed_commands() {
|
|||
count=0
|
||||
for x in ${!airconcmd[@]}; do
|
||||
fullcmd="myair $AIRCON_IP ${airconcmd[$x]}"
|
||||
printf -- "$cmdformat" "$fullcmd"
|
||||
printf -- "$cmdformat" "$fullcmd"
|
||||
[[ ! -z ${airconcomment[$x]} ]] && printf " $GREEN$BOLD# $PLAIN$GREEN%s$PLAIN\n" "${airconcomment[$x]}" || echo
|
||||
count=$((count + 1))
|
||||
done
|
||||
|
@ -1221,7 +1239,7 @@ function run_commands() {
|
|||
local x
|
||||
for x in ${!airconcmd[@]}; do
|
||||
[[ ! -z ${airconcomment[$x]} ]] && action "${airconcomment[$x]}"
|
||||
echo RUNNING myair $AIRCON_IP ${airconcmd[$x]}
|
||||
echo RUNNING myair $AIRCON_IP ${airconcmd[$x]}
|
||||
myair $AIRCON_IP ${airconcmd[$x]} >/dev/null 2>&1
|
||||
influx_insert "INSERT aircon action=\"${airconcomment[$x]}\",comment=\"${airconproblem[$x]}\""
|
||||
done
|
||||
|
@ -1278,7 +1296,7 @@ function influx_insert() { # $1 == cmd
|
|||
function influx_init() { # $1 == dbname
|
||||
local dbfound
|
||||
influx=$(which influx 2>/dev/null)
|
||||
influxdb="$1"
|
||||
influxdb="$1"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
error "influx executable not found in path."
|
||||
return 1
|
||||
|
@ -1435,7 +1453,7 @@ fi
|
|||
|
||||
if [[ -e $CONFIGFILE ]]; then
|
||||
if ! load_config; then
|
||||
error "Config load failed"
|
||||
error "Config load failed"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
|
@ -1463,7 +1481,7 @@ if [[ $showwho -eq 1 ]]; then
|
|||
printf "$TFORMAT" "Person" "Availability"
|
||||
for x in ${!pname[@]}; do
|
||||
if canping "${pdev[$x]}"; then
|
||||
thisform="$HFORMAT"
|
||||
thisform="$HFORMAT"
|
||||
str="At home"
|
||||
else
|
||||
thisform="$AFORMAT"
|
||||
|
@ -1497,7 +1515,7 @@ if [[ $logmode -eq 1 ]]; then
|
|||
exit 0
|
||||
elif [[ $logmode -eq 2 ]]; then
|
||||
now=$(date +'%d/%m/%Y %H:%M:%S')
|
||||
|
||||
|
||||
rv=0
|
||||
failedcmds=""
|
||||
influx_clear
|
||||
|
|
Loading…
Reference in New Issue