Help scripting with rest/system/connections

I got rid off false positive connections (read unstable, spurious connected status) by tweaking my script this way (increased probes number to 4 and sleep in between to 17s - 17 instead of a multiple of 5 lowers the risks of regular sync between connections and probes), which gives enough time to the long ones among relay-client connections to drop or be replaced by higher rate and quicker failure-responsive new tcp-client ones. This seems the minimal tradeoff:

...
 # Counter for successive connections
while :; do echo `date +'%B %-d %T'` "AutoOff.sh (L24) enter wait for successive connections loop" &>>/var/log/syslog
 if [[ `$REST/system/connections|awk -v HID=$HomeID '$0~HID,/}/ {if ($0~/connected/) print}'|grep '"connected": true,'` ]]; then ((++CmptCntd)); echo `date +'%B %-d %T'` "AutoOff.sh (L25) ST connected. Increased counter by 1:" $CmptCntd &>>/var/log/syslog
    if [ $CmptCntd -ge 4 ]; then echo `date +'%B %-d %T'` "AutoOff.sh (L26) ST connected threshold reached:" $CmptCntd ": so break" &>>/var/log/syslog; break 1
    fi; echo `date +'%B %-d %T'` "AutoOff.sh (L27) ST was sense connected for only (current count):" $CmptCntd " time. Sleep17 and continue" &>>/var/log/syslog; sleep 17; continue 1
 fi; echo `date +'%B %-d %T'` "AutoOff.sh (L28) Test connected failed. Counter:" $CmptCntd  &>>/var/log/syslog; CmptCntd=0; echo `date +'%B %-d %T'` "AutoOff.sh (L28) counter was reset to:" $CmptCntd ". I will sleep15" &>>/var/log/syslog; sleep 15
done
echo `date +'%B %-d %T'` "AutoOff.sh (L30) exited loop" &>>/var/log/syslog
...