Page 2 of 5

Re: [DIY] Garden irrigation and learning project

Posted: Wednesday 17 June 2015 16:31
by Siewert308SW
krizzz wrote:Cool project and Thanks for sharing! What were the costs for this whole project?
Thx... I think it's cool and functional.
Seems some of my neighbors think it's overkill :lol:
Total costs are €161
Keep in mind that i also used stuff i already got like garden hoses, hose coupling, wood, paint, stainless screws, sillicon kit and wiring.

Re: [DIY] Garden irrigation and learning project

Posted: Wednesday 17 June 2015 17:18
by StanHD
Of course some of your neighbours think it's overkill. That's just because they haven't done it or can't do it :mrgreen:

Nice project, well done :)

Re: [DIY] Garden irrigation and learning project

Posted: Wednesday 17 June 2015 19:37
by Siewert308SW
StanHD wrote:Of course some of your neighbours think it's overkill. That's just because they haven't done it or can't do it :mrgreen:

Nice project, well done :)
Thx for the heads up ;-)
Hardest part has begun now.
Writing a script which has to take account of different weather conditions over a longer period of time.
Hell, i want to automate and not manually switching it. :mrgreen:
The script i now temporally use (found in this forum) is great for one day.
But one perfect irrigation day doesn't mean you have to irrigate.
As i'm just a novice and will have do a lot of trial & error, copy/paste ect. ;-)

Re: [DIY] Garden irrigation and learning project

Posted: Saturday 20 June 2015 14:16
by Siewert308SW
Just got noticed by my neighbor.
The moist sensors have arrived.
Unfortunately not at home, at the campside.
So I have to have some patience until I get home tomorrow night.

Re: [DIY] Garden irrigation and learning project

Posted: Saturday 20 June 2015 18:04
by blackdog65
*Update* on my project

