Page 1 of 1

Simple script for garden relying on rain

Posted: Friday 09 June 2017 19:48
by qbusr
Hi,
I have three dummy switches which control my sprinkler valves (I have 3 loops in my garden) - i control my electrovalves via Wifi IoT Relay Board Based on ESP8266 and MQTT. Right now it is simple and working - i have group of those three switches (with on/off delays). But i would like to prevent EV from work if it has rained earlier (i would like to check it eg for 10hr). Right now i don't have any wheather station and rely on darksky wheather forecast. What I am thinking of is time LUa script, which would do something like that (pseudocode, I am not programmer (yet ;) ):

Code: Select all

--set variable in minutes, when my group should switch on, here 60 min before sunset

groupHeadStart = 60 

--set variable when to start monitoring rain, here for 10hr before sunset = 600 min

checkRainStart = 600

--set time when groups sets on

GroupStart = timeofday['SunsetInMinutes'] - groupHeadStart

--start checking if it has rained, my rain sensor from darkssky is called t1 and has idx = 6

timenow = os.date("*t")
minutesNow = timenow.min + timenow.hour * 60
if minutesNow >= GroupStart - chceckRainStart / if it is less than 10 hr to start the sprinkler group check if it has rained and set variable
   if t1 > 0 //i  have to values from my sensor, but i don't know what they are - i presume one is current raindrop
       set global variable itHasRained -> 1
   else
      pass

--turn on the group
if minutesNow == GroupStart
   if vglobal variable itHasRained == 0
      set group on
   else
       pass
--reset variable during the night 

if minutesNow ==0
 set global variable itHasRained -> 0

Could you help my with the lua code ? I am trying to get to know lua a little bit better

Re: Simple script for garden relying on rain

Posted: Saturday 10 June 2017 19:39
by zicht
You could make use of wetherunderground , what is fully supported by domoticz.
The wether station can be added in the hardware tab and then the devices would appear in the table ( dont forget to add them :) )

Then you can read the values with lua from the wethersensors that are visible.
You just have to find a station with reliable rain measurement in you neighbourhood.

For wether underground you need to subscribe (Free) and get an api key on the site, i believe someone made a wiki about it.
https://www.domoticz.com/wiki/Virtual_weather_devices