Balcony irrigation project

In this subforum you can show projects you have made, or you are busy with. Please create your own topic.

Moderator: leecollings

Post Reply
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Balcony irrigation project

Post by emme »

Ciao,

I have no luck with flowers and plant.
My balcony has poor sunlight and more I use to forgot to water them!

So I had the idea to use a standard irrigation computer, but I have no water on my balcony and more... I wish to have small vases with small plants

So I decided to start a project with Raspberry and implement it in Domoticz.
Unfortunately my domoticz server is quite too far from the balcony so I had to use a new raspberry and find a way to communicate with the Domoticz main server.

As first my intention is to use a second domoticz installation and configure it on the main one as a remote server.... but all these stuff a a second step

At the moment my hardware is:
Raspberry PI3
8Switch Relay
Custard PI3 (a ADC 8 port)
5x YL-38 soil moist sensors
12v Power suppy
6mm pipes, valves, connectors and stuff

The intention is to run the script once a day and update via API/Json the domoticz main server

Actually I have a 30lt water tank (that I should remember to fill sometimes!!!), few valves, a pump and this (uncomplete) pyhton script:

Code: Select all

import RPi.GPIO as GPIO
import urllib
from time import sleep

GPIO.setmode(GPIO.BCM)
# SETUP DOMOTICZ Parameters
DOMOIP = "192.168.0.40"
DOMOPORT = "8080"
DOMOVALVEIDX=[0,0,0,0,0,0,0,0] #IDX for domoticz Switch for valves
DOMOSOILIDX=[0,0,0,0,0,0,0,0] #IDX for Soil Moisture sensors in Domoticz
DOMOPUMPIDX = 0 #IDX for domoticz Switch for pump

# Setup loacl variables and PIN
WATER = 17     #PIN, value DIGITAL 0 (water ok) /1 (Add Water)
PUMP = 21           #PIN BCM to be set on OUTPUT 
VALVES =[0,0,0,0,0,0,0,0] #PINs used for 8 channel raly switch 
IRRTIME= [10,10,10,10,10,10,10,10] #irrigation time (in seconds) every zone has its own setup
SOILVALUE = [0,100, 250,190,10,175,90,255] #values gathered from the soil moist sensors and CustardPI3 interface
								#Actual values are for testing purpuse only
								
SOILACTIVE = 2  #Solo zone 1 e 2 attive # how many zones are active

#Setup GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(WATER,GPIO.IN)

GPIO.setup(PUMP,GPIO.OUT)
GPIO.output(PUMP,GPIO.LOW)

#GPIO.setup(VALVES,GPIO.OUT)
#GPIO.output(VALVES.GPIO.LOW)


# MISSING PART
# GET SOIL MOIST SENSORS VALUES FROM CUSTARDPI3



if GPIO.input(WATER) == 0:
    for idx in range(0,SOILACTIVE):
        if SOILVALUE[idx] < 129:
            print("Vaso: ",idx, " Umidità critica (",SOILVALUE[idx],") --> apertura valvola e pompa per ", IRRTIME[idx], "sec")
            GPIO.output(PUMP,GPIO.HIGH)
            #UPDATE DOMOTICZ SWITCH
            sleep(0.5)
            GPIO.output(VALVES[IDX],GPIO.HIGH)
            #UPDATE DOMOTICZ SWITCH
            sleep(IRRTIME[idx])
            GPIO.output(PUMP,GPIO.LOW)
            #UPDATE DOMOTICZ SWITCH
            GPIO.output(VALVES[IDX],GPIO.LOW)
            #UPDATE DOMOTICZ SWITCH
            print("OK!")
        else:
            print("Vaso: ",idx, " OK!(",SOILVALUE[idx],")")
    else:
    	    #SEND NOTIFICATION FOR MISSING WATER
GPIO.cleanup()

I'm not a coder, nor a programmer.... as soon as my implementation is completed I will fill the missing parts and add some pics...
but... I wish to get your opinion about :P :P

ciao
M
The most dangerous phrase in any language is:
"We always done this way"
Amsterdam020
Posts: 55
Joined: Saturday 05 March 2016 21:42
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5629
Contact:

Re: Balcony irrigation project

Post by Amsterdam020 »

Some people use a Soil Humidity Tester, this will inform you whether or not you should water.
http://www.domoticz.com/forum/viewtopic ... oil#p94215
You still have to water manually, but the implementation is fare easier.
Rp3, youlesss, rfxcom, philips hue, dsb1820
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Balcony irrigation project

Post by emme »

Amsterdam020 wrote:Some people use a Soil Humidity Tester, this will inform you whether or not you should water.
viewtopic.php?f=44&t=13078&p=94215&hilit=soil#p94215
You still have to water manually, but the implementation is fare easier.
thank you!

I'll give it a try since I'm not really satified by the YL-69 sensor