The relay I have like yours is no good for me :( the range is too far from my house so it only gets the signal 50% of the time.
I need to use the MUCH more expensive Fibaro FGS222 Double Relay. But these do work 100%

The drippler hoses work well for me but my rainwater pump only supplies enough pressure for 1 hose at a time and I need 4. So I need to get another washing machine valve ( and another FGS222 ) :x

The good news is that the relays can be switched manually which frees up some of the hardware ( and space ) I was using. :D

The bad news is... if the 433mhz relay is out of range... those soil moisture sensors have no chance of working for me, unless I buy another FRXTRX.... growing tomatoes can be an expensive hobby :lol:

I'll try and post some pictures :D

Re: [DIY] Garden irrigation and learning project

Posted: Sunday 21 June 2015 14:28
by Siewert308SW
Just got home and put some aaa batteries in the two devices.
First experience is bad.
Enabled Imagetronix/Opus support on in settings.
And nothing happend then i hooked up the rfxcom to my laptop and fired up RFXCom manager.
The rfxcom does see the devices but aren't recognized.
I thuight the Imagintronox/Opus was supported.

Raspberyy b 2 with a RFXtrx433e
Domoticz version 2.2579 beta
243 firmware

RFXcom manager says the following:

Code: Select all

Packettype        = UNDECODED RF Message
UNDECODED LACROSSE:1BA7BFF2C0 
------------------------------------------------
Packettype        = UNDECODED RF Message
UNDECODED OREGON3:37FCFFFFFFFFFF7F 

Re: [DIY] Garden irrigation and learning project

Posted: Sunday 21 June 2015 14:33
by Siewert308SW
p.s

after 20min on of the devices appeared in domoticz after hooking up the rfxcom again and restarting domoticz

Re: [DIY] Garden irrigation and learning project

Posted: Sunday 21 June 2015 15:30
by Siewert308SW
Have to go to a birthday party.
For now one device is recognized but last seen 14:15 while the time is now 15:30
Will let them both run for a while and see if domoticz picked them up when i come back.
One of the devices i gave a different ID by replacing the jumper inside the device.
Both are with 1.5mtr from my rfxcom.
So will report later.

Re: [DIY] Garden irrigation and learning project

Posted: Sunday 21 June 2015 20:04
by Siewert308SW
Just got back and 4hr ago i could add one device but it hasn't updated since then.
The other device isn't detected by domoticz.
While Imagintronix is enabled in hardware settings.
Just hooked it up to the RFXCOM manager to see if both devices will appear again there.
After 15min still nothing in the rfxcom manager 16.0.0.5.
Then i enabled all possible settings and after 15min i saw one device...

Code: Select all

Packettype    = TEMP_HUM
subtype       = TH12 - Imagintronix
                channel 2
Sequence nbr  = 14
ID            = 2
Temperature   = 25 °C
Humidity      = 5
Status        = Dry
Signal level  = 8
Battery       = OK
Only the reading is a bit offset.
25 degrees wil it's 20 degrees in my house and 5% humidity is right also.

Who got this device running under the same hardware and software as i wrote earlier?
And what did you do to get it working?

edit:

now i only recieve the following when the moist sensor is transmitting.

Code: Select all

Packettype        = UNDECODED RF Message
UNDECODED LACROSSE:12BFE740 
For now i must say i'm done with this sensor.
everyone has it working out of the box and i don't seem to get them working.

Re: [DIY] Garden irrigation and learning project

Posted: Wednesday 24 June 2015 13:34
by blackdog65
Here's how my project is progressing ;)

4 switches for manual over-ride on the solenoid valves. Aeon labs sensor for temp/humidity/lux.
Image

Inside box "A" **Temporary wiring!!** Power for light. Power for the 2 fibaro double relays. USB power for the Aeon labs sensor.
Image

Inside box "B" Even messier as I waiting for my second valve to arrive. :(
Image

Drippler hose No. 1 starting to sweat around the base of one of Mrs. Blackdog's beloved tomato plants :roll:
Image

One of my 12v moisture sensors. Unlike most, they have a relay with NC NO contacts and a sensitivity trimmer. I've not figured out yet how to get a signal from these back to Domoticz. The range + walls is too much for 433mhz. I don't want another RasPi in there. Maybe a fibaro universal sensor? Any suggestions?
Image

Re: [DIY] Garden irrigation and learning project

Posted: Wednesday 24 June 2015 13:57
by Siewert308SW
Looks great...
Seem you have a lot more wiring and hardware involved ;-)
The manual override is good, i have virtual switch for on my Tablet to override the irrigation process.
I can't give any suggestions for any available or usable Moist sensors.
No experience with any other then the one i own now.

As for the 2 Opus xt300 moist sensors i own.
Which report moist humidity, and soil temp.
Which i modified the antenna and extended the existing antenna with a 17cm copper wire.
Before the mod the range was below 2mtr outside the house :-(
It had to get true a double brick wall and HR++ glass.
Some other 433mhz devices have the same issue.
With the mod the range increased to 20mtr and have no problems with receiving data.

Downside is that i couldn't use them.
Seems Opus changed protocols in their new batch and the RFXcom had troubles seeing the devices.
Reported this and new firmware for RFXcom is out.
Other downside is that it's raining all week now so i couldn't test the irrigation or the scripts i'm trying the write... ;-)
Need a bit more patience over here, hope to have those ready before the holidays start (in two weeks)

Over here i use some scripts which reports and calculates/override the irrigation process.
1x if upcoming showers for 1hr/12hr and 24hr.
1x WeatherUnderground script to predict UV/Humidity/Temp ect to enable some override switches.
WeatherUnderground is pretty accurate as one of the stations reporting is close to me.

Re: [DIY] Garden irrigation and learning project

Posted: Thursday 25 June 2015 12:27
by Siewert308SW
For those who are interested and curious about what i'm upto regarding the script.
It's far from done but the first part is almost ready.
It's a copy and past from several scripts like, scrapping the weather data from weatherundeground, Flipstorm script (still need to implant) and some other snippets found on the internet.
I'm not a coder so it's a lot of trial and error ;)

First preview is ready.
This part of the script scraps the weather data and moist sensor data with a lot of user variables inorder to give the irrigation program a Go or NoGo
Now it's time to write some time triggers ect...

Code: Select all

--[[

	script_time_irrigation.lua
	@author: Siewert Lameijer
	@since: 2015-06-24
	@version: 1.0
	
	
Garden Irrigation script 

Variable to create:
- VarMayFollowProgram (type=integer, value=0)

--]]

commandArray = {}
time = os.date("*t")

    week       = tonumber(os.date("%V"));
	week       = tonumber(os.date("%m"));
    dayno       = tonumber(os.date("%d"));
    dayofweekno = tonumber(os.date("%w"));
    day       = tostring(os.date("%a"));
    hour       = tonumber(os.date("%H"));
    min       = tonumber(os.date("%M"));
	
--
-- **********************************************************
-- Settings Begin
-- **********************************************************
--

-- Lua script interval check, change the number 1 to every desired number in minutes
if((time.min % 1)==0)then

-- Logging: 0 = Off, 1 = On
local logging = 1

--
-- Weatherstation
-- Name of your Weatherstation widget which contains humidity,uv,temp and pressure
local weatherstation = 'Barometer'

-- Name of your Weatherstation Wind widget
local wind = 'Wind'

-- Name of your Weatherstation Wind widget
local rain = 'Regenmeter'

-- Name of your Weatherstation Wind widget
local uv = 'UV'

--
-- Moist Sensors
-- Name of your Moist Sensor device 1
local moistsensor1 = 'Vocht Sensor (border 1)'

-- Name of your Moist Sensor device 2
local moistsensor2 = 'Vocht Sensor (border 1)'

--
-- Switches and Virtual Switches
-- Name of your manual override virtual switch
local manoverride = 'Irrigatie Manual Override'

--
-- User Variables
-- Maximum amount of cycles your irrigation can be on
local VarMaxRun = '12'

-- Your target soil humidity percentage
local VarTarHum = '85'

-- Your Minumum soil temperature
local VarTarTempMin = '14'

-- Your Maximum soil temperature
local VarTarTempMax = '30'

-- Name of your User Variable for counting clear days: (type integer, Input 0)
local VarDays = 'Dagen'

-- Set your desired irrigation day, leave blank for no irrigation, set Mo, Tue, Wed, Thu, Fri, Sat or Sun
local VarDay1 = 'Mo'

local VarDay2 = 'Tue'

local VarDay3 = 'Wed'

local VarDay4 = 'Thu'

local VarDay5 = 'Fri'

local VarDay6 = 'Sat'

local VarDay7 = 'Sun'

-- Set your desired irrigation month, leave blank for no irrigation, set a number like 1 for January or 5 for May
local VarMonth1 = '1'

local VarMonth2 = '2'

local VarMonth3 = '3'

local VarMonth4 = '4'

local VarMonth5 = '5'

local VarMonth6 = '6'

local VarMonth7 = '7'

local VarMonth8 = '8'

local VarMonth9 = '9'

local VarMonth10 = '10'

local VarMonth11 = '11'

local VarMonth12 = '12'
--
-- Weather Variables
-- Set your prefered max rain fall
local RainCurrent = '0'

-- Set your prefered maximum temperature for irrigation (Higher doesn't trigger irrigation)
local WeatherTempMin = '15'

-- Set your prefered maximum temperature for irrigation (Higher doesn't trigger irrigation)
local WeatherTempMax = '27'

-- Set your prefered maximum UV for irrigation (Higher doesn't trigger irrigation)
local UV = '6'

-- Set your prefered max windspeed km/h (higher doesn't trigger irrigation)
local WindSpeed = '50'

-- Set your prefered max windgust km/h (higher doesn't trigger irrigation)
local WindGust = '150'



--
-- **********************************************************
-- Settings END
-- **********************************************************
--

--[[
--> Don't edit anything below this line or you could break the script!
--]]

--
-- **********************************************************
-- Scrapping Weather Data from WeatherUnderground
-- **********************************************************
--

--
-- Weatherstation data:
-- 

sWeatherTemp, sWeatherHumidity, sWeatherUV, sWeatherPressure, sWeatherUV2 = otherdevices_svalues[weatherstation]:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
sWeatherTemp = tonumber(sWeatherTemp);
sWeatherHumidity = tonumber(sWeatherHumidity);
sWeatherUV = tonumber(sWeatherUV);
sWeatherPressure = tonumber(sWeatherPressure);
sWeatherUV2 = tonumber(sWeatherUV2);


	if logging >= 1 then
		print("Irrigation [INFO]");
		print("Irrigation [Weather station] ==> Temperature is " .. sWeatherTemp .. " ");
		print("Irrigation [Weather station] ==> Humidity is " .. sWeatherHumidity .. " ");
		print("Irrigation [Weather station] ==> UV is " .. sWeatherUV .. " ");
		print("Irrigation [Weather station] ==> Pressure is " .. sWeatherPressure .. " ");
		print("Irrigation [Weather station] ==> UV2 is " .. sWeatherUV2 .. " ");

	end
	
--
-- Windmeter data:
-- 

sWindDirectionDegrees, sWindDirection, sWindSpeed, sWindGust, sWindTemperature, sWindFeel = otherdevices_svalues[wind]:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
 
sWindDirectionDegrees = tonumber(sWindDirectionDegrees);
sWindDirection = (sWindDirection);
sWindSpeed = tonumber(sWindSpeed);
sWindGust = tonumber(sWindGust);
sWindTemperature = tonumber(sWindTemperature);
sWindFeel = tonumber(sWindFeel);

	if logging >= 1 then
		print("Irrigation [Windmeter] ==> Winddirection (in degrees) is: " .. sWindDirectionDegrees .. " ");
		print("Irrigation [Windmeter] ==> Winddirection is: " .. sWindDirection .. " ");
		print("Irrigation [Windmeter] ==> Windspeed is: " .. sWindSpeed .. " ");
		print("Irrigation [Windmeter] ==> Windgust is: " .. sWindGust .. " ");
		print("Irrigation [Windmeter] ==> Windtemperature is: " .. sWindTemperature .. " ");
		print("Irrigation [Windmeter] ==> Windfeel is: " .. sWindFeel .. " ");
	end
	
--
-- Rainmeter data:
-- 

sRainmeterCurrent, sRainmeterTotal = otherdevices_svalues[rain]:match("([^;]+);([^;]+)")
 
sRainmeterCurrent = tonumber(sRainmeterCurrent);
sRainmeterTotal = tonumber(sRainmeterTotal);

	if logging >= 1 then
		print("Irrigation [Rainmeter] ==> Actual rain is: " .. sRainmeterCurrent .. " ");
		print("Irrigation [Rainmeter] ==> Total rain is: " .. sRainmeterTotal .. " ");
	end
	
--
-- UV data:
-- 

sUV, sSolar = otherdevices_svalues[uv]:match("([^;]+);([^;]+)")
 
sUV = tonumber(sUV);
sSolar = tonumber(sSolar);

	if logging >= 1 then
		print("Irrigation [UV] ==> UV Strength is: " .. sUV .." ");
		print("Irrigation [UV] ==> Solar radiation is: " .. sSolar .." ");
	end
	
--
-- **********************************************************
-- Scrapping Temparature and moist humidity from moist sensor
-- **********************************************************
--

--
-- Moist Sensor 1 data:
-- 

    smoistsensorTemp, smoistsensorHumidity = otherdevices_svalues[moistsensor1]:match("([^;]+);([^;]+);([^;]+)")
    smoistsensorTemp = tonumber(smoistsensorTemp);
    smoistsensorHumidity = tonumber(smoistsensorHumidity);

	if logging >= 1 then
		print("Irrigation [MoistSensor 1] ==> Moist Temperature: " .. smoistsensorTemp .. " ");
		print("Irrigation [MoistSensor 1] ==> Moist Humidity: " .. smoistsensorHumidity .. " ");
	end
	
--
-- Moist Sensor 2 data:
--

    smoistsensor2Temp, smoistsensor2Humidity = otherdevices_svalues[moistsensor2]:match("([^;]+);([^;]+);([^;]+)")
    smoistsensor2Temp = tonumber(smoistsensor2Temp);
    smoistsensor2Humidity = tonumber(smoistsensor2Humidity);

	if logging >= 1 then
		print("Irrigation [MoistSensor 2] ==> Moist Temperature: " .. smoistsensor2Temp .. " ");
		print("Irrigation [MoistSensor 2] ==> Moist Humidity: " .. smoistsensor2Humidity .. " ");
	end	
	
--
-- **********************************************************
-- Moist Sensor online check
-- **********************************************************
--	

--
-- Moist Sensor 1:
--

-- check if the moist sensor 1 is online
if (smoistsensorTemp == 0 or smoistsensorTemp == nil) then
    print('Moist Sensor 1 reports Temp is 0 or nil. Skipping Irrigation')
	commandArray[manoverride]='On'
    return commandArray
end

if (smoistsensorHumidity == 0 or smoistsensorHumidity == nil) then
    print('Moist Sensor 1 reports Humidity is 0 or nil. Skipping Irrigation')
	commandArray[manoverride]='On'
    return commandArray
end

--
-- Moist Sensor 2:
--

-- check if the moist sensor 2 is online
if (smoistsensor2Temp == 0 or smoistsensor2Temp == nil) then
    print('Moist Sensor 2 reports Temp is 0 or nil. Skipping Irrigation')
	commandArray[manoverride]='On'
    return commandArray
end

if (smoistsensor2Humidity == 0 or smoistsensor2Humidity == nil) then
    print('Moist Sensor 2 reports Humidity is 0 or nil. Skipping Irrigation')
	commandArray[manoverride]='On'
    return commandArray
end

--
-- **********************************************************
-- checking weather conditions so irrigation may proceed 
-- **********************************************************
--	

if day == VarDay1 or day == VarDay2 or day == VarDay3 or day == VarDay4 or day == VarDay5 or day == VarDay6 or day == VarDay7 or
   month == VarMonth1 or month == VarMonth2	or month == VarMonth3 or month == VarMonth4 or month == VarMonth5 or month == VarMonth6 or month == VarMonth7 or month == VarMonth8 or month == VarMonth9 or month == VarMonth10 or month == VarMonth11 or month == VarMonth12
	and smoistsensorTemp >= tonumber (VarTarTempMin)
	--and smoistsensorTemp <= tonumber (VarTarTempMax)
	--and smoistsensorHumidity <= tonumber (VarTarHum)
	--and sRainmeterCurrent == tonumber (RainCurrent)
	--and sWeatherTemp >= tonumber (WeatherTempMin)
	--and sWeatherTemp <= tonumber (WeatherTempMax)
	--and sUV <= tonumber (UV)
	--and sWindSpeed <= tonumber (WindSpeed)
	--and sWindGust <= tonumber (WindGust)
then

	if logging >= 1 then
		print("Irrigation [Program] ==> May continue");
	end
	if(uservariables['VarMayFollowProgram'] == 0) then
	--if ( uservariables["VarMayFollowProgram"] == "0" ) then
	print("Irrigation [Program Value] ==> Updated");
	commandArray['Variable:VarMayFollowProgram']= '1'
end
	
else

	if logging >= 1 then
		print("Irrigation [Program] ==> May NOT continue");
	end
	if(uservariables['VarMayFollowProgram'] == 1) then	
	print("Irrigation [Program Value] ==> Updated");
	commandArray['Variable:VarMayFollowProgram']= '0'
	end	
end

end 
return commandArray

Re: [DIY] Garden irrigation and learning project

Posted: Thursday 25 June 2015 19:41
by Siewert308SW
Second preview...
Got i bit closer to the end result.
Build in a manual override, improved value checks and improved the Go or No Go and added a desired time of day.

Now i have to build in a desired max run cycle with checks and overrides.
Fun stuff that lua... Never worked with it.

Code: Select all

--[[

	script_time_irrigation.lua
	@author: Siewert Lameijer
	@since: 2015-06-24
	@version: 1.0
	
	
Garden Irrigation script 

User Variable to create:
- VarManOverride (type=integer, value=0)
- VarTimeCon (type=integer, value=0)
- VarWeatherCon (type=integer, value=0)
- VarTimeOfDayCurrent (type=integer, value=0)
- VarMayFollowProgram (type=integer, value=0)
- VarFollowsProgram (type=integer, value=0)
- VarMaxRun (type=integer, value=0)
- VarMoistCon (type=integer, value=0)

--]]

commandArray = {}
time = os.date("*t")

    week       = tonumber(os.date("%V"));
	week       = tonumber(os.date("%m"));
    dayno       = tonumber(os.date("%d"));
    dayofweekno = tonumber(os.date("%w"));
    day       = tostring(os.date("%a"));
    hour       = tonumber(os.date("%H"));
    min       = tonumber(os.date("%M"));
	
--
-- **********************************************************
-- Settings Begin
-- **********************************************************
--

-- Lua script interval check, change the number 1 to every desired number in minutes
if((time.min % 1)==0)then

-- Logging: 0 = Off, 1 = On
local logging = 1

--
-- Weatherstation
-- Name of your Weatherstation widget which contains humidity,uv,temp and pressure
local weatherstation = 'Barometer'

-- Name of your Weatherstation Wind widget
local wind = 'Wind'

-- Name of your Weatherstation Wind widget
local rain = 'Regenmeter'

-- Name of your Weatherstation Wind widget
local uv = 'UV'

--
-- Moist Sensors
-- Name of your Moist Sensor device 1
local moistsensor1 = 'Vocht Sensor (border 1)'

-- Name of your Moist Sensor device 2
local moistsensor2 = 'Vocht Sensor (border 1)'

--
-- Switches and Virtual Switches
-- Name of your manual override virtual switch
local manoverride = 'Irrigatie Manual Override'

--
-- User Variables
-- Maximum amount of cycles your irrigation can be on
local VarMaxRun = '12'

-- Your target soil humidity percentage
local VarTarHum = '85'

-- Your Minumum soil temperature, Lower won't trigger irrigation
local VarTarTempMin = '14'

-- Your Maximum soil temperature, Higher won't trigger irrigation
local VarTarTempMax = '30'

-- Set your desired TimeOfDay for irrigation (Morning=0, Afternoon=1, Evening=2 or Night=3)
local VarTimeOfDay = '2'

-- Set your desired irrigation day, leave blank for no irrigation, set Mon, Tue, Wed, Thu, Fri, Sat or Sun
local VarDay1 = 'Mon'

local VarDay2 = ''

local VarDay3 = 'Wed'

local VarDay4 = 'Thu'

local VarDay5 = 'Fri'

local VarDay6 = ''

local VarDay7 = 'Sun'

-- Set your desired irrigation month, leave blank for no irrigation, set a number like 1 for January or 5 for May
local VarMonth1 = ''

local VarMonth2 = ''

local VarMonth3 = ''

local VarMonth4 = '4'

local VarMonth5 = '5'

local VarMonth6 = '6'

local VarMonth7 = '7'

local VarMonth8 = '8'

local VarMonth9 = '9'

local VarMonth10 = ''

local VarMonth11 = ''

local VarMonth12 = ''
--
-- Weather Variables
-- Set your prefered max rain fall, higher won't trigger irrigation
local RainCurrent = '0'

-- Set your prefered minimum outside temperature for irrigation, Lower won't trigger irrigation
local WeatherTempMin = '15'

-- Set your prefered maximum outside temperature for irrigation, Higher won't trigger irrigation
local WeatherTempMax = '27'

-- Set your prefered maximum UV for irrigation, Higher won't trigger irrigation
local UV = '6'

-- Set your prefered max windspeed km/h, higher won't trigger irrigation
local WindSpeed = '50'

-- Set your prefered max windgust km/h, higher won't trigger irrigation
local WindGust = '150'


--
-- **********************************************************
-- Settings END
-- **********************************************************
--

--[[
--> Don't edit anything below this line or you could break the script!
--]]

--
-- **********************************************************
-- Scrapping Weather Data from WeatherUnderground
-- **********************************************************
--

--
-- Weatherstation data:
-- 

sWeatherTemp, sWeatherHumidity, sWeatherUV, sWeatherPressure, sWeatherUV2 = otherdevices_svalues[weatherstation]:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
sWeatherTemp = tonumber(sWeatherTemp);
sWeatherHumidity = tonumber(sWeatherHumidity);
sWeatherUV = tonumber(sWeatherUV);
sWeatherPressure = tonumber(sWeatherPressure);
sWeatherUV2 = tonumber(sWeatherUV2);


	if logging >= 1 then
		print("--------------------------------------------------------------------------------------")
		print("Irrigation [INFO]");
		print("-- [Weather station] ==> Temperature is " .. sWeatherTemp .. " ");
		print("-- [Weather station] ==> Humidity is " .. sWeatherHumidity .. " ");
		print("-- [Weather station] ==> UV is " .. sWeatherUV .. " ");
		print("-- [Weather station] ==> Pressure is " .. sWeatherPressure .. " ");
		print("-- [Weather station] ==> UV2 is " .. sWeatherUV2 .. " ");
	    print("--------------------------------------------------------------------------------------")
	end
	
--
-- Windmeter data:
-- 

sWindDirectionDegrees, sWindDirection, sWindSpeed, sWindGust, sWindTemperature, sWindFeel = otherdevices_svalues[wind]:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
 
sWindDirectionDegrees = tonumber(sWindDirectionDegrees);
sWindDirection = (sWindDirection);
sWindSpeed = tonumber(sWindSpeed);
sWindGust = tonumber(sWindGust);
sWindTemperature = tonumber(sWindTemperature);
sWindFeel = tonumber(sWindFeel);

	if logging >= 1 then
		print("-- [Windmeter] ==> Winddirection (in degrees) is: " .. sWindDirectionDegrees .. " ");
		print("-- [Windmeter] ==> Winddirection is: " .. sWindDirection .. " ");
		print("-- [Windmeter] ==> Windspeed is: " .. sWindSpeed .. " ");
		print("-- [Windmeter] ==> Windgust is: " .. sWindGust .. " ");
		print("-- [Windmeter] ==> Windtemperature is: " .. sWindTemperature .. " ");
		print("-- [Windmeter] ==> Windfeel is: " .. sWindFeel .. " ");
		print("--------------------------------------------------------------------------------------")
	end
	
--
-- Rainmeter data:
-- 

sRainmeterCurrent, sRainmeterTotal = otherdevices_svalues[rain]:match("([^;]+);([^;]+)")
 
sRainmeterCurrent = tonumber(sRainmeterCurrent);
sRainmeterTotal = tonumber(sRainmeterTotal);

	if logging >= 1 then
		print("-- [Rainmeter] ==> Actual rain is: " .. sRainmeterCurrent .. " ");
		print("-- [Rainmeter] ==> Total rain is: " .. sRainmeterTotal .. " ");
		print("--------------------------------------------------------------------------------------")
	end
	
--
-- UV data:
-- 

sUV, sSolar = otherdevices_svalues[uv]:match("([^;]+);([^;]+)")
 
sUV = tonumber(sUV);
sSolar = tonumber(sSolar);

	if logging >= 1 then
		print("-- [UV] ==> UV Strength is: " .. sUV .." ");
		print("-- [UV] ==> Solar radiation is: " .. sSolar .." ");
		print("--------------------------------------------------------------------------------------")
	end
	
--
-- **********************************************************
-- Scrapping Temparature and moist humidity from moist sensor
-- **********************************************************
--

--
-- Moist Sensor 1 data:
-- 

    smoistsensorTemp, smoistsensorHumidity = otherdevices_svalues[moistsensor1]:match("([^;]+);([^;]+);([^;]+)")
    smoistsensorTemp = tonumber(smoistsensorTemp);
    smoistsensorHumidity = tonumber(smoistsensorHumidity);

	if logging >= 1 then
		print("-- [MoistSensor 1] ==> Moist Temperature: " .. smoistsensorTemp .. " ");
		print("-- [MoistSensor 1] ==> Moist Humidity: " .. smoistsensorHumidity .. " ");
	end
	
--
-- Moist Sensor 2 data:
--

    smoistsensor2Temp, smoistsensor2Humidity = otherdevices_svalues[moistsensor2]:match("([^;]+);([^;]+);([^;]+)")
    smoistsensor2Temp = tonumber(smoistsensor2Temp);
    smoistsensor2Humidity = tonumber(smoistsensor2Humidity);

	if logging >= 1 then
		print("-- [MoistSensor 2] ==> Moist Temperature: " .. smoistsensor2Temp .. " ");
		print("-- [MoistSensor 2] ==> Moist Humidity: " .. smoistsensor2Humidity .. " ");
		print("--------------------------------------------------------------------------------------")
	end	
	
--
-- **********************************************************
-- Moist Sensor online check
-- **********************************************************
--	

--
-- Moist Sensor 1:
--

-- check if the moist sensor 1 is online
if (smoistsensorTemp == 0 or smoistsensorTemp == nil) then
    print('Irrigation [MoistSensor 1 ERROR] ==> Moist Sensor 1 reports Temp is 0 or nil. Skipping Irrigation')
	if(uservariables['VarMoistCon'] == 1) then	
	commandArray['Variable:VarMoistCon']= '0'
	end
    return commandArray
		else
		if logging >= 1 then
		print("-- Irrigation [Program] ==> Moist temperature sensor (1) is Online");
		end
	if(uservariables['VarMoistCon'] == 0) then		
	commandArray['Variable:VarMoistCon']= '1'
	end
end

if (smoistsensorHumidity == 0 or smoistsensorHumidity == nil) then
    print('Irrigation [MoistSensor 1 ERROR] ==> Moist Sensor 1 reports Humidity is 0 or nil. Skipping Irrigation')
	if(uservariables['VarMoistCon'] == 1) then	
	commandArray['Variable:VarMoistCon']= '0'
	end
    return commandArray
		else
		if logging >= 1 then
		print("-- Irrigation [Program] ==> Moist humidity sensor (1) is Online");
		end
	if(uservariables['VarMoistCon'] == 0) then		
	commandArray['Variable:VarMoistCon']= '1'
	end
end

--
-- Moist Sensor 2:
--

-- check if the moist sensor 2 is online
if (smoistsensor2Temp == 0 or smoistsensor2Temp == nil) then
    print('Irrigation [MoistSensor 2 ERROR] ==> Moist Sensor 2 reports Temp is 0 or nil. Skipping Irrigation')
	if(uservariables['VarMoistCon'] == 1) then	
	commandArray['Variable:VarMoistCon']= '0'
	end
    return commandArray
		else
		if logging >= 1 then
		print("-- Irrigation [Program] ==> Moist temperature sensor (2) is Online");
		end
	if(uservariables['VarMoistCon'] == 0) then		
	commandArray['Variable:VarMoistCon']= '1'
	end
end

if (smoistsensor2Humidity == 0 or smoistsensor2Humidity == nil) then
    print('Irrigation [MoistSensor 2 ERROR] ==> Moist Sensor 2 reports Humidity is 0 or nil. Skipping Irrigation')
	if(uservariables['VarMoistCon'] == 1) then	
	commandArray['Variable:VarMoistCon']= '0'
	end
    return commandArray
		else
		if logging >= 1 then
		print("-- Irrigation [Program] ==> Moist humidity sensor (2) is Online");
		end	
	if(uservariables['VarMoistCon'] == 0) then
	commandArray['Variable:VarMoistCon']= '1'
	end
end

--
-- **********************************************************
-- checking weather conditions so irrigation may proceed 
-- **********************************************************
--	

if day == VarDay1 or day == VarDay2 or day == VarDay3 or day == VarDay4 or day == VarDay5 or day == VarDay6 or day == VarDay7 or
   month == VarMonth1 or month == VarMonth2	or month == VarMonth3 or month == VarMonth4 or month == VarMonth5 or month == VarMonth6 or month == VarMonth7 or month == VarMonth8 or month == VarMonth9 or month == VarMonth10 or month == VarMonth11 or month == VarMonth12
	and smoistsensorTemp >= tonumber (VarTarTempMin)
	--and smoistsensorTemp <= tonumber (VarTarTempMax)
	--and smoistsensorHumidity <= tonumber (VarTarHum)
	--and sRainmeterCurrent == tonumber (RainCurrent)
	--and sWeatherTemp >= tonumber (WeatherTempMin)
	--and sWeatherTemp <= tonumber (WeatherTempMax)
	--and sUV <= tonumber (UV)
	--and sWindSpeed <= tonumber (WindSpeed)
	--and sWindGust <= tonumber (WindGust)
then

	if logging >= 1 then
		print("-- Irrigation [Program] ==> Weather condition are looking good");
	end
	
	if(uservariables['VarWeatherCon'] == 0) then
	
	if logging >= 1 then
	print("-- Irrigation [Program] ==> Weather condition set Okay");
	end
	commandArray['Variable:VarWeatherCon']= '1'
end
	
else

	if logging >= 1 then
		print("-- Irrigation [Program] ==> Weather condition aren't looking good");
	end
	if(uservariables['VarWeatherCon'] == 1) then
	
	if logging >= 1 then
	print("-- Irrigation [Program] ==> Weather condition set False");
	end
	commandArray['Variable:VarWeatherCon']= '0'
	end	
end

--
-- **********************************************************
-- checking time of the day so irrigation may proceed 
-- **********************************************************
--

if (timeofday['Sunrise']) and (uservariables['VarTimeOfDayCurrent'] ~= 0) then
commandArray['Variable:VarTimeOfDayCurrent']= '0'
if logging >= 1 then
print("-- Irrigation [Program] ==> Time set to Morning")
end
end

if (time.hour >= 12) and (time.hour <= 17) and (uservariables['VarTimeOfDayCurrent'] ~= 1) then
commandArray['Variable:VarTimeOfDayCurrent']= '1'
if logging >= 1 then
print("-- Irrigation [Program] ==>  Time set to Afternoon")
end
end

if (time.hour >= 17) and (time.hour <= 20) and (uservariables['VarTimeOfDayCurrent'] ~= 2) then
commandArray['Variable:VarTimeOfDayCurrent']= '2'
if logging >= 1 then
print("-- Irrigation [Program] ==>  Time set to Evening")
end
end

if (time.hour >= 20) and (uservariables['VarTimeOfDayCurrent'] ~= 3) then
commandArray['Variable:VarTimeOfDayCurrent']= '3'
if logging >= 1 then
print("-- Irrigation [Program] ==>  Time set to Night")
end
end

if (uservariables['VarTimeOfDayCurrent']) == tonumber (VarTimeOfDay) then
if logging >= 1 then
print("-- Irrigation [Program] ==> Timeframe okay")
if (uservariables['VarTimeCon']) == 0 then
commandArray['Variable:VarTimeCon']= '1'
end
end
else
if logging >= 1 then
print("-- Irrigation [Program] ==> Awaiting for the right Timeframe")
end
if (uservariables['VarTimeCon']) == 1 then
commandArray['Variable:VarTimeCon']= '0'
end
end

--
-- **********************************************************
-- Processing data into a usable yes or nogo for irrigation
-- **********************************************************
--

	if (uservariables['VarTimeCon']) == 1 
		and (uservariables['VarWeatherCon']) == 1
		and (uservariables['VarMoistCon']) == 1
		--and (uservariables['VarMayFollowProgram']) == 0
		and (uservariables['VarFollowsProgram']) == 0
		and (uservariables['VarManOverride']) == 0
	then
		if logging >= 1 then
		print("-- Irrigation [Program] ==> All okay, Irrigation may follow program")
		print("--------------------------------------------------------------------------------------")
		end
		if (uservariables['VarMayFollowProgram']) == 0 then
		commandArray['Variable:VarMayFollowProgram']= '1'
		end
	else
		if logging >= 1 then
		print("-- Irrigation [Program] ==> All ain't okay, Irrigation may not follow program")
		print("--------------------------------------------------------------------------------------")
		end
	if (uservariables['VarMayFollowProgram']) == 1 then
	commandArray['Variable:VarMayFollowProgram']= '0'
		end
	end
	
	if (uservariables['VarManOverride']) == 1
	then
		if logging >= 1 then
		print("-- Irrigation [Program] ==> Irrigation set to manual, programm stopped")
		print("--------------------------------------------------------------------------------------")
		end
		
		if (uservariables['VarMayFollowProgram']) == 1 then
		commandArray['Variable:VarMayFollowProgram']= '0'
		end
		
		if (uservariables['VarFollowsProgram']) == 1 then
		commandArray['Variable:VarFollowsProgram']= '0'
		end

	end

Re: [DIY] Garden irrigation and learning project

Posted: Thursday 25 June 2015 22:47
by maluko
good project

it can be done with esp8266 and a relay board to control the valves, only if you have wifi there.
and than control on domoticz with virtual switch.

https://drive.google.com/file/d/0B9yx2L ... sp=sharing
https://drive.google.com/file/d/0B9yx2L ... sp=sharing
https://drive.google.com/file/d/0B9yx2L ... sp=sharing

Re: [DIY] Garden irrigation and learning project

Posted: Monday 29 June 2015 9:42
by ThinkPad
Nice project :)

How long does the water keeps flowing if activated by the script? I don't know if those washing machine valves can handle being turned on for an hour or so. I think they will get quite warm.
Normally in a washing machine they are only operated for 2 minutes or so.

Re: [DIY] Garden irrigation and learning project

Posted: Monday 29 June 2015 10:17
by Siewert308SW
ThinkPad wrote:Nice project :)

How long does the water keeps flowing if activated by the script? I don't know if those washing machine valves can handle being turned on for an hour or so. I think they will get quite warm.
Normally in a washing machine they are only operated for 2 minutes or so.
Script aint ready yet so i can not test it yet.
For i only have a small script which looks at the the moist humidity and triggers when water is required.
Holiday time so i'm at the camping for 4 weeks.
Won't be writing all day, just enjoying the weather and beer :D

I don't know how long such a valve can be on as it was raining last week and this weekend so no irrigation required.
Only had it ON two times to see how long it took to get to a certain humidity level.
Which took 50min to get from 45% to 85%.
But i guess it gets a bit of cooling when the water flows by the membrane.
Lucky it's just a 6euro part so easily replaced when it dies ;)

The script version i got here is different from the one i posted earlier.
It's far from ready but hope to finish it soon.
A Preview of the current script you will find below.
- The scripts scraps the weather conditions from WeatherUnderground.
- For Dutch users i also inserted buienradar rain forecast for 6/12/24hr
- Also the scripts checks if the Moist sensors are online and sending the right values.
- It also checks if the right TimeOfTheDay is correct which you have to set in the script.
- Same counts for which days of week and months you want to be able to irrigate.
- You also can set your desired DayTime like morning, evening or night
- The script has a manual override to stop irrigation when needed
- When a irrigation cycle has completed it will trigger a override which will reset when your TimeFrame is correct again.
So for example you set irrigation ON on Monday and Thursday and the irrigation has completed on Monday then it won't trigger again on Monday until your on Thursday even if the all the targeted conditions say you must irrigate.

Further more the irrigation will be stopped when your desired humidity is reached within your desired Maximum Irrigation RunTime.
The RunTime when the pump is ON can be set manually i have it set to 60min.
So if the humidity target is reached with in the hour then the irrigation will stop.
But when the hour expires and the humidity target hasn't been reached then the irrigation will also stop.
Only the script won't stop when the weather conditions are going from a OKAY to a FALSE.
When the irrigation program has been started while the weather target conditions are good and suddenly the weather condition changes the irrigation will finish it cycle.
So it only stops when the humidity target or MaxRunTime has been exceeded.

I'm not a programmer so the script aint the cleanest but for me it will work and does the job... :D
As mentioned earlier, it's not finished yet.

Code: Select all

--[[

	script_time_irrigation.lua
	@author: Siewert Lameijer
	@since: 2015-06-24
	@version: 1.0
	
	
Garden Irrigation script 

User Variable to create:
- VarManOverride (type=integer, value=0)
- VarTimeCon (type=integer, value=0)
- VarWeatherCon (type=integer, value=0)
- VarTimeOfDayCurrent (type=integer, value=0)
- VarMayFollowProgram (type=integer, value=0)
- VarFollowsProgram (type=integer, value=0)
- VarMaxRunTime (type=integer, value=0)
- VarMoistOnline (type=integer, value=0)
- VarMoistOnlineHum (type=integer, value=0)
- VarMoistConTemp (type=integer, value=0)
- VarMoistConHum (type=integer, value=0)
- VarProgramOverride (type=integer, value=0)
- VarProgramRun (type=integer, value=0)
- VarTimeFrame (type=integer, value=0)
- VarManOverrideCon (type=integer, value=0)

Virtual Switches
- Manual Override

Hardware:
1x Moist Sensor which measures Temperature and Humdity
1x WeatherUnderground
1x Switch for wireless controled WaterPump for irrigation

--]]

time = os.date("*t")
	commandArray = {}
--
-- **********************************************************
-- Settings Begin
-- **********************************************************
--

-- Lua script interval check, change the number 1 to every desired number in minutes
--if((time.min % 1)==0)then

-- Logging: 0 = Off, 1 = On
local logging = 1

--
-- **********************************************************
-- WeatherUnderGround Variables
-- **********************************************************
-- 
-- Name of your Weatherstation widget which contains humidity,uv,temp and pressure
local weatherstation = 'Barometer'

-- Name of your Weatherstation Wind widget
local wind = 'Wind'

-- Name of your Weatherstation Rain widget
local rain = 'Regenmeter'

-- Name of your Weatherstation UV widget
local uv = 'UV'

--
-- **********************************************************
-- Switches and Virtual Switches Variables
-- **********************************************************
--
-- Name of your manual override virtual switch
local VitManOverride = 'Irrigatie Manual Override'

-- Name of your irrigation switch for water valve 1
local VarPump = 'Irrigatie 1 Check'

--
-- **********************************************************
-- Moist Sensor Variables
-- **********************************************************
-- 
-- Name of your Moist Sensor device
local MoistSensor = 'Vocht Sensor (border 1)'

-- Your target soil humidity percentage
local VarTarHum = '85'

-- Your Minumum soil temperature, Lower won't trigger irrigation
local VarTarTempMin = '12'

-- Your Maximum soil temperature, Higher won't trigger irrigation
local VarTarTempMax = '30'

-- Amount of minuten/times we want to switch OFF irrigation after the program has started.		
local VarMaxRunTime_off = 5

--
-- **********************************************************
-- Day, Month and Time Variables
-- **********************************************************
--
-- Set your desired TimeOfDay for irrigation (Morning=0, Afternoon=1, Evening=2 or Night=3)
local VarTimeOfDay = '0'

-- Set your desired irrigation day, leave blank for no irrigation, set Mon, Tue, Wed, Thu, Fri, Sat or Sun
local VarDay1 = 'Mon'

local VarDay2 = ''

local VarDay3 = 'Wed'

local VarDay4 = ''

local VarDay5 = 'Fri'

local VarDay6 = ''

local VarDay7 = 'Sun'

-- Set your desired irrigation month, leave blank for no irrigation, set a number like 1 for January or 5 for May
local VarMonth1 = ''

local VarMonth2 = ''

local VarMonth3 = ''

local VarMonth4 = '4'

local VarMonth5 = '5'

local VarMonth6 = '6'

local VarMonth7 = '7'

local VarMonth8 = '8'

local VarMonth9 = '9'

local VarMonth10 = ''

local VarMonth11 = ''

local VarMonth12 = ''

--
-- **********************************************************
-- Weather Variables
-- **********************************************************
-- 
-- Set your prefered max rain fall, higher won't trigger irrigation
local RainCurrent = '0'

-- Set your prefered minimum outside temperature for irrigation, Lower won't trigger irrigation
local WeatherTempMin = '13'

-- Set your prefered maximum outside temperature for irrigation, Higher won't trigger irrigation
local WeatherTempMax = '25'

-- Set your prefered maximum UV for irrigation, Higher won't trigger irrigation
local UVMax = '6'

-- Set your prefered max windspeed km/h, higher won't trigger irrigation
local WindSpeed = '50'

-- Set your prefered max windgust km/h, higher won't trigger irrigation
local WindGust = '150'


--
-- **********************************************************
-- Settings END
-- **********************************************************
--

--[[
--> Don't edit anything below this line or you could break the script!
--]]

    week       = tonumber(os.date("%V"));
	month       = tonumber(os.date("%m"));
    dayno       = tonumber(os.date("%d"));
    dayofweekno = tonumber(os.date("%w"));
    day       = tostring(os.date("%a"));
    hour       = tonumber(os.date("%H"));
    min       = tonumber(os.date("%M"));
	
--
-- **********************************************************
-- Scrapping Weather Data from WeatherUnderground
-- **********************************************************
--

--
-- Weatherstation data:
-- 

sWeatherTemp, sWeatherHumidity, sWeatherUV, sWeatherPressure, sWeatherUV2 = otherdevices_svalues[weatherstation]:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
sWeatherTemp = tonumber(sWeatherTemp);
sWeatherHumidity = tonumber(sWeatherHumidity);
sWeatherUV = tonumber(sWeatherUV);
sWeatherPressure = tonumber(sWeatherPressure);
sWeatherUV2 = tonumber(sWeatherUV2);


	if logging >= 1 then
		print("--------------------------------------------------------------------------------------")
		print("Irrigation [PROGRAM - Weather Conditions]");
		print("-- Irrigation ==> [WeatherStation] - Temperature is " .. sWeatherTemp .. " ");
		print("-- Irrigation ==> [WeatherStation] - Humidity is " .. sWeatherHumidity .. " ");
		print("-- Irrigation ==> [WeatherStation] - UV is " .. sWeatherUV .. " ");
		print("-- Irrigation ==> [WeatherStation] - Pressure is " .. sWeatherPressure .. " ");
		print("-- Irrigation ==> [WeatherStation] - UV2 is " .. sWeatherUV2 .. " ");
	end
	
--
-- Windmeter data:
-- 

sWindDirectionDegrees, sWindDirection, sWindSpeed, sWindGust, sWindTemperature, sWindFeel = otherdevices_svalues[wind]:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
 
sWindDirectionDegrees = tonumber(sWindDirectionDegrees);
sWindDirection = (sWindDirection);
sWindSpeed = tonumber(sWindSpeed);
sWindGust = tonumber(sWindGust);
sWindTemperature = tonumber(sWindTemperature);
sWindFeel = tonumber(sWindFeel);

	if logging >= 1 then
		print("-- Irrigation ==> [Windmeter] - Winddirection (in degrees) is: " .. sWindDirectionDegrees .. " ");
		print("-- Irrigation ==> [Windmeter] - Winddirection is: " .. sWindDirection .. " ");
		print("-- Irrigation ==> [Windmeter] - Windspeed is: " .. sWindSpeed .. " ");
		print("-- Irrigation ==> [Windmeter] - Windgust is: " .. sWindGust .. " ");
		print("-- Irrigation ==> [Windmeter] - Windtemperature is: " .. sWindTemperature .. " ");
		print("-- Irrigation ==> [Windmeter] - Windfeel is: " .. sWindFeel .. " ");
	end
	
--
-- Rainmeter data:
-- 

sRainmeterCurrent, sRainmeterTotal = otherdevices_svalues[rain]:match("([^;]+);([^;]+)")
 
sRainmeterCurrent = tonumber(sRainmeterCurrent);
sRainmeterTotal = tonumber(sRainmeterTotal);

	if logging >= 1 then
		print("-- Irrigation ==> [Rainmeter] - Actual rain is: " .. sRainmeterCurrent .. " ");
		print("-- Irrigation ==> [Rainmeter] - Total rain is: " .. sRainmeterTotal .. " ");
	end
	
--
-- UV data:
-- 

sUV, sSolar = otherdevices_svalues[uv]:match("([^;]+);([^;]+)")
 
sUV = tonumber(sUV);
sSolar = tonumber(sSolar);

	if logging >= 1 then
		print("-- Irrigation ==> [UV] - UV Strength is: " .. sUV .." ");
		print("-- Irrigation ==> [UV] - Solar radiation is: " .. sSolar .." ");
	end

if  sRainmeterCurrent >= tonumber (RainCurrent)
	and sWeatherTemp >= tonumber (WeatherTempMin)
	and sWeatherTemp <= tonumber (WeatherTempMax)
	and sUV <= tonumber (UVMax)
	and sWindSpeed <= tonumber (WindSpeed)
	and sWindGust <= tonumber (WindGust)
then

	if logging >= 1 then
		print("-- Irrigation ==> [Weather] - Weather conditions are looking good and ready for irrigation");
	end
	
	if(uservariables['VarWeatherCon'] == 0) then
	commandArray['Variable:VarWeatherCon']= '1'
    end
	
else

	if logging >= 1 then
		print("-- Irrigation [Info] ==> Weather conditions aren't looking good");
	end
	if(uservariables['VarWeatherCon'] == 1) then
	commandArray['Variable:VarWeatherCon']= '0'
	end	
end

if logging >= 1 then
	print("--------------------------------------------------------------------------------------")
end
	
--
-- **********************************************************
-- Scrapping Temparature and moist humidity from moist sensor
-- **********************************************************
--

--
-- Moist Sensor data:
-- 

    smoistsensorTemp, smoistsensorHumidity = otherdevices_svalues[MoistSensor]:match("([^;]+);([^;]+);([^;]+)")
    smoistsensorTemp = tonumber(smoistsensorTemp);
    smoistsensorHumidity = tonumber(smoistsensorHumidity);

	if logging >= 1 then
		print("Irrigation [PROGRAM - Moist Sensor and Moist Conditions]");
		print("-- Irrigation ==> [MoistSensor] - Moist Temperature: " .. smoistsensorTemp .. " ");
		print("-- Irrigation ==> [MoistSensor] - Moist Humidity: " .. smoistsensorHumidity .. " ");
	end
	
--
-- **********************************************************
-- Moist Sensor online check
-- **********************************************************
--	

if (smoistsensorTemp == 0 or smoistsensorTemp == nil) then
    print('-- Irrigation ==> [MoistSensor] - [ERROR] Moist Sensor reports Temp is 0 or nil. Skipping Irrigation')
	if(uservariables['VarMoistOnline'] == 1) then	
	commandArray['Variable:VarMoistOnline']= '0'
	end
		else
	if(uservariables['VarMoistOnline'] == 0) then		
	commandArray['Variable:VarMoistOnline']= '1'
	end
end

if (smoistsensorHumidity <= 6 or smoistsensorHumidity >= 99 or smoistsensorHumidity == nil) then
    print('-- Irrigation ==> [MoistSensor] - [Error] ==> Moist Sensor reports wrong Humidity values. Skipping Irrigation')
	if(uservariables['VarMoistOnlineHum'] == 1) then	
	commandArray['Variable:VarMoistOnlineHum']= '0'
	end
		else
	if(uservariables['VarMoistOnlineHum'] == 0) then		
	commandArray['Variable:VarMoistOnlineHum']= '1'
	end
end

--
-- **********************************************************
-- checking moist conditions
-- **********************************************************
--

if 	smoistsensorTemp >= tonumber (VarTarTempMin)
	and smoistsensorTemp <= tonumber (VarTarTempMax)
then

	if logging >= 1 then
		print("-- Irrigation ==> [MoistSensor] - Moist Temp conditions are fine for irrigation");
	end
	if(uservariables['VarMoistConTemp'] == 0) then
	commandArray['Variable:VarMoistConTemp']= '1'
	end
	
else
	if logging >= 1 then
	print("-- Irrigation ==> [MoistSensor] - Moist Temp conditions aren't good enough for irrigation");
	end
	if(uservariables['VarMoistConTemp'] == 1) then
	commandArray['Variable:VarMoistConTemp']= '0'
	end
end


if smoistsensorHumidity <= tonumber (VarTarHum)
then

	if logging >= 1 then
		print("-- Irrigation ==> [MoistSensor] - Moist humidity conditions are fine for irrigation");
	end
	if(uservariables['VarMoistConHum'] == 0) then
	commandArray['Variable:VarMoistConHum']= '1'
	end
	
else
	if logging >= 1 then
	print("-- Irrigation ==> [MoistSensor] - Moist humidity conditions aren to high, no irrigation required");
	end
	if(uservariables['VarMoistConHum'] == 1) then
	commandArray['Variable:VarMoistConHum']= '0'
	end
end
		
if logging >= 1 then
	print("--------------------------------------------------------------------------------------")
end

--
-- **********************************************************
-- Checking Time Frame 
-- **********************************************************
--

	if logging >= 1 then
		print("Irrigation [PROGRAM - TimeFrame]");	
	end	

if day == VarDay1 or day == VarDay2 or day == VarDay3 or day == VarDay4 or day == VarDay5 or day == VarDay6 or day == VarDay7 or
   month == VarMonth1 or month == VarMonth2	or month == VarMonth3 or month == VarMonth4 or month == VarMonth5 or month == VarMonth6 or month == VarMonth7 or month == VarMonth8 or month == VarMonth9 or month == VarMonth10 or month == VarMonth11 or month == VarMonth12
then
	if logging >= 1 then
		print("-- Irrigation ==> [TimeFrame] - TimeFrame does match your desired TimeFrame");
	end
	
	if(uservariables['VarTimeFrame'] == 0) then
	commandArray['Variable:VarTimeFrame']= '1'
	end

else

	if logging >= 1 then
		print("-- Irrigation ==> [TimeFrame] - TimeFrame doesn't match your desired TimeFrame");
	end
	
	if(uservariables['VarTimeFrame'] == 1) then
	commandArray['Variable:VarTimeFrame']= '0'
	end	
end	

--
-- **********************************************************
-- checking time of the day so irrigation may proceed 
-- **********************************************************
--

	if (time.hour >= 7) and (time.hour <= 11) then
		if  (uservariables['VarTimeOfDayCurrent'] ~= 0) then
				commandArray['Variable:VarTimeOfDayCurrent']= '0'
			end
	end

	if (time.hour >= 12) and (time.hour <= 18) then
		if (uservariables['VarTimeOfDayCurrent'] ~= 1) then
			commandArray['Variable:VarTimeOfDayCurrent']= '1'
		end	
	end

	if (time.hour >= 19) and (time.hour <= 22) then
		if (uservariables['VarTimeOfDayCurrent'] ~= 2) then
			commandArray['Variable:VarTimeOfDayCurrent']= '2'
		end
	end

	if (time.hour >= 23) then
		if (uservariables['VarTimeOfDayCurrent'] ~= 3) then
			commandArray['Variable:VarTimeOfDayCurrent']= '3'
		end	
	end

	if (uservariables['VarTimeOfDayCurrent']) == tonumber (VarTimeOfDay) then
		if logging >= 1 then
		print("-- Irrigation ==> [TimeOfTheDay] - Time of the Day matches your desired irrigation value")
		end
	if (uservariables['VarTimeCon']) == 0 then
	commandArray['Variable:VarTimeCon']= '1'
	end
end



if (uservariables['VarTimeOfDayCurrent']) ~= tonumber (VarTimeOfDay) then
		if logging >= 1 then
		print("-- Irrigation ==> [TimeOfTheDay] - Time of the Day doesnt match your criteria, Awaiting for the right Time of the Day")
		end
	if (uservariables['VarTimeCon']) == 1 then
	commandArray['Variable:VarTimeCon']= '0'
	end
end

if logging >= 1 then
	print("--------------------------------------------------------------------------------------")
end
	if logging >= 1 then
		print("Irrigation [Program]");	
	end	
--
-- **********************************************************
-- Giving the irrigation program a Go or NoGo
-- **********************************************************
--
	
	if (uservariables['VarTimeCon']) == 1
		and (uservariables['VarTimeFrame']) == 1 
		and (uservariables['VarWeatherCon']) == 1
		and (uservariables['VarMoistOnline']) == 1
		and (uservariables['VarMoistOnlineHum']) == 1		
		and (uservariables['VarMoistConTemp']) == 1
		and (uservariables['VarMoistOnlineHum']) == 1		
	then
		if logging >= 1 then
		print("-- Irrigation [Conditions] ==> All conditions seems to be okay, Irrigation may continue program")
		end
	if (uservariables['VarMayFollowProgram']) == 0 
    then
		commandArray['Variable:VarMayFollowProgram']= '1'
	end
	
	else
		if logging >= 1 then
		print("-- Irrigation [Conditions] ==> Not all conditions seems to be okay, Irrigation may NOT continue program")
		end
	if (uservariables['VarMayFollowProgram']) == 1 
    then
		commandArray['Variable:VarMayFollowProgram']= '0'
	end	
	end
	
	--
-- **********************************************************
-- New irrigation reactivated
-- **********************************************************
--

if (uservariables['VarMayFollowProgram']) == 1
	and (uservariables['VarProgramRun']) == 0
	and (uservariables['VarProgramOverride']) == 0
	and (uservariables['VarManOverrideCon']) == 0
	then 
if (uservariables['VarFollowsProgram']) == 0 then	
	commandArray['Variable:VarFollowsProgram']= '1'
		
end
		if logging >= 1 then
		print("-- Irrigation [Program] ==> Irrigation Program Activated...")
		print("--------------------------------------------------------------------------------------")
end	
end
	
	

--
-- **********************************************************
-- Irrigation stopped after a full run cycle
-- **********************************************************
--
if (uservariables['VarProgramRun']) == 1
	and (uservariables['VarProgramOverride']) == 1
then
	if logging >= 1 then
		print("-- Irrigation [Program] ==> Irrigation Stopped, Maximum RunTime Exceeded...")
		print("-- Irrigation [Program] ==> Awaiting new TimeFrame...")
		print("--------------------------------------------------------------------------------------")
	end
end

--
-- **********************************************************
-- New timeframe so irrigation reactivated
-- **********************************************************
--

if (uservariables['VarTimeCon']) == 0
	and (uservariables['VarProgramRun']) == 1
	and (uservariables['VarProgramOverride']) == 1
	then 
if (uservariables['VarProgramOverride']) == 1 then	
	commandArray['Variable:VarProgramOverride']= '0'
		commandArray['Variable:VarProgramRun']= '0'
		
end
		if logging >= 1 then
		print("-- Irrigation [Program] ==> Irrigation Program Reactivated...")
		print("--------------------------------------------------------------------------------------")
end	
end

--
-- **********************************************************
-- Irrigation stoppen as the moist humidity exceed your desired value
-- **********************************************************
--

if smoistsensorHumidity >= tonumber (VarTarHum)
	and (uservariables['VarProgramRun']) == 1
	then 
if (uservariables['VarProgramOverride']) == 0 then	
	commandArray['Variable:VarProgramOverride']= '1'
	commandArray['Variable:VarMaxRunTime']= '-1000'
	commandArray['Variable:VarProgramRun']= '0'
	commandArray[VarPump]='Off'
end
		if logging >= 1 then
		print("-- Irrigation [Program] ==> Irrigation Program Stopped, Moist Humidity exceeded your desired value...")
		print("--------------------------------------------------------------------------------------")
end	
end 

--
-- **********************************************************
-- Irrigation stoppen, Manual Override
-- **********************************************************
--

if otherdevices[VitManOverride] == 'On'
	and (uservariables['VarManOverrideCon']) == 0
	then 
if (uservariables['VarProgramOverride']) == 0 then	
	commandArray['Variable:VarProgramOverride']= '1'
	commandArray['Variable:VarMaxRunTime']= '-1000'
	commandArray['Variable:VarProgramRun']= '0'
	commandArray[VarPump]='Off'
	commandArray['Variable:VarManOverrideCon']= '1'
end	
end 

if otherdevices[VitManOverride] == 'On'
	and (uservariables['VarManOverrideCon']) == 1
	then 
		if logging >= 1 then
		print("-- Irrigation [Program] ==> Irrigation Program Stopped, Manual Override")
		print("--------------------------------------------------------------------------------------")	
end 
end

if otherdevices[VitManOverride] == 'Off'
	and (uservariables['VarManOverrideCon']) == 1
	then 
if (uservariables['VarProgramOverride']) == 1 then	
	commandArray['Variable:VarProgramOverride']= '0'
	commandArray['Variable:VarMaxRunTime']= '-1000'
	commandArray['Variable:VarProgramRun']= '0'
	commandArray['Variable:VarFollowsProgram']= '0'
	commandArray['Variable:VarManOverrideCon']= '0'
	commandArray[VarPump]='Off'
			print("-- Irrigation [Program] ==> Irrigation Program Reactivated, Manual Override OFF")
		print("--------------------------------------------------------------------------------------")	
end	
end 

--
-- **********************************************************
-- Irrigation Counter MaxRunTime and validate check
-- **********************************************************
--

--
-- Debug logging.
--
function debug(msg)

	if logging >= 1 then
		print('-- Irrigation [DEBUG] ==> ' .. msg)
	end

end

--
-- Info logging.
--
function info(msg)

	if logging >= 1 then
		print('-- Irrigation [Program] ==> ' .. msg)
	end

end

--
-- Error logging.
--
function error(msg)

	print('-- Irrigation [ERROR] ==> ' .. msg)

end

--
-- Validates the configuration
--
function validate() 

	result = true

	if not (uservariables['VarMaxRunTime']) then
		error('User Variable [' .. VarMaxRunTime .. '] doesnt exist.')
		result = false
	end
	
	if not otherdevices[VarPump] then
		error('Device [' .. VarPump .. '] doesnt exist.')
		result = false
	end
	 
	if not (uservariables['VarFollowsProgram']) then
		error('User Variable [' .. VarFollowsProgram .. '] doesnt exist.')
		result = false
	end 


	return result

end

--
-- Tests if irrigation may start.
--
function may_update(VarIsPump)

	counter = (uservariables['VarMaxRunTime'])
	current_counter = counter
	
	-- set the counter.
	if VarIsPump and counter >= 0 then
		counter = math.min(1, counter + 1)
	elseif not VarIsPump and counter <= 0 then
		counter = math.max(VarMaxRunTime_off * -1, counter - 1)
	else
		counter = 0
	end

	if counter ~= current_counter then
		commandArray['Variable:VarMaxRunTime']= tostring(counter)
	end

	result = false
		
	if VarIsPump and counter >= 1 then
		result = true
	elseif not VarIsPump and math.abs(counter) >= VarMaxRunTime_off then
		result = true
	end
	
	return result

end

--
-- Start irrigation
--

function on_off(VarIsPump)

	update_allowed = may_update(VarIsPump)

	info('Irrigation Pump = [' .. otherdevices[VarPump] .. ']')

	if update_allowed then
		if otherdevices[VarPump] == 'Off' and VarIsPump then
 			commandArray[VarPump]='On'
			commandArray['Variable:VarFollowsProgram']= '0'
			commandArray['Variable:VarProgramRun']= '1'
		elseif (otherdevices[VarPump] == 'On' and not VarIsPump) then
 			commandArray[VarPump]='Off'
			commandArray['Variable:VarProgramOverride']= '1'
			
	end

end
end
--
-- Is Irrigation  On.
--

function is_VarFollowsProgram_aan()

	result = false
	result = (uservariables['VarFollowsProgram'] == 1)
    return result
end
--
-- **********************************************************
-- Starting Irrigation
-- **********************************************************
--
if validate() then
	on_off(is_VarFollowsProgram_aan())
end

		if logging >= 1 then
		print("--------------------------------------------------------------------------------------")
	end

return commandArray

Re: [DIY] Garden irrigation and learning project

Posted: Monday 29 June 2015 13:47
by Siewert308SW
Here a updated version for dutch users.
Now i integrated the IsItGonnaRain script by Hans van der Heijden into mine.
So when there is rain expected within 24hr and more then you set in the settings then the Irrigation program is set to standby.
Also when the irrigation is running and there is more rain expected then you set in the settings then the irrigation will be stopped.

I also changed the Soil Moist Humidity trigger.
Irrigation will now be activated when a minimum humidity target is reached and irrigation will stop when the maximum is reached.

Code: Select all

--[[

	script_time_irrigation.lua
	@author: Siewert Lameijer
	@since: 2015-06-24
	@version: 1.0
	
	
Garden Irrigation script 

User Variable to create:
- VarManOverride (type=integer, value=0)
- VarTimeCon (type=integer, value=0)
- VarWeatherCon (type=integer, value=0)
- VarTimeOfDayCurrent (type=integer, value=0)
- VarMayFollowProgram (type=integer, value=0)
- VarFollowsProgram (type=integer, value=0)
- VarMaxRunTime (type=integer, value=0)
- VarMoistOnline (type=integer, value=0)
- VarMoistOnlineHum (type=integer, value=0)
- VarMoistConTemp (type=integer, value=0)
- VarMoistConHum (type=integer, value=0)
- VarProgramOverride (type=integer, value=0)
- VarProgramRun (type=integer, value=0)
- VarTimeFrame (type=integer, value=0)
- VarManOverrideCon (type=integer, value=0)
- VarBuienRadarCon (type=integer, value=0)

Virtual Switches
- Manual Override

Hardware:
1x Moist Sensor which measures Temperature and Humdity
1x WeatherUnderground
1x Switch for wireless controled WaterPump for irrigation

--]]

time = os.date("*t")
	commandArray = {}
--
-- **********************************************************
-- Settings Begin
-- **********************************************************
--

-- Lua script interval check, change the number 1 to every desired number in minutes
--if((time.min % 1)==0)then

-- Logging: 0 = Off, 1 = On
local logging = 1

--
-- **********************************************************
-- Location and minimum Rain Fall Variables For BuienRadar
-- **********************************************************
-- 

-- Set your location by adding Lat/Lon
local lat = '53.338023'
local lon = '6.303114'

-- Set your minimum rain fall for in a periode of 24hr 
local  VarMaxRainFall = '10'

--
-- **********************************************************
-- WeatherUnderGround Variables
-- **********************************************************
-- 
-- Name of your Weatherstation widget which contains humidity,uv,temp and pressure
local weatherstation = 'Barometer'

-- Name of your Weatherstation Wind widget
local wind = 'Wind'

-- Name of your Weatherstation Rain widget
local rain = 'Regenmeter'

-- Name of your Weatherstation UV widget
local uv = 'UV'

--
-- **********************************************************
-- Switches and Virtual Switches Variables
-- **********************************************************
--
-- Name of your manual override virtual switch
local VitManOverride = 'Irrigatie Manual Override'

-- Name of your irrigation switch for water valve 1
local VarPump = 'Irrigatie 1 Check'

--
-- **********************************************************
-- Moist Sensor Variables
-- **********************************************************
-- 
-- Name of your Moist Sensor device
local MoistSensor = 'Vocht Sensor (border 1)'

-- Your target soil humidity percentage
local VarTarHum = '80'

-- Your minumim moist humidity percentage from which the irrigation will start
local VarMinHum = '55'

-- Your Minumum soil temperature, Lower won't trigger irrigation
local VarTarTempMin = '12'

-- Your Maximum soil temperature, Higher won't trigger irrigation
local VarTarTempMax = '25'

-- Amount of minuten/times we want to switch OFF irrigation after the program has started.		
local VarMaxRunTime_off = 60

--
-- **********************************************************
-- Day, Month and Time Variables
-- **********************************************************
--
-- Set your desired TimeOfDay for irrigation (Morning=0, Afternoon=1, Evening=2 or Night=3)
local VarTimeOfDay = '2'

-- Set your desired irrigation day, leave blank for no irrigation, set Mon, Tue, Wed, Thu, Fri, Sat or Sun
local VarDay1 = 'Mon'

local VarDay2 = ''

local VarDay3 = 'Wed'

local VarDay4 = ''

local VarDay5 = 'Fri'

local VarDay6 = ''

local VarDay7 = 'Sun'

-- Set your desired irrigation month, leave blank for no irrigation, set a number like 1 for January or 5 for May
local VarMonth1 = ''

local VarMonth2 = ''

local VarMonth3 = ''

local VarMonth4 = '4'

local VarMonth5 = '5'

local VarMonth6 = '6'

local VarMonth7 = '7'

local VarMonth8 = '8'

local VarMonth9 = '9'

local VarMonth10 = ''

local VarMonth11 = ''

local VarMonth12 = ''

--
-- **********************************************************
-- Weather Variables
-- **********************************************************
-- 
-- Set your prefered max rain fall, higher won't trigger irrigation
local RainCurrent = '0'

-- Set your prefered minimum outside temperature for irrigation, Lower won't trigger irrigation
local WeatherTempMin = '13'

-- Set your prefered maximum outside temperature for irrigation, Higher won't trigger irrigation
local WeatherTempMax = '25'

-- Set your prefered maximum UV for irrigation, Higher won't trigger irrigation
local UVMax = '6'

-- Set your prefered max windspeed km/h, higher won't trigger irrigation
local WindSpeed = '50'

-- Set your prefered max windgust km/h, higher won't trigger irrigation
local WindGust = '150'


--
-- **********************************************************
-- Settings END
-- **********************************************************
--

--[[
--> Don't edit anything below this line or you could break the script!
--]]

    week       = tonumber(os.date("%V"));
	month       = tonumber(os.date("%m"));
    dayno       = tonumber(os.date("%d"));
    dayofweekno = tonumber(os.date("%w"));
    day       = tostring(os.date("%a"));
    hour       = tonumber(os.date("%H"));
    min       = tonumber(os.date("%M"));
	
--
-- **********************************************************
-- Scrapping Weather Data from WeatherUnderground
-- **********************************************************
--

--
-- Weatherstation data:
-- 

sWeatherTemp, sWeatherHumidity, sWeatherUV, sWeatherPressure, sWeatherUV2 = otherdevices_svalues[weatherstation]:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
sWeatherTemp = tonumber(sWeatherTemp);
sWeatherHumidity = tonumber(sWeatherHumidity);
sWeatherUV = tonumber(sWeatherUV);
sWeatherPressure = tonumber(sWeatherPressure);
sWeatherUV2 = tonumber(sWeatherUV2);


	if logging >= 1 then
		print("--------------------------------------------------------------------------------------")
		print("Irrigation [PROGRAM - Weather Conditions]");
		print("-- Irrigation ==> [WeatherStation] - Temperature is " .. sWeatherTemp .. " ");
		print("-- Irrigation ==> [WeatherStation] - Humidity is " .. sWeatherHumidity .. " ");
		print("-- Irrigation ==> [WeatherStation] - UV is " .. sWeatherUV .. " ");
		print("-- Irrigation ==> [WeatherStation] - Pressure is " .. sWeatherPressure .. " ");
		print("-- Irrigation ==> [WeatherStation] - UV2 is " .. sWeatherUV2 .. " ");
	end
	
--
-- Windmeter data:
-- 

sWindDirectionDegrees, sWindDirection, sWindSpeed, sWindGust, sWindTemperature, sWindFeel = otherdevices_svalues[wind]:match("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
 
sWindDirectionDegrees = tonumber(sWindDirectionDegrees);
sWindDirection = (sWindDirection);
sWindSpeed = tonumber(sWindSpeed);
sWindGust = tonumber(sWindGust);
sWindTemperature = tonumber(sWindTemperature);
sWindFeel = tonumber(sWindFeel);

	if logging >= 1 then
		print("-- Irrigation ==> [Windmeter] - Winddirection (in degrees) is: " .. sWindDirectionDegrees .. " ");
		print("-- Irrigation ==> [Windmeter] - Winddirection is: " .. sWindDirection .. " ");
		print("-- Irrigation ==> [Windmeter] - Windspeed is: " .. sWindSpeed .. " ");
		print("-- Irrigation ==> [Windmeter] - Windgust is: " .. sWindGust .. " ");
		print("-- Irrigation ==> [Windmeter] - Windtemperature is: " .. sWindTemperature .. " ");
		print("-- Irrigation ==> [Windmeter] - Windfeel is: " .. sWindFeel .. " ");
	end
	
--
-- Rainmeter data:
-- 

sRainmeterCurrent, sRainmeterTotal = otherdevices_svalues[rain]:match("([^;]+);([^;]+)")
 
sRainmeterCurrent = tonumber(sRainmeterCurrent);
sRainmeterTotal = tonumber(sRainmeterTotal);

	if logging >= 1 then
		print("-- Irrigation ==> [Rainmeter] - Actual rain is: " .. sRainmeterCurrent .. " ");
		print("-- Irrigation ==> [Rainmeter] - Total rain is: " .. sRainmeterTotal .. " ");
	end
	
--
-- UV data:
-- 

sUV, sSolar = otherdevices_svalues[uv]:match("([^;]+);([^;]+)")
 
sUV = tonumber(sUV);
sSolar = tonumber(sSolar);

	if logging >= 1 then
		print("-- Irrigation ==> [UV] - UV Strength is: " .. sUV .." ");
		print("-- Irrigation ==> [UV] - Solar radiation is: " .. sSolar .." ");
	end

if  sRainmeterCurrent >= tonumber (RainCurrent)
	and sWeatherTemp >= tonumber (WeatherTempMin)
	and sWeatherTemp <= tonumber (WeatherTempMax)
	and sUV <= tonumber (UVMax)
	and sWindSpeed <= tonumber (WindSpeed)
	and sWindGust <= tonumber (WindGust)
then

	if logging >= 1 then
		print("-- Irrigation ==> [Weather] - Weather conditions are looking good and ready for irrigation");
	end
	
	if(uservariables['VarWeatherCon'] == 0) then
	commandArray['Variable:VarWeatherCon']= '1'
    end
	
else

	if logging >= 1 then
		print("-- Irrigation [Info] ==> Weather conditions aren't looking good");
	end
	if(uservariables['VarWeatherCon'] == 1) then
	commandArray['Variable:VarWeatherCon']= '0'
	end	
end

if logging >= 1 then
	print("--------------------------------------------------------------------------------------")
end
	
--
-- **********************************************************
-- Scrapping Temparature and moist humidity from moist sensor
-- **********************************************************
--

--
-- Moist Sensor data:
-- 

    smoistsensorTemp, smoistsensorHumidity = otherdevices_svalues[MoistSensor]:match("([^;]+);([^;]+);([^;]+)")
    smoistsensorTemp = tonumber(smoistsensorTemp);
    smoistsensorHumidity = tonumber(smoistsensorHumidity);

	if logging >= 1 then
		print("Irrigation [PROGRAM - Moist Sensor and Moist Conditions]");
		print("-- Irrigation ==> [MoistSensor] - Moist Temperature: " .. smoistsensorTemp .. " ");
		print("-- Irrigation ==> [MoistSensor] - Moist Humidity: " .. smoistsensorHumidity .. " ");
	end
	
--
-- **********************************************************
-- Moist Sensor online check
-- **********************************************************
--	

if (smoistsensorTemp == 0 or smoistsensorTemp == nil) then
    print('-- Irrigation ==> [MoistSensor] - [ERROR] Moist Sensor reports Temp is 0 or nil. Skipping Irrigation')
	if(uservariables['VarMoistOnline'] == 1) then	
	commandArray['Variable:VarMoistOnline']= '0'
	end
		else
	if(uservariables['VarMoistOnline'] == 0) then		
	commandArray['Variable:VarMoistOnline']= '1'
	end
end

if (smoistsensorHumidity <= 6 or smoistsensorHumidity >= 99 or smoistsensorHumidity == nil) then
    print('-- Irrigation ==> [MoistSensor] - [Error] ==> Moist Sensor reports wrong Humidity values. Skipping Irrigation')
	if(uservariables['VarMoistOnlineHum'] == 1) then	
	commandArray['Variable:VarMoistOnlineHum']= '0'
	end
		else
	if(uservariables['VarMoistOnlineHum'] == 0) then		
	commandArray['Variable:VarMoistOnlineHum']= '1'
	end
end

--
-- **********************************************************
-- checking moist conditions
-- **********************************************************
--

if 	smoistsensorTemp >= tonumber (VarTarTempMin)
	and smoistsensorTemp <= tonumber (VarTarTempMax)
then

	if logging >= 1 then
		print("-- Irrigation ==> [MoistSensor] - Moist Temp conditions are fine for irrigation");
	end
	if(uservariables['VarMoistConTemp'] == 0) then
	commandArray['Variable:VarMoistConTemp']= '1'
	end
	
else
	if logging >= 1 then
	print("-- Irrigation ==> [MoistSensor] - Moist Temp conditions aren't good enough for irrigation");
	end
	if(uservariables['VarMoistConTemp'] == 1) then
	commandArray['Variable:VarMoistConTemp']= '0'
	end
end


if smoistsensorHumidity <= tonumber (VarMinHum) or smoistsensorHumidity == tonumber (VarMinHum)
then

	if logging >= 1 then
		print("-- Irrigation ==> [MoistSensor] - Your Soil is dry and needs irrigation");
	end
	if(uservariables['VarMoistConHum'] == 0) then
	commandArray['Variable:VarMoistConHum']= '1'
	end
	
else
	if logging >= 1 then
	print("-- Irrigation ==> [MoistSensor] - Soil humidity is fine, no irrigation required");
	end
	if(uservariables['VarMoistConHum'] == 1) then
	commandArray['Variable:VarMoistConHum']= '0'
	end
end
		
	if logging >= 1 then
		print("--------------------------------------------------------------------------------------")
	end

--
-- **********************************************************
-- Checking Buienradar 
-- **********************************************************
--

	if logging >= 1 then
		print("Irrigation [PROGRAM - Buienradar]");	
	end	
	

    tempfilename = '/var/tmp/rain.tmp'
    totalrain = 0
    rainlines = 0	
	
	
   function IsItGonnaRain( minutesinfuture )
       url='http://gps.buienradar.nl/getrr.php?lat='..lat..'&lon='..lon
       read = os.execute('curl -s -o '..tempfilename..' "'..url..'"')
       file = io.open(tempfilename, "r")

       while true do
          line = file:read("*line")
          if not line then break end
          linetime=string.sub(tostring(line), 5, 9)
          linetime2 = os.time{year=os.date('%Y'), month=os.date('%m'), day=os.date('%d'), hour=string.sub(linetime,1,2), min=string.sub(linetime,4,5), sec=os.date('%S')}
          difference = os.difftime (linetime2,os.time())

          if ((difference > 0) and (difference<=minutesinfuture*60)) then
             rain=tonumber(string.sub(tostring(line), 0, 3))
             totalrain = totalrain+rain
             rainlines=rainlines+1
          end

       end
       file:close()
       
       averagerain=totalrain/rainlines
       return(averagerain)
    end

    function round(num, idp)
       local mult = 10^(idp or 0)
       return math.floor(num * mult + 0.5) / mult
    end

--
-- **********************************************************
-- Is it gonna rain for the upcoming 24hr YES/NO
-- **********************************************************
--

       minutes=1440
       RainPrediction = IsItGonnaRain(minutes)
       RainmmHour=10^((RainPrediction-109)/32)

       if RainPrediction >= tonumber (VarMaxRainFall) then
          verw = 3
		  if (uservariables['VarBuienRadarCon']) == 1  then
		  commandArray['Variable:VarBuienRadarCon']= '0'
		  end
		  if logging >= 1 then  
			print('-- Irrigation ==> [RAIN] - Expected '..RainPrediction..' within 24 hours.')
		  end
       else
          verw = 2

		  if (uservariables['VarBuienRadarCon']) == 0  then
		  commandArray['Variable:VarBuienRadarCon']= '1'
		  end
		  if logging >= 1 then 
			print('-- Irrigation ==> [RAIN] - No rain or little rain expected within 24 hours.')
		  end		  
       end
	
	if logging >= 1 then
		print("--------------------------------------------------------------------------------------")
	end	

--
-- **********************************************************
-- Checking Time Frame 
-- **********************************************************
--

	if logging >= 1 then
		print("Irrigation [PROGRAM - TimeFrame]");	
	end	

if day == VarDay1 or day == VarDay2 or day == VarDay3 or day == VarDay4 or day == VarDay5 or day == VarDay6 or day == VarDay7 or
   month == VarMonth1 or month == VarMonth2	or month == VarMonth3 or month == VarMonth4 or month == VarMonth5 or month == VarMonth6 or month == VarMonth7 or month == VarMonth8 or month == VarMonth9 or month == VarMonth10 or month == VarMonth11 or month == VarMonth12
then
	if logging >= 1 then
		print("-- Irrigation ==> [TimeFrame] - TimeFrame does match your desired TimeFrame");
	end
	
	if(uservariables['VarTimeFrame'] == 0) then
	commandArray['Variable:VarTimeFrame']= '1'
	end

else

	if logging >= 1 then
		print("-- Irrigation ==> [TimeFrame] - TimeFrame doesn't match your desired TimeFrame");
	end
	
	if(uservariables['VarTimeFrame'] == 1) then
	commandArray['Variable:VarTimeFrame']= '0'
	end	
end	

--
-- **********************************************************
-- checking time of the day so irrigation may proceed 
-- **********************************************************
--

	if (time.hour >= 7) and (time.hour <= 11) then
		if  (uservariables['VarTimeOfDayCurrent'] ~= 0) then
				commandArray['Variable:VarTimeOfDayCurrent']= '0'
			end
	end

	if (time.hour >= 12) and (time.hour <= 18) then
		if (uservariables['VarTimeOfDayCurrent'] ~= 1) then
			commandArray['Variable:VarTimeOfDayCurrent']= '1'
		end	
	end

	if (time.hour >= 19) and (time.hour <= 22) then
		if (uservariables['VarTimeOfDayCurrent'] ~= 2) then
			commandArray['Variable:VarTimeOfDayCurrent']= '2'
		end
	end

	if (time.hour >= 23) then
		if (uservariables['VarTimeOfDayCurrent'] ~= 3) then
			commandArray['Variable:VarTimeOfDayCurrent']= '3'
		end	
	end

	if (uservariables['VarTimeOfDayCurrent']) == tonumber (VarTimeOfDay) then
		if logging >= 1 then
		print("-- Irrigation ==> [TimeFrame] - Time of the Day matches your desired irrigation value")
		end
	if (uservariables['VarTimeCon']) == 0 then
	commandArray['Variable:VarTimeCon']= '1'
	end
end



if (uservariables['VarTimeOfDayCurrent']) ~= tonumber (VarTimeOfDay) then
		if logging >= 1 then
		print("-- Irrigation ==> [TimeFrame] - Time of the Day doesnt match your criteria, Awaiting for the right Time of the Day")
		end
	if (uservariables['VarTimeCon']) == 1 then
	commandArray['Variable:VarTimeCon']= '0'
	end
end

if logging >= 1 then
	print("--------------------------------------------------------------------------------------")
end
	if logging >= 1 then
		print("Irrigation [Program]");	
	end	
--
-- **********************************************************
-- Giving the irrigation program a Go or NoGo
-- **********************************************************
--
	
	if (uservariables['VarTimeCon']) == 1
		and (uservariables['VarTimeFrame']) == 1 
		and (uservariables['VarWeatherCon']) == 1
		and (uservariables['VarMoistOnline']) == 1
		and (uservariables['VarMoistOnlineHum']) == 1		
		and (uservariables['VarMoistConTemp']) == 1
		and (uservariables['VarMoistOnlineHum']) == 1
		and (uservariables['VarBuienRadarCon']) == 1
		
	then
		if logging >= 1 then
		print("-- Irrigation [Conditions] ==> All conditions seems to be okay, Irrigation may continue program")
		end
	if (uservariables['VarMayFollowProgram']) == 0 
    then
		commandArray['Variable:VarMayFollowProgram']= '1'
	end
	
	else
		if logging >= 1 then
		print("-- Irrigation [Conditions] ==> Not all conditions seems to be okay, Irrigation may NOT continue program")
		end
	if (uservariables['VarMayFollowProgram']) == 1 
    then
		commandArray['Variable:VarMayFollowProgram']= '0'
	end	
	end
	
	--
-- **********************************************************
-- New irrigation reactivated
-- **********************************************************
--

if (uservariables['VarMayFollowProgram']) == 1
	and (uservariables['VarProgramRun']) == 0
	and (uservariables['VarProgramOverride']) == 0
	and (uservariables['VarManOverrideCon']) == 0
	then 
if (uservariables['VarFollowsProgram']) == 0 then	
	commandArray['Variable:VarFollowsProgram']= '1'
		
end
		if logging >= 1 then
		print("-- Irrigation [Program] ==> Irrigation Program Activated...")
		print("--------------------------------------------------------------------------------------")
end	
end
	
	

--
-- **********************************************************
-- Irrigation stopped after a full run cycle
-- **********************************************************
--
if (uservariables['VarProgramRun']) == 1
	and (uservariables['VarProgramOverride']) == 1
then
	if logging >= 1 then
		print("-- Irrigation [Program] ==> Irrigation Stopped, Maximum RunTime Exceeded...")
		print("-- Irrigation [Program] ==> Awaiting new TimeFrame...")
		print("--------------------------------------------------------------------------------------")
	end
end

--
-- **********************************************************
-- New timeframe so irrigation reactivated
-- **********************************************************
--

if (uservariables['VarTimeCon']) == 0
	and (uservariables['VarMayFollowProgram']) == 0
	and (uservariables['VarProgramOverride']) == 1
	then 
if (uservariables['VarProgramOverride']) == 1 then	
	commandArray['Variable:VarProgramOverride']= '0'
		commandArray['Variable:VarProgramRun']= '0'
		
end
		if logging >= 1 then
		print("-- Irrigation [Program] ==> Irrigation Program Reactivated...")
		print("--------------------------------------------------------------------------------------")
end	
end

--
-- **********************************************************
-- Irrigation stopped as the moist humidity exceed your desired value
-- **********************************************************
--

if smoistsensorHumidity >= tonumber (VarTarHum)
	and (uservariables['VarProgramRun']) == 1
	then 
if (uservariables['VarProgramOverride']) == 0 then	
	commandArray['Variable:VarProgramOverride']= '1'
	commandArray['Variable:VarMaxRunTime']= '-1000'
	commandArray['Variable:VarProgramRun']= '0'
	commandArray[VarPump]='Off'
end
		if logging >= 1 then
		print("-- Irrigation [Program] ==> Irrigation Program Stopped, Moist Humidity exceeded your desired value...")
		print("--------------------------------------------------------------------------------------")
		end	
end 

--
-- **********************************************************
-- Irrigation stoppen, Manual Override
-- **********************************************************
--

if otherdevices[VitManOverride] == 'On'
	and (uservariables['VarManOverrideCon']) == 0
	then 
if (uservariables['VarProgramOverride']) == 0 then	
	commandArray['Variable:VarProgramOverride']= '1'
	commandArray['Variable:VarMaxRunTime']= '-1000'
	commandArray['Variable:VarProgramRun']= '0'
	commandArray[VarPump]='Off'
	commandArray['Variable:VarManOverrideCon']= '1'
end	
end

--
-- **********************************************************
-- Irrigation stoppen, Rain Expected
-- **********************************************************
--

if (uservariables['VarBuienRadarCon']) == 0 and (uservariables['VarProgramRun']) == 1
	then 
if (uservariables['VarProgramOverride']) == 0 then	
	commandArray['Variable:VarProgramOverride']= '1'
	commandArray['Variable:VarMaxRunTime']= '-1000'
	commandArray['Variable:VarProgramRun']= '0'
	commandArray[VarPump]='Off'
	
		if logging >= 1 then
		print("-- Irrigation [Program] ==> Irrigation Program Stopped, Rain Expected...")
		print("--------------------------------------------------------------------------------------")
		end		
end	
end 

if (uservariables['VarBuienRadarCon']) == 1
	then 
if (uservariables['VarProgramOverride']) == 1 then	
	commandArray['Variable:VarProgramOverride']= '1'
	commandArray['Variable:VarMaxRunTime']= '-1000'
	commandArray['Variable:VarProgramRun']= '0'
	commandArray[VarPump]='Off'
	
		if logging >= 1 then
		print("-- Irrigation [Program] ==> Irrigation Program Reactivated, No More Rain Expected...")
		print("--------------------------------------------------------------------------------------")
		end		
end	
end 

--
-- **********************************************************
-- Irrigation stoppen, Manual Override
-- **********************************************************
--

if otherdevices[VitManOverride] == 'On'
	and (uservariables['VarManOverrideCon']) == 1
	then 
		if logging >= 1 then
		print("-- Irrigation [Program] ==> Irrigation Program Stopped, Manual Override")
		print("--------------------------------------------------------------------------------------")	
end 
end

if otherdevices[VitManOverride] == 'Off'
	and (uservariables['VarManOverrideCon']) == 1
	then 
if (uservariables['VarProgramOverride']) == 1 then	
	commandArray['Variable:VarProgramOverride']= '0'
	commandArray['Variable:VarMaxRunTime']= '-1000'
	commandArray['Variable:VarProgramRun']= '0'
	commandArray['Variable:VarFollowsProgram']= '0'
	commandArray['Variable:VarManOverrideCon']= '0'
	commandArray[VarPump]='Off'
			print("-- Irrigation [Program] ==> Irrigation Program Reactivated, Manual Override OFF")
		print("--------------------------------------------------------------------------------------")	
end	
end 

--
-- **********************************************************
-- Irrigation Counter MaxRunTime and validate check
-- **********************************************************
--

--
-- Debug logging.
--
function debug(msg)

	if logging >= 1 then
		print('-- Irrigation [DEBUG] ==> ' .. msg)
	end

end

--
-- Info logging.
--
function info(msg)

	if logging >= 1 then
		print('-- Irrigation [Program] ==> ' .. msg)
	end

end

--
-- Error logging.
--
function error(msg)

	print('-- Irrigation [ERROR] ==> ' .. msg)

end

--
-- Validates the configuration
--
function validate() 

	result = true

	if not (uservariables['VarMaxRunTime']) then
		error('User Variable [' .. VarMaxRunTime .. '] doesnt exist.')
		result = false
	end
	
	if not otherdevices[VarPump] then
		error('Device [' .. VarPump .. '] doesnt exist.')
		result = false
	end
	 
	if not (uservariables['VarFollowsProgram']) then
		error('User Variable [' .. VarFollowsProgram .. '] doesnt exist.')
		result = false
	end 


	return result

end

--
-- Tests if irrigation may start.
--
function may_update(VarIsPump)

	counter = (uservariables['VarMaxRunTime'])
	current_counter = counter
	
	-- set the counter.
	if VarIsPump and counter >= 0 then
		counter = math.min(1, counter + 1)
	elseif not VarIsPump and counter <= 0 then
		counter = math.max(VarMaxRunTime_off * -1, counter - 1)
	else
		counter = 0
	end

	if counter ~= current_counter then
		commandArray['Variable:VarMaxRunTime']= tostring(counter)
	end

	result = false
		
	if VarIsPump and counter >= 1 then
		result = true
	elseif not VarIsPump and math.abs(counter) >= VarMaxRunTime_off then
		result = true
	end
	
	return result

end

--
-- Start irrigation
--

function on_off(VarIsPump)

	update_allowed = may_update(VarIsPump)

	info('Irrigation Pump = [' .. otherdevices[VarPump] .. ']')

	if update_allowed then
		if otherdevices[VarPump] == 'Off' and VarIsPump then
 			commandArray[VarPump]='On'
			commandArray['Variable:VarFollowsProgram']= '0'
			commandArray['Variable:VarProgramRun']= '1'
		elseif (otherdevices[VarPump] == 'On' and not VarIsPump) then
 			commandArray[VarPump]='Off'
			commandArray['Variable:VarProgramOverride']= '1'
			
	end

end
end
--
-- Is Irrigation  On.
--

function is_VarFollowsProgram_aan()

	result = false
	result = (uservariables['VarFollowsProgram'] == 1)
    return result
end
--
-- **********************************************************
-- Starting Irrigation
-- **********************************************************
--
if validate() then
	on_off(is_VarFollowsProgram_aan())
end

	if logging >= 1 and (uservariables['VarMayFollowProgram']) == 0 
		and (uservariables['VarFollowsProgram']) == 0
		and (uservariables['VarProgramOverride']) == 0  
	then
		print("-- Irrigation [Standby] ==> Irrigation Program on Standby")
	end
	
	if logging >= 1 and (uservariables['VarMayFollowProgram']) == 1 
		and (uservariables['VarFollowsProgram']) == 0
		and (uservariables['VarProgramOverride']) == 1  
	then
		print("-- Irrigation [Standby] ==> Already Irrigated, Irrigation Program on Standby and awaiting new cycle")
	end	

		if logging >= 1 then
		print("--------------------------------------------------------------------------------------")
	end

return commandArray

Re: [DIY] Garden irrigation and learning project

Posted: Monday 29 June 2015 20:07
by Siewert308SW
@blackdog65

Your water valve, is it a f-11 or f14?
I can't find any reverence but i have a f-11 earlier this week i tried to fine tune the little sprinkler.
But i couldn't get the right. something block the pressure.
So i removed the regulator and that didn't help.
Then i connected the water supply directly to irrigation and all work with enough water pressure.
So i think the valve is decreasing the water pressure.

Re: [DIY] Garden irrigation and learning project

Posted: Monday 29 June 2015 22:38
by blackdog65
Do you mean this? :?
http://www.ebay.co.uk/itm/360771645775? ... EBIDX%3AIT

I'm not sure which type it is but I have problems with low pressure as I use rain water + pump. The drippler hose was pretty poor with low pressure so I tried this today
http://www.amazon.co.uk/Green-Porous-So ... ation+hose
and it works brilliantly! :D

Re: [DIY] Garden irrigation and learning project

Posted: Tuesday 30 June 2015 11:30
by Siewert308SW
blackdog65 wrote:Do you mean this? :?
http://www.ebay.co.uk/itm/360771645775? ... EBIDX%3AIT

I'm not sure which type it is but I have problems with low pressure as I use rain water + pump. The drippler hose was pretty poor with low pressure so I tried this today
http://www.amazon.co.uk/Green-Porous-So ... ation+hose
and it works brilliantly! :D
Yep, thats what i ment.
Looks like the valve decreases the pressure and over the entire 15mtr the water pressure is to low.
When i hook up the water supply directly to the irrigation then all is fine and i have enough water pressure.