diff --git a/CHANGELOG.md b/CHANGELOG.md index cae4811..acedef9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,9 @@ # 0.6.4 - xx/xx/2021 -- Add support for sensor mi flora +- Add support for sensor: moisture, temperature, fertility, illuminance - Add command line: sensor_status, sensor_status_all, sensor_status_set - Add api command: sensor_status_set +- Add event ev_not_open_for_moisture, sensor_set_state_before, sensor_set_state_after +- Added zone humidity management: when a zone has reached the humidity defined in EVx_SENSOR_MOISTURE it does not start irrigation or interrupts it if it is already active. In case of rain it does not stop irrigation if the soil humidity has not reached the configured value # 0.6.3 - 10/08/2021 - Add command last_rain_sensor_timestamp, last_rain_online_timestamp, reset_last_rain_sensor_timestamp, reset_last_rain_online_timestamp diff --git a/include/rain.include.sh b/include/rain.include.sh index 24a83e3..9fd1d9e 100644 --- a/include/rain.include.sh +++ b/include/rain.include.sh @@ -75,11 +75,32 @@ function check_rain_sensor { } # -# Chiude tutte le elettrovalvole se sta piovendo +# Chiude tutte le elettrovalvole se sta piovendo oppure chiude quelle che hanno raggiunto l'mudità massima impostata # Eseguie il controllo in tempo reale sul sensore hardware e sui dati dell'ultima chiamata eseguita online # function close_all_for_rain { + # + # Chiude le elettrovalvole che hanno raggiunto l'umidità del terreno impostata in EVx_SENSOR_MOISTURE + # + + for i in $(seq $EV_TOTAL) + do + local a=EV"$i"_ALIAS + local al=${!a} + ev_status $al + local state=$? + local moisture=$(ev_check_moisture $i) + if [ "$state" = "1" ] && [ "$moisture" -gt 0 ]; then + ev_close $al + log_write "irrigate" "warning" "close_all_for_rain - Close solenoid '$al' because maximum soil moisture has been reached" + fi + done + + # + # Chiude le elettrovalvole in caso di pioggia + # + local close_all=0 local now=`date +%s` @@ -102,6 +123,12 @@ function close_all_for_rain { fi if [ "$close_all" = "1" ]; then + + # + # PIOVE + # Valuta se la sciare aperte le elettrovalvole in caso l'umidità del sensore non sia stata raggiunta + # + for i in $(seq $EV_TOTAL) do local a=EV"$i"_ALIAS @@ -110,14 +137,17 @@ function close_all_for_rain { local evnorain=${!a} ev_status $al local state=$? + local moisture=$(ev_check_moisture $i) #echo "$al = $state" - if [ "$state" = "1" ] && [ "$evnorain" != "1" ]; then + if [ "$state" = "1" ] && [ "$evnorain" != "1" ] && [ "$moisture" -ne 0 ]; then ev_close $al log_write "irrigate" "warning" "close_all_for_rain - Close solenoid '$al' for rain" fi done + fi + } # diff --git a/include/sensor.include.sh b/include/sensor.include.sh index be5792e..c5111ca 100644 --- a/include/sensor.include.sh +++ b/include/sensor.include.sh @@ -5,7 +5,9 @@ # $3 stato da scrivere # function sensor_set_state { + trigger_event "sensor_set_state_before" $1 $2 $3 echo "$3" > "$STATUS_DIR/sensor$1_$2" + trigger_event "sensor_set_state_after" $1 $2 $3 } # @@ -155,3 +157,42 @@ function json_sensor_status_all { js="\"sensor\": {$js_item}" echo $js } + +# +# Controlla se la zona comandata da un elettrovalvola ha raggiunto l'umidità necessaria per interrompere l'irrigazione +# Se è stata superata l'umidità indicata in EVx_SENSOR_MOISTURE ritorna l'umidità attuale del sensore relativo all'elettrovalvola +# in caso contrario ritorna 0, se no è impostato il parametro EV_xSENSOR_ALIAS o EVxSENSOR?MOISTURE ritorna il valore -1 +# +# $1 numero elettrovalvola da controllare +# +function ev_check_moisture { + + local s=EV"$1"_SENSOR_ALIAS + local sa=${!s} + + if [[ -z $sa ]]; then + echo -1 + return + fi + + local moisture=$(sensor_status $sa moisture) + + local s=EV"$1"_SENSOR_MOISTURE + local max_moisture=${!s} + + if [ -z $max_moisture ]; then + echo -1 + return + fi + + if [ $moisture -gt $max_moisture ]; then + log_write "sensor" "info" "humidity of the \"$sa\" sensor reached: $moisture%" + echo $moisture + return $moisture + fi + + echo 0 + return 0 +} + + diff --git a/piGarden.sh b/piGarden.sh index 8b75b52..2aa712f 100755 --- a/piGarden.sh +++ b/piGarden.sh @@ -88,35 +88,48 @@ function ev_open { local EV_IS_MONOSTABLE_VAR=EV"$EVNUM"_MONOSTABLE local EV_IS_MONOSTABLE=${!EV_IS_MONOSTABLE_VAR} - if [ ! "$2" = "force" ] && [ "$EVNORAIN" != "1" ]; then - if [[ "$NOT_IRRIGATE_IF_RAIN_ONLINE" -gt 0 && -f $STATUS_DIR/last_rain_online ]]; then - local last_rain=`cat $STATUS_DIR/last_rain_online` - local now=`date +%s` - local dif=0 - let "dif = now - last_rain" - if [ $dif -lt $NOT_IRRIGATE_IF_RAIN_ONLINE ]; then - message_write "warning" "Solenoid not open for rain" - trigger_event "ev_not_open_for_rain_online" "$1" - trigger_event "ev_not_open_for_rain" "$1" - log_write "irrigate" "warning" "Solenoid '$1' not open for rain (online check)" - return + if [ ! "$2" = "force" ]; then + + local moisture=$(ev_check_moisture $EVNUM) + if [ $moisture -gt 0 ]; then + message_write "warning" "solenoid not open because maximum soil moisture has been reached" + trigger_event "ev_not_open_for_moisture" "$1" + log_write "irrigate" "warning" "Solenoid '$1' not open because maximum soil moisture has been reached" + return + fi + + if [ "$EVNORAIN" != "1" ]; then + + if [[ "$NOT_IRRIGATE_IF_RAIN_ONLINE" -gt 0 && -f $STATUS_DIR/last_rain_online ]]; then + local last_rain=`cat $STATUS_DIR/last_rain_online` + local now=`date +%s` + local dif=0 + let "dif = now - last_rain" + if [ $dif -lt $NOT_IRRIGATE_IF_RAIN_ONLINE ] && [ $moisture -ne 0 ]; then + message_write "warning" "Solenoid not open for rain" + trigger_event "ev_not_open_for_rain_online" "$1" + trigger_event "ev_not_open_for_rain" "$1" + log_write "irrigate" "warning" "Solenoid '$1' not open for rain (online check)" + return + fi + fi + + check_rain_sensor + if [[ "$NOT_IRRIGATE_IF_RAIN_SENSOR" -gt 0 && -f $STATUS_DIR/last_rain_sensor && $moisture -ne 0 ]]; then + local last_rain=`cat $STATUS_DIR/last_rain_sensor` + local now=`date +%s` + local dif=0 + let "dif = now - last_rain" + if [ $dif -lt $NOT_IRRIGATE_IF_RAIN_SENSOR ]; then + message_write "warning" "Solenoid not open for rain" + trigger_event "ev_not_open_for_rain_sensor" "$1" + trigger_event "ev_not_open_for_rain" "$1" + log_write "irrigate" "warning" "Solenoid '$1' not open for rain (sensor check)" + return + fi fi fi - check_rain_sensor - if [[ "$NOT_IRRIGATE_IF_RAIN_SENSOR" -gt 0 && -f $STATUS_DIR/last_rain_sensor ]]; then - local last_rain=`cat $STATUS_DIR/last_rain_sensor` - local now=`date +%s` - local dif=0 - let "dif = now - last_rain" - if [ $dif -lt $NOT_IRRIGATE_IF_RAIN_SENSOR ]; then - message_write "warning" "Solenoid not open for rain" - trigger_event "ev_not_open_for_rain_sensor" "$1" - trigger_event "ev_not_open_for_rain" "$1" - log_write "irrigate" "warning" "Solenoid '$1' not open for rain (sensor check)" - return - fi - fi fi local state=1