..the project is almost finished... running in "beta" since few days... (I'll post the scripts this evening as I get back home :P)

At the end I moved to this structure:

- Create several Soil moist virtual sensors in Domoticz
- Create several virtual Switches (ON/OFF) in Domoticz (one for the pump, others for the zones/vases)
- Create a vitual Push ON button to force irrigation (if needed/test)
- Create user variable for timeON timeOFF irrigation

there are 2 scripts on the remote rb:
GetSoil.py that reads the analogue sensors and update the soil value in Domoticz
Irrigate.py that reads the analogue sensors, update the soil value in Domoticz, take action if needed (watering)
Both refers to a setting file named config.py that it needed to be in the same directory

GetSoil.py have been scheduled to run con cron every 10 minutes
Irrigate.py is not on cron and is invoked by Domoticz based on the timing (via ssh call)

The values in CB are calculated as follow:
Custard Pi3 is a 8 channel, 12bit ADC, each channel is connected to a YL69, so every channel return a value from 0 (contact almost closed) to 4095 (contact almost open)
cb runs from 0 (really wet) to 200 (reallr DRY)
So I simply convert the scale: (value * 200) / 4095

I'm not really enthusiastic about YL-69 and CustardPI3 card... values are not really accurate... and I gave gap of 50/60cb that can trigger watering when it is not needed... this is a bit annoyng... if someone has a trick for it it would be appreciated :P :P (using a rfxcom device will need I parse the values from Domoticz... and I'm not really sure I'm able to :P)

ciao
M

Here are the scripts:

GetSoil.py

Code: Select all

#!/usr/bin/ python

import config
import RPi.GPIO as GPIO
from time import sleep
import urllib2

# Setting up GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)

# Setting up Water and Pump
GPIO.setup(config.WATER,GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(config.PUMP,GPIO.OUT)

# Setting up valves
for idx in range(0,8):
        if config.VALVES[idx] !=0:
                GPIO.setup(config.VALVES[idx],GPIO.OUT)
                GPIO.output(config.VALVES[idx],GPIO.HIGH)

# Setting up CustardPI3
# Custard PI3 uses specific PINs
# So no need to set them up in config.py file
GPIO.setup(24, GPIO.OUT)        # chip enable
GPIO.setup(23, GPIO.OUT)        # clock
GPIO.setup(19, GPIO.OUT)        # data out
GPIO.setup(21, GPIO.IN)         # data in

# CustardPI3 default setup (grabbed from their site)
GPIO.output(24, True)
GPIO.output(23, False)
GPIO.output(19, True)

# Beginning CustardPi3 Reading channels procedure
# All these have been grabbed from their Website

for y in range (0,8):
        if y == 0:
                word = [1,1,0,0,0,1,1]  # Setting up channel0 (pin 1)
        if y == 1:
                word = [1,1,0,0,1,1,1]  # Setting up channel0 (pin 1)
        if y == 2:
                word = [1,1,0,1,0,1,1]  # Setting up channel0 (pin 1)
        if y == 3:
                word = [1,1,0,1,1,1,1]  # Setting up channel0 (pin 1)
        if y == 4:
                word = [1,1,1,0,0,1,1]  # Setting up channel0 (pin 1)
        if y == 5:
                word = [1,1,1,0,1,1,1]  # Setting up channel0 (pin 1)
        if y == 6:
                word = [1,1,1,1,0,1,1]  # Setting up channel0 (pin 1)
        if y == 7:
                word = [1,1,1,1,1,1,1]  # Setting up channel0 (pin 1)

        GPIO.output(24, False)  #chip enable

        for x in range (0,7):   # Sending channel selection
                GPIO.output(19, word[x])
                sleep(0.03)
                GPIO.output(23, True)   # sending clock
                sleep(0.03)
                GPIO.output(23, False)

        VALUE = ""

        for x in range(0,12):   # Getting back info in 12bit string
                GPIO.output(23, True)   # Sending clock
                sleep(0.03)
                bit = GPIO.input(21)    # Reading data bit
                sleep(0.03)
                GPIO.output(23, False)  # Sending Clock
                VALUE = str(VALUE) + str(bit)   # Generatig 12 Bit binary string

        GPIO.output(24, True)   # Chip Disable
        print "Canale: ", y
        print "Stringa Acquisita --> ", VALUE
        VALUE = int(VALUE,2)    # Converting Binary to Dec
        print "Conversione BIN2DEC -->", VALUE
        VALUE = (((VALUE-100)*200)/4096)
        print "Conversione cb: ", VALUE

        #updating domoticz Soil Moisture area (y)
        url = 'http://' + config.DOMOIP +':' + config.DOMOPORT + '/json.htm?type=command&param=udevice&nvalue=' + str(config.SOILVALUE[y]) + '&idx=' + str(config.DOMOSOILS[y]) + '&svalue=' + str(config.SOILVALUE[y])
        request = urllib2.Request(url)
        response = urllib2.urlopen(request)
        
GPIO.cleanup()
config.py

Code: Select all

#!/usr/bin/ python

# Config file for Soil Moist zones
# Integrated with Dommoticz local server


# Domoticz Server config
DOMOIP = "192.168.0.40"
DOMOPORT = "8080"
# If you do not whitelist the local ip in Domoticz, complete these
DOMOUSER = "username"
DOMOPASS = "password"

# Setup Domoticz IDX for vales, pump and soils in order to allow them to be correctly setted ON and OFF
DOMOPUMP = 442
DOMOSOIL = [377,378,0,0,0,0,0,0]
DOMOVALVES = [443,444,0,0,0,0,0,0]

# Setup PIN (they all are BOARD layout and NOT BCM
#
# it means the PIN number reflect the physical layout
WATER = 18 #Water Level DIGITAL In
PUMP = 5
VALVES = [7,11,12,13,15,16,3,0]

SOILVALUE = [0,0,0,0,0,0,0,0]
SOILTRIGGER = [130,130,0,0,0,0,0,0]
VNAMES = ["Vaso Ginevra 1", "Vaso Ginevra 2"," "," "," "," "," "," "]
SOILAVTIVE = [1,1,0,0,0,0,0,0]
IRTIME = [3,3,0,0,0,0,0,0]
The most dangerous phrase in any language is:
"We always done this way"
Post Reply