Add support for sensor: moisture, temperature, fertility, illuminance. 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.

This commit is contained in:
lejubila
2021-08-27 22:52:01 +02:00
parent c91128cbb4
commit 2001b09937
4 changed files with 115 additions and 29 deletions

View File

@@ -1,7 +1,9 @@
# 0.6.4 - xx/xx/2021 # 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 command line: sensor_status, sensor_status_all, sensor_status_set
- Add api command: 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 # 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 - Add command last_rain_sensor_timestamp, last_rain_online_timestamp, reset_last_rain_sensor_timestamp, reset_last_rain_online_timestamp

View File

@@ -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 # Eseguie il controllo in tempo reale sul sensore hardware e sui dati dell'ultima chiamata eseguita online
# #
function close_all_for_rain { 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 close_all=0
local now=`date +%s` local now=`date +%s`
@@ -102,6 +123,12 @@ function close_all_for_rain {
fi fi
if [ "$close_all" = "1" ]; then 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) for i in $(seq $EV_TOTAL)
do do
local a=EV"$i"_ALIAS local a=EV"$i"_ALIAS
@@ -110,14 +137,17 @@ function close_all_for_rain {
local evnorain=${!a} local evnorain=${!a}
ev_status $al ev_status $al
local state=$? local state=$?
local moisture=$(ev_check_moisture $i)
#echo "$al = $state" #echo "$al = $state"
if [ "$state" = "1" ] && [ "$evnorain" != "1" ]; then if [ "$state" = "1" ] && [ "$evnorain" != "1" ] && [ "$moisture" -ne 0 ]; then
ev_close $al ev_close $al
log_write "irrigate" "warning" "close_all_for_rain - Close solenoid '$al' for rain" log_write "irrigate" "warning" "close_all_for_rain - Close solenoid '$al' for rain"
fi fi
done done
fi fi
} }
# #

View File

@@ -5,7 +5,9 @@
# $3 stato da scrivere # $3 stato da scrivere
# #
function sensor_set_state { function sensor_set_state {
trigger_event "sensor_set_state_before" $1 $2 $3
echo "$3" > "$STATUS_DIR/sensor$1_$2" 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}" js="\"sensor\": {$js_item}"
echo $js 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
}

View File

@@ -88,35 +88,48 @@ function ev_open {
local EV_IS_MONOSTABLE_VAR=EV"$EVNUM"_MONOSTABLE local EV_IS_MONOSTABLE_VAR=EV"$EVNUM"_MONOSTABLE
local EV_IS_MONOSTABLE=${!EV_IS_MONOSTABLE_VAR} local EV_IS_MONOSTABLE=${!EV_IS_MONOSTABLE_VAR}
if [ ! "$2" = "force" ] && [ "$EVNORAIN" != "1" ]; then if [ ! "$2" = "force" ]; 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 moisture=$(ev_check_moisture $EVNUM)
local now=`date +%s` if [ $moisture -gt 0 ]; then
local dif=0 message_write "warning" "solenoid not open because maximum soil moisture has been reached"
let "dif = now - last_rain" trigger_event "ev_not_open_for_moisture" "$1"
if [ $dif -lt $NOT_IRRIGATE_IF_RAIN_ONLINE ]; then log_write "irrigate" "warning" "Solenoid '$1' not open because maximum soil moisture has been reached"
message_write "warning" "Solenoid not open for rain" return
trigger_event "ev_not_open_for_rain_online" "$1" fi
trigger_event "ev_not_open_for_rain" "$1"
log_write "irrigate" "warning" "Solenoid '$1' not open for rain (online check)" if [ "$EVNORAIN" != "1" ]; then
return
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
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 fi
local state=1 local state=1