AIGarden: how to create a balcony garden from scratch and watering by AI

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:


  • 1 trasparent paint
  • 1 shelf and supports
  • assembly kit: screws, nails, plates, hammer


  • 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)



AIGarden: main schema

Garden creation

  • assembly the wood tables like in the picture:
  • the garden should look like this
Built garden
  • 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

insert moisture sensor into vegetable garden

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.

rfx and trx 433mhz connection 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

git clone git:// && cd wiringPi &&./build
git clone

//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.

node-red processflow for catching data sensor

script into node-red function

var url = "";
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" &&{
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:

  1. new device for soil moisture and temperature
  2. new device for a remote switch
  3. 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).

data sensor visualization from Domoticz
moisture and temperature sensor logs

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:

  1. 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%.
  2. 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.
  3. 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.

sample of training set (previous values) and the action predicted. Note at 22.00 pm the soil moisture humidity has 69%. For a determinated rule (under 70% of soil moisture) the action will be “water”. Instead, AI predict a “no water” action because the previous days values (training set)

“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

vegetable growth with AI irrigation algorithm

Leave a Reply