Deprecation note: I used this project actively for 3-4 months but I wanted to add new features that were too time consuming to implement so I migrated my system to Home Assistant.
A self-learning project to get familiar with Python, electronics and gardening.
- Automatic irrigation
- Saves historical moisture readings and irrigation events to a database
- Web UI for monitoring the system
As you can see, the web UI is very much a work in progress...
The app relies on a database for the configuration of the plant pots you want to irrigate and the devices these pots are connected to. You can define all the settings for each pot (see table below) to determine when to irrigate and for how long. Every time the moisture reading changes it's automatically saved to the database.
- Rasperry Pi 4 Model B (
serverand/orclient) - Raspberry Pico W (
clientonly)
- Clone the repo:
git clone https://github.com/fmaclen/auto-garden.git - Download and setup PocketBase (see Development section)
- Open port
8090and8888on the device that's running the server and check the rule was added:
iptables -A INPUT -p tcp --dport 8888 -j ACCEPT
iptables -A INPUT -p tcp --dport 8090 -j ACCEPT
iptables -L INPUT- Create the
adminaccount,deviceandpots:
| Pot Key | Explanation |
|---|---|
id |
Identifier or ID associated with the pot |
device |
ID of the device which will control the pot |
name |
Name of the pot |
moisture_low |
The lower threshold % of moisture value below which the pot needs irrigation |
moisture_high |
The upper threshold % of moisture value above which the pot doesn't require irrigation |
moisture_sensor_dry |
The raw value the moisture sensor is reporting when it's exposed to the air |
moisture_sensor_wet |
The raw value the moisture sensor is reporting when it's exposed to water |
moisture_sensor_pin |
The GPIO pin number where the moisture sensor is connected. Note: for Pi 4 the pin number refers to the ADC channel |
pump_max_attempts |
The maximum number of pump attempts allowed per irrigation event |
pump_duration_in_s |
The duration in seconds for which the pump remains on during irrigation |
pump_frequency_in_s |
The duration in seconds to wait between pumps during an irrigation event |
pump_relay_pin |
The GPIO pin number number connected to the pump relay |
- Run the Web UI server in another window:
python web/web.py- On another computer in the same network visit:
http://<your-local-ip-address>:8888(Web UI)http://<your-local-ip-address>:8090(PocketBase)
- In the Web UI configure the IP address of the PocketBase server, as well as the admin
usernameandpassword. These values are saved locally on your browser.
-
Clone the repo:
git clone https://github.com/fmaclen/auto-garden.gitandcd auto-garden -
Build the app with:
./script/build/pi_4. This will generate/dist/pi_4folder with all the files. -
Create a copy of
env.sample.pyand rename it todist/pi_4/env.py. Update the file with the correct values. -
Install the Python libraries
pip install -r dist/pi_4/requirements.txt. -
Start the app in another window:
python dist/pi_4/main.pyIf you are running the server + client in a Pi 4, after following the setup steps above, you can start all 3 processes (in the background) with:
./scripts/startStop the server and app:
./scripts/stop- Clone the repo:
git clone https://github.com/fmaclen/auto-garden.gitandcd auto-garden - Build the app with:
./script/build/pico_w. This will generate/dist/pico_wfolder with all the files. - Create a copy of
env.sample.pyand rename it todist/pico_w/env.py. Update the file with the correct values. - Copy the contents of the
dist/pico_wfolder to the Pico W's filesystem. If you are using VSCode I'd recommend using the MicroPico extension, otherwise use Thonny. - Unplug from your computer and connect it to a power source. It should connect to the WiFi network set in
env.pyand start running the app. You can check if it's running by looking at the logged events in PocketBase or seeing the moisture readings in the Web UI.
- Clone repo and install dependencies:
pip install -r requirements.txt- Download and unzip Pocketbase (update the URL to match your OS architecture):
wget -O pocketbase.zip https://github.com/pocketbase/pocketbase/releases/download/v0.16.10/pocketbase_0.16.10_darwin_amd64.zip
unzip pocketbase.zip -d pocketbase- Start the database server in one window:
./pocketbase/pocketbase serve- Visit http://127.0.0.1:8090:
- Create an admin account
- Create a Device in the
devicestable - Create a Pot in the
potstable
-
Create a copy of
env.sample.pyand rename it toenv.py. You can leave the default values for testing. -
Run the tests. If you are using VSCode launch the debugger with the
Test: auto-gardenconfiguration (recommended). Alternatively, run the following command from the root of the project:
python -m pytest -s -v test/
