Compare commits
7 Commits
v0.6.2
...
10045d5a11
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
10045d5a11 | ||
|
|
3d0d36077d | ||
|
|
a30e1cb6ef | ||
|
|
81ce03e90a | ||
|
|
2001b09937 | ||
|
|
c91128cbb4 | ||
|
|
7242b1c2ab |
14
CHANGELOG.md
14
CHANGELOG.md
@@ -1,3 +1,17 @@
|
||||
# 0.6.4 - 03/10/2021
|
||||
- Fix path of url weather icons
|
||||
|
||||
# 0.6.4 - 03/10/2021
|
||||
- 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
|
||||
- Add socket server api for reset_last_rain_sensor_timestamp, reset_last_rain_online_timestamp
|
||||
|
||||
# 0.6.2 - 24/04/2021
|
||||
- Update rainsensorqty driver to version 0.2.5c
|
||||
|
||||
|
||||
@@ -107,6 +107,9 @@ EV1_ALIAS="1" #
|
||||
EV1_GPIO=17 # Physical 11 - wPi 0
|
||||
#EV1_NORAIN=1 # Non interrompe l'irrigazione di questa zona in caso di pioggia
|
||||
#EV1_MONOSTABLE=1 # L'elettrovalvola è monostabile
|
||||
#EV1_SENSOR_ALIAS=Mi_Flora # Nome del sensore (definito in SENSORx_ALIAS) per stabilire l'umidità del terreno
|
||||
#EV1_SENSOR_MOISTURE=50 # Percentule di umidità ottimale
|
||||
#EV1_SENSOR_MOISTURE_AUTOCLOSE=1 # Chiude automaticamente l'elettrovalvola quando supera l'umidità impostata in EVx_MONOSTABLE
|
||||
|
||||
EV2_ALIAS="2" #
|
||||
EV2_GPIO=27 # Physical 13 - wPi 2
|
||||
@@ -124,6 +127,16 @@ EV6_ALIAS="6" #
|
||||
EV6_GPIO=24 # Physical 18 - wPi 5
|
||||
|
||||
|
||||
|
||||
# Numero di sensori
|
||||
SENSOR_TOTAL=1
|
||||
|
||||
# Definizione sensori
|
||||
SENSOR1_ALIAS=Mi_Flora
|
||||
|
||||
|
||||
|
||||
|
||||
# Definisci il servizio online da utilizzare per il controllo delle condizioni meteo, puoi scegliere openweathermap oppure wunderground.
|
||||
# Se non vuoi configurare nessun servizio imposta il vale "none"
|
||||
WEATHER_SERVICE="openweathermap"
|
||||
|
||||
@@ -91,24 +91,24 @@ function drv_openweathermap_get_ico {
|
||||
|
||||
declare -A w
|
||||
|
||||
w["01d"]="http://icons.wxug.com/i/c/k/clear.gif"
|
||||
w["01n"]="http://icons.wxug.com/i/c/k/nt_clear.gif"
|
||||
w["02d"]="http://icons.wxug.com/i/c/k/partlycloudy.gif"
|
||||
w["02n"]="http://icons.wxug.com/i/c/k/nt_partlycloudy.gif"
|
||||
w["03d"]="http://icons.wxug.com/i/c/k/cloudy.gif"
|
||||
w["03n"]="http://icons.wxug.com/i/c/k/nt_cloudy.gif"
|
||||
w["04d"]="http://icons.wxug.com/i/c/k/cloudy.gif"
|
||||
w["04n"]="http://icons.wxug.com/i/c/k/nt_cloudy.gif"
|
||||
w["09d"]="http://icons.wxug.com/i/c/k/sleet.gif"
|
||||
w["09n"]="http://icons.wxug.com/i/c/k/nt_sleet.gif"
|
||||
w["10d"]="http://icons.wxug.com/i/c/k/rain.gif"
|
||||
w["10n"]="http://icons.wxug.com/i/c/k/nt_rain.gif"
|
||||
w["11d"]="http://icons.wxug.com/i/c/k/tstorms.gif"
|
||||
w["11n"]="http://icons.wxug.com/i/c/k/nt_tstorms.gif"
|
||||
w["13d"]="http://icons.wxug.com/i/c/k/snow.gif"
|
||||
w["13n"]="http://icons.wxug.com/i/c/k/nt_snow.gif"
|
||||
w["50d"]="http://icons.wxug.com/i/c/k/fog.gif"
|
||||
w["50n"]="http://icons.wxug.com/i/c/k/nt_fog.gif"
|
||||
w["01d"]="http://www.wunderground.com/static/i/c/k/clear.gif"
|
||||
w["01n"]="http://www.wunderground.com/static/i/c/k/nt_clear.gif"
|
||||
w["02d"]="http://www.wunderground.com/static/i/c/k/partlycloudy.gif"
|
||||
w["02n"]="http://www.wunderground.com/static/i/c/k/nt_partlycloudy.gif"
|
||||
w["03d"]="http://www.wunderground.com/static/i/c/k/cloudy.gif"
|
||||
w["03n"]="http://www.wunderground.com/static/i/c/k/nt_cloudy.gif"
|
||||
w["04d"]="http://www.wunderground.com/static/i/c/k/cloudy.gif"
|
||||
w["04n"]="http://www.wunderground.com/static/i/c/k/nt_cloudy.gif"
|
||||
w["09d"]="http://www.wunderground.com/static/i/c/k/sleet.gif"
|
||||
w["09n"]="http://www.wunderground.com/static/i/c/k/nt_sleet.gif"
|
||||
w["10d"]="http://www.wunderground.com/static/i/c/k/rain.gif"
|
||||
w["10n"]="http://www.wunderground.com/static/i/c/k/nt_rain.gif"
|
||||
w["11d"]="http://www.wunderground.com/static/i/c/k/tstorms.gif"
|
||||
w["11n"]="http://www.wunderground.com/static/i/c/k/nt_tstorms.gif"
|
||||
w["13d"]="http://www.wunderground.com/static/i/c/k/snow.gif"
|
||||
w["13n"]="http://www.wunderground.com/static/i/c/k/nt_snow.gif"
|
||||
w["50d"]="http://www.wunderground.com/static/i/c/k/fog.gif"
|
||||
w["50n"]="http://www.wunderground.com/static/i/c/k/nt_fog.gif"
|
||||
|
||||
local ico=${w[$1]}
|
||||
|
||||
|
||||
@@ -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_autoclose $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,51 @@ 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
|
||||
|
||||
|
||||
}
|
||||
|
||||
#
|
||||
# Mostra il timestamp dell'ultima pioggia rilevato dal sensore
|
||||
#
|
||||
function last_rain_sensor_timestamp {
|
||||
cat "$STATUS_DIR/last_rain_sensor" 2> /dev/null
|
||||
}
|
||||
|
||||
#
|
||||
# Mostra il timestamp dell'ultima pioggia rilevato dal servizio online
|
||||
#
|
||||
function last_rain_online_timestamp {
|
||||
cat "$STATUS_DIR/last_rain_online" 2> /dev/null
|
||||
}
|
||||
|
||||
#
|
||||
# Resetta il timestamp dell'ultima pioggia rilevato dal sensore
|
||||
#
|
||||
function reset_last_rain_sensor_timestamp {
|
||||
trigger_event "reset_last_rain_sensor_timestamp_before" ""
|
||||
rm "$STATUS_DIR/last_rain_sensor" 2> /dev/null
|
||||
trigger_event "reset_last_rain_sensor_timestamp_after" ""
|
||||
log_write "rain" "info" "reset_last_rain_sensor_timestamp"
|
||||
}
|
||||
|
||||
#
|
||||
# Resetta mostra il timestamp dell'ultima pioggia rilevato dal servizio online
|
||||
#
|
||||
function reset_last_rain_online_timestamp {
|
||||
trigger_event "reset_last_rain_online_timestamp_before" ""
|
||||
rm "$STATUS_DIR/last_rain_online" 2> /dev/null
|
||||
trigger_event "reset_last_rain_online_timestamp_before" ""
|
||||
log_write "rain" "info" "reset_last_rain_online_timestamp"
|
||||
}
|
||||
|
||||
|
||||
|
||||
249
include/sensor.include.sh
Normal file
249
include/sensor.include.sh
Normal file
@@ -0,0 +1,249 @@
|
||||
#
|
||||
# Imposta lo stato di una elettrovalvola
|
||||
# $1 numero del sensore
|
||||
# $2 tipologia dello stato
|
||||
# $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
|
||||
}
|
||||
|
||||
#
|
||||
# Legge lo stato di un sensore
|
||||
# $1 numero del sensore
|
||||
# $2 tipologia dello stato
|
||||
#
|
||||
function sensor_get_state {
|
||||
if [ ! -f "$STATUS_DIR/sensor$1_$2" ]; then
|
||||
sensor_set_state $1 $2 ""
|
||||
fi
|
||||
|
||||
local state=$(cat "$STATUS_DIR/sensor$1_$2" 2> /dev/null)
|
||||
echo $state
|
||||
}
|
||||
|
||||
#
|
||||
# Recupera il numero di un sensore in base all'alias
|
||||
# $1 alias del sensore
|
||||
#
|
||||
function sensor_alias2number {
|
||||
for i in $(seq $EV_TOTAL)
|
||||
do
|
||||
a=SENSOR"$i"_ALIAS
|
||||
av=${!a}
|
||||
if [ "$av" == "$1" ]; then
|
||||
return $i
|
||||
fi
|
||||
done
|
||||
|
||||
log_write "general" "error" "ERROR sensor alias not found: $1"
|
||||
message_write "warning" "Sensor alias not found"
|
||||
mqtt_status
|
||||
exit 1
|
||||
}
|
||||
|
||||
#
|
||||
# Verifica se un alias di un sensore esiste
|
||||
# $1 alias dell'elettrovalvola
|
||||
#
|
||||
function sensor_alias_exists {
|
||||
local vret='FALSE'
|
||||
for i in $(seq $EV_TOTAL)
|
||||
do
|
||||
a=SENSOR"$i"_ALIAS
|
||||
av=${!a}
|
||||
if [ "$av" == "$1" ]; then
|
||||
vret='TRUE'
|
||||
fi
|
||||
done
|
||||
|
||||
echo $vret
|
||||
}
|
||||
|
||||
#
|
||||
# Mostra lo stato di tutte le elettrovalvole
|
||||
#
|
||||
function sensor_status_all {
|
||||
for i in $(seq $SENSOR_TOTAL)
|
||||
do
|
||||
a=SENSOR"$i"_ALIAS
|
||||
av=${!a}
|
||||
for t in $SENSOR_STATE_TYPE
|
||||
do
|
||||
local state=$(sensor_get_state $i $t)
|
||||
echo -e "$av: $t $state"
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
#
|
||||
# Mostra lo stato di un sensore
|
||||
# $1 alias sensore
|
||||
# $2 tipologia dello stato
|
||||
#
|
||||
function sensor_status {
|
||||
sensor_alias2number $1
|
||||
i=$?
|
||||
if [ -z "$2" ]; then
|
||||
for t in $SENSOR_STATE_TYPE
|
||||
do
|
||||
local state=$(sensor_get_state $i $t)
|
||||
echo -e "$av: $t $state"
|
||||
done
|
||||
else
|
||||
local state=$(sensor_get_state $i $2)
|
||||
echo -e "$state"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
#
|
||||
# Imposta lo stato di un sensore per alias
|
||||
# $1 alias sensore
|
||||
# $2 tipologia dello stato
|
||||
# $3 stato da imopostare
|
||||
#
|
||||
function sensor_status_set {
|
||||
sensor_alias2number $1
|
||||
i=$?
|
||||
sensor_set_state $i $2 $3
|
||||
mqtt_status
|
||||
}
|
||||
|
||||
#
|
||||
# Stampa la lista degli alias dei sensori
|
||||
#
|
||||
function list_alias_sensor {
|
||||
|
||||
for i in $(seq $SENSOR_TOTAL)
|
||||
do
|
||||
local a=SENSOR"$i"_ALIAS
|
||||
local al=${!a}
|
||||
echo $al
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
#
|
||||
# Stampa lo stato di tutti i sensori in formato json
|
||||
#
|
||||
function json_sensor_status_all {
|
||||
local js=""
|
||||
local js_item=""
|
||||
local js_type=""
|
||||
|
||||
for i in $(seq $SENSOR_TOTAL)
|
||||
do
|
||||
a=SENSOR"$i"_ALIAS
|
||||
av=${!a}
|
||||
|
||||
js_type=""
|
||||
for t in $SENSOR_STATE_TYPE
|
||||
do
|
||||
local state=$(sensor_get_state $i $t)
|
||||
js_type="$js_type \"$t\": \"$state\", "
|
||||
done
|
||||
js_type="${js_type::-2}"
|
||||
js_item="$js_item \"$av\":{$js_type}, ";
|
||||
done
|
||||
|
||||
if [[ ! -z $js_item ]]; then
|
||||
js_item="${js_item::-2}"
|
||||
fi
|
||||
|
||||
js="\"sensor\": {$js_item}"
|
||||
echo $js
|
||||
}
|
||||
|
||||
#
|
||||
# Controlla se la zona comandata da un elettrovalvola ha raggiunto l'umidità necessaria per non fare partire l'irrigazione,
|
||||
# faerla chiudere in caso di pioggia.
|
||||
# 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" "ev_check_moisture_autoclose: humidity of the \"$sa\" sensor reached: $moisture%"
|
||||
echo $moisture
|
||||
return $moisture
|
||||
fi
|
||||
|
||||
echo 0
|
||||
return 0
|
||||
}
|
||||
|
||||
#
|
||||
# Controlla se la zona comandata da un elettrovalvola ha raggiunto l'umidità necessaria per essere chiusa in automatico
|
||||
# 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, EVxSENSOR_MOISTURE o
|
||||
# EVxSENSOR_MOISTURE_AUTOCLOSE ritorna il valore -1
|
||||
#
|
||||
# $1 numero elettrovalvola da controllare
|
||||
#
|
||||
function ev_check_moisture_autoclose {
|
||||
|
||||
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
|
||||
|
||||
local s=EV"$1"_SENSOR_MOISTURE_AUTOCLOSE
|
||||
local autoclose=${!s}
|
||||
|
||||
if [ -z $autoclose ]; then
|
||||
echo -1
|
||||
return
|
||||
fi
|
||||
|
||||
if [ $autoclose -ne 1 ]; then
|
||||
echo -1
|
||||
return
|
||||
fi
|
||||
|
||||
if [ $moisture -gt $max_moisture ]; then
|
||||
log_write "sensor" "info" "ev_check_moisture_autoclose: humidity of the \"$sa\" sensor reached: $moisture%"
|
||||
echo $moisture
|
||||
return $moisture
|
||||
fi
|
||||
|
||||
echo 0
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
@@ -240,6 +240,27 @@ function socket_server_command {
|
||||
nohup $PATH_SCRIPT poweroff > /dev/null 2>&1 &
|
||||
;;
|
||||
|
||||
reset_last_rain_sensor_timestamp)
|
||||
reset_last_rain_sensor_timestamp
|
||||
message_write "success" "Timestamp of last sensor rain successfull reset"
|
||||
json_status
|
||||
;;
|
||||
|
||||
reset_last_rain_online_timestamp)
|
||||
reset_last_rain_online_timestamp
|
||||
message_write "success" "Timestamp of last online rain successfull reset"
|
||||
json_status
|
||||
;;
|
||||
|
||||
sensor_status_set)
|
||||
if [ "empty$arg2" == "empty" ]; then
|
||||
json_error 0 "Alias sensor not specified"
|
||||
else
|
||||
sensor_status_set $arg2 $arg3 $arg4 &> /dev/null
|
||||
json_status
|
||||
fi
|
||||
;;
|
||||
|
||||
*)
|
||||
json_error 0 "invalid command"
|
||||
;;
|
||||
|
||||
130
piGarden.sh
130
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
|
||||
@@ -684,8 +697,9 @@ function json_status {
|
||||
fi
|
||||
local json_cron_open_in="\"cron_open_in\":{$json_get_cron_open_in}"
|
||||
local json_timestamp="\"timestamp\": $(date +%s)"
|
||||
local json_sensor="$(json_sensor_status_all)"
|
||||
|
||||
json="{$json_version,$json_timestamp,$json_event,$json,$json_last_weather_online,$json_error,$json_last_info,$json_last_warning,$json_last_success,$json_last_rain_online,$json_last_rain_sensor,$json_cron,$json_cron_open_in $json_schedule}"
|
||||
json="{$json_version,$json_timestamp,$json_event,$json,$json_sensor,$json_last_weather_online,$json_error,$json_last_info,$json_last_warning,$json_last_success,$json_last_rain_online,$json_last_rain_sensor,$json_cron,$json_cron_open_in $json_schedule}"
|
||||
|
||||
echo "$json"
|
||||
|
||||
@@ -727,10 +741,25 @@ function show_usage {
|
||||
echo -e "\t$NAME_SCRIPT list_alias view list of aliases solenoid"
|
||||
echo -e "\t$NAME_SCRIPT ev_status alias show status solenoid"
|
||||
echo -e "\t$NAME_SCRIPT ev_status_all show status solenoids"
|
||||
|
||||
echo -e "\n"
|
||||
echo -e "\t$NAME_SCRIPT list_alias_sensor view list of aliases sensor"
|
||||
echo -e "\t$NAME_SCRIPT sensor_status alias [type] show status sensor (type: $SENSOR_STATE_TYPE)"
|
||||
echo -e "\t$NAME_SCRIPT sensor_status_set alias type value set status of sensor (type: $SENSOR_STATE_TYPE)"
|
||||
echo -e "\t$NAME_SCRIPT sensor_status_all show status of all sensors"
|
||||
|
||||
echo -e "\n"
|
||||
echo -e "\t$NAME_SCRIPT last_rain_sensor_timestamp show timestamp of last rain sensor"
|
||||
echo -e "\t$NAME_SCRIPT last_rain_online_timestamp show timestamp of last rain online"
|
||||
echo -e "\t$NAME_SCRIPT reset_last_rain_sensor_timestamp show timestamp of last rain sensor"
|
||||
echo -e "\t$NAME_SCRIPT reset_last_rain_online_timestamp show timestamp of last rain online"
|
||||
echo -e "\n"
|
||||
echo -e "\t$NAME_SCRIPT json_status [get_cron|get_cron_open_in|get_schedule] show status in json format"
|
||||
echo -e "\t$NAME_SCRIPT mqtt_status send status in json format to mqtt broker"
|
||||
echo -e "\t$NAME_SCRIPT check_rain_online check rain from http://api.wunderground.com/"
|
||||
echo -e "\n"
|
||||
echo -e "\t$NAME_SCRIPT check_rain_online check rain from online api service"
|
||||
echo -e "\t$NAME_SCRIPT check_rain_sensor check rain from hardware sensor"
|
||||
echo -e "\n"
|
||||
echo -e "\t$NAME_SCRIPT close_all_for_rain close all solenoid if it's raining"
|
||||
echo -e "\t$NAME_SCRIPT close_all [force] close all solenoid"
|
||||
echo -e "\n"
|
||||
@@ -1004,7 +1033,7 @@ function debug2 {
|
||||
|
||||
VERSION=0
|
||||
SUB_VERSION=6
|
||||
RELEASE_VERSION=2
|
||||
RELEASE_VERSION=5
|
||||
|
||||
DIR_SCRIPT=`dirname $0`
|
||||
NAME_SCRIPT=${0##*/}
|
||||
@@ -1030,6 +1059,7 @@ fi
|
||||
. "$DIR_SCRIPT/include/cron.include.sh"
|
||||
. "$DIR_SCRIPT/include/socket.include.sh"
|
||||
. "$DIR_SCRIPT/include/rain.include.sh"
|
||||
. "$DIR_SCRIPT/include/sensor.include.sh"
|
||||
. "$DIR_SCRIPT/include/events.include.sh"
|
||||
|
||||
MESSAGE_INFO=""
|
||||
@@ -1039,8 +1069,14 @@ MESSAGE_SUCCESS=""
|
||||
CURRENT_EVENT=""
|
||||
CURRENT_EVENT_ALIAS=""
|
||||
|
||||
SENSOR_STATE_TYPE="moisture temperature fertility illuminance"
|
||||
|
||||
PARENT_PID=0
|
||||
|
||||
if [ -z $SENSOR_TOTAL ]; then
|
||||
SENSOR_TOTAL=0
|
||||
fi
|
||||
|
||||
if [ -z $LOG_OUTPUT_DRV_FILE ]; then
|
||||
LOG_OUTPUT_DRV_FILE="/dev/null"
|
||||
fi
|
||||
@@ -1111,6 +1147,26 @@ case "$1" in
|
||||
ev_status_all
|
||||
;;
|
||||
|
||||
list_alias_sensor)
|
||||
list_alias_sensor
|
||||
;;
|
||||
|
||||
sensor_status)
|
||||
sensor_status $2 $3
|
||||
;;
|
||||
|
||||
sensor_status_all)
|
||||
sensor_status_all
|
||||
;;
|
||||
|
||||
sensor_status_set)
|
||||
sensor_status_set $2 $3 $4
|
||||
;;
|
||||
|
||||
json_sensor_status_all)
|
||||
json_sensor_status_all
|
||||
;;
|
||||
|
||||
json_status)
|
||||
json_status $2 $3 $4 $5 $6
|
||||
;;
|
||||
@@ -1119,6 +1175,22 @@ case "$1" in
|
||||
mqtt_status $2
|
||||
;;
|
||||
|
||||
last_rain_sensor_timestamp)
|
||||
last_rain_sensor_timestamp
|
||||
;;
|
||||
|
||||
last_rain_online_timestamp)
|
||||
last_rain_online_timestamp
|
||||
;;
|
||||
|
||||
reset_last_rain_sensor_timestamp)
|
||||
reset_last_rain_sensor_timestamp
|
||||
;;
|
||||
|
||||
reset_last_rain_online_timestamp)
|
||||
reset_last_rain_online_timestamp
|
||||
;;
|
||||
|
||||
check_rain_online)
|
||||
check_rain_online
|
||||
;;
|
||||
|
||||
Reference in New Issue
Block a user