hard
quite expensive
5 days
In this tutorial we are going to create a nice balcony garden in pine wood and controlled by an artificial intelligence. One of the most important feature is to give to the machine the full control of watering.
goals of AI integration
- could be used in different microclimate: each garden could be installed in different geographic area (but also in different location of the same area) and is adaptable for each microclimate.
- reduction of water waste due to artificial intelligence
- reduce the instrumentation errors: each garden could be monitered by different sensors that could give different range of measures (it depends of used HW or other characteristics). For AI it’s not important which sensor is used because it adapts to different ones
What we need:
MATERIAL ELEMENTS
- 2 pine wood tables 100X30
- 2 pine wood tables 50X30
- 1 pine wood table 100X50
- 4 legs for table 40cm
- 1 tub 20lt
- garden water pipes and garden nozzles
- 1 trasparent paint
- 1 shelf and supports
- assembly kit: screws, nails, plates, hammer
HARDWARE
- 1 raspberry Pi starter kit (in this tutorial we have used another raspberry Pi as a remote domoticz controller, but, we can do it with just one Rpi)
SOFTWARE:
MAIN SCHEMA

Garden creation
- assembly the wood tables like in the picture:

- the garden should look like this

- protect inside with a transparent paint or insulating paper

- strengthening the woods with a transparent paint

- installing the legs

- filling the soil

- planting tomatoes, zucchini, peppers, cucumbers or other vegetables you prefer.

Preparing raspberry Pi: add electronic plugins
Preparing raspberry from scratch with Raspbian image. Choose the right distribution from the repository
On boot input the command:
sudo apt-get update
sudo apt-get upgrade
Receive wireless signal from Raspberry
for capturing any 433,92Mhz signal install into Rpi the USB DVB-T following thi tutorial
install the RTL_433 software for capturing the 433,92 signal from the sensors

execute the command
cd /home/pi/rtl433
rtl_433 -F json -r receive.json
Moisture sensor
insert the moisture sensor into the balcony garden and let’s catch the signal from DVBT antenna


Launching rtl_433 command from terminal and wait for signal catching
launch rtl_433 -G -F /home/pi/rtl433/receive.json
for storing data received into a json file.
Elaborate json file with node-red and send it to a remote domoticz console
External humidity and temperature sensor
The external humidity and temperature are provided by a lot of wireless sensors (see the devices protocol list).
we have used Acurite external and internal temperature and humidity.
you can use a public sensor like Open Weather Map that it’s compatible with domoticz.
Control wireless remote switch
for controlling the wireless remote switch we need other modules to connect into the Rpi Gpio. The modules allows the machine to receive and transmit 433,92 mhz signal.
The process looks like: catch the signal (sent by remote controller) from receiver module, copy the code and send it with the transmit module.

follow the tutorial
connect the module into raspberry gpio following this schema
install 433utils for raspberry
sudo apt-get install git-core
sudo apt-get update
sudo apt-get upgrade
//CLONE WIRINGPI - 433Utils
git clone git://git.drogon.net/wiringPi && cd wiringPi &&./build
git clone https://github.com/ninjablocks/433Utils.git
//BUILD 433Utils
cd 433Utils/RPi_utils
make all
after the installation, copy the signal from remote controller with the function RFSniffer
cd 433Utils/RPi_utils sudo ./RFSniffer
listen the code once button pressed on remote controller and send the code through 433Utils function codesend:
sudo ./codesend <code>
elaborate the data sensor with nodered
Node-red data elaboration
Install node-red into raspberry by following this tutorial
Create the processflow like in the picture below for catching data sensor from receive.json file created and sending to a domoticz remote controller.

script into node-red function
var url = "http://192.168.1.4:8088/json.htm?type=command¶m=udevice";
var objOpus=[];
var obj={};
for (var z=2;z<msg.payload.length;z++)
//cycle into receive.json array file
{
obj = JSON.parse(msg.payload[msg.payload.length-z]);
if (typeof obj !== 'undefined') {
if (obj.model==="Opus-XT300" && obj.channel==2){
objOpus.push(obj);//populate only Opus-XT300 data array
}
}
}
if (objOpus[0].channel==2){
url=url+"&idx=39&nvalue=0&svalue="+objOpus[0].temperature_C+";"+objOpus[0].moisture+";3" ;//idx=39 is related to the index of virtual sensor into domoticz
}
msg = {payload: url};
return msg;
Domoticz data visualization
install domoticz by following this tutorial
create new devices for each sensor/actuators we want to use:
- new device for soil moisture and temperature
- new device for a remote switch
- new device for OpenWeatherMap (or external temperature and humidity wireless sensor)
Install new virtual device sensor into domoticz for retrieving the json information sent by nodered. We call it “vegetable balcony” and has index(IDX)=39 (look at script above).


Add Artificial Intelligence
add an Artificial Intelligence for watering the plants.
We use this NaiveBayes algorithm and taking the prediction action. The input parameters are:
- soil humidity
- external temperature: high temperature could take effects on soil water evaporation
- external humidity: high external humidity could take effects on water absorption rate
- external wind speed: high wind speed could take effetcs on water evaporation
The system is thought for predicting the irrigation based on historical training data set and works like:
- every hour the AI system store into the training set the: humidity, temperature and the action data: water or not water. Set “water” if soil moisture is under 60% and “no water” if is over 60%.
- every 2 hours (in the night) the system store into testing set the forecasted humidity and temperature values. The action will be predicted based on the training set and NaiveBayes algorithm. If the prediction is “water” automatically start the irrigation, otherwise, the irrigation not start.
- repeat at point 1
water prediction web application
“NO WATER” ACTION PREDICTION : P(“NO WATER”|ext. temperature, ext humidity, soil moisture, wind speed)
In the following example, current soil moisture is 69% but the “water” not start like written in the determinated rule (under 70% the water start). This is explained by NaiveBayes algorithm: the conditional probability for no water event is the likelihood of action “no water” occurring given input parameters (temperature, humidity, soil moisture, speed wind) are true.

“WATER” ACTION PREDICTION : P(“WATER”|ext. temperature, ext humidity, soil moisture, wind speed)
the conditional probability for water event: is the likelihood of “water” action occurring given input parameters are true. In the following example with a 49% of soil moisture, 50% of external humidity, 25°C of external temperature, 4 m/s of wind the predicted action is “water”.

NOTE: The prediction is made every 2 hours in the night period, the result of prediction will act “watering” or “not watering”.
AIGarden vegetable growth
