A complete IoT solution for monitoring and controlling a smart greenhouse system. This project includes ESP32 firmware, a modern web interface, a Node.js backend, and Home Assistant integration.
- Real-time Monitoring: Temperature, pressure, soil moisture, UV index, rain detection, and light intensity
- Remote Control: Control lighting, ventilation, and irrigation from anywhere
- Automatic Mode: Intelligent automation based on sensor readings
- Modern Web Dashboard: Beautiful, responsive React-based interface
- Home Assistant Integration: Full MQTT integration with pre-configured sensors and automations
- Live Updates: WebSocket-based real-time data updates
- Hardware
- Software Architecture
- Installation
- Configuration
- Usage
- Home Assistant Integration
- API Documentation
- License
- ESP32 NodeMCU
- FC-37 - Rain Sensor
- Capacitive Soil Moisture Sensor v1.2 - Soil moisture measurement
- DS18B20 - Soil temperature sensor
- BMP280 - Temperature, pressure, and altitude sensor
- UVM30A - UV sensor
- ARD SEN LDR - Light intensity sensor
- 2x FUNGWAN MG 996R - Servo motors for window/vent control
- 3-Wire Fan - Ventilation fan
- 3x 5V Relays - Control switches for various devices
- 230V Lamp - Supplemental lighting
aau_smartgreenhouse/
├── Greenhouse_Struct_MQTT_V4.ino # ESP32 firmware
├── backend/ # Node.js backend server
│ ├── server.js # Express server with MQTT client
│ ├── package.json
│ └── .env.example
├── frontend/ # React web interface
│ ├── src/
│ │ ├── App.jsx # Main application component
│ │ ├── App.css
│ │ └── main.jsx
│ ├── package.json
│ └── vite.config.js
├── homeassistant/ # Home Assistant integration
│ ├── sensors.yaml # Sensor definitions
│ ├── switches.yaml # Switch definitions
│ ├── automations.yaml # Automation examples
│ └── dashboard.yaml # Lovelace dashboard config
└── nodered ui.json # Legacy Node-RED configuration
- Node.js (v16 or higher)
- npm or yarn
- Arduino IDE (for ESP32 firmware)
- MQTT Broker (e.g., HiveMQ, Mosquitto, or Home Assistant's built-in broker)
-
Install the Arduino IDE
-
Install ESP32 board support
-
Install required libraries:
- ESP32Servo
- Adafruit_BMP280
- Adafruit_Sensor
- OneWire
- DallasTemperature
- BH1750
- EspMQTTClient
-
Open
Greenhouse_Struct_MQTT_V4.ino -
Update WiFi credentials and MQTT broker settings (lines 29-37)
-
Upload to ESP32
cd backend
npm install
cp .env.example .env
# Edit .env with your MQTT broker settings
npm startThe backend will run on http://localhost:3001
cd frontend
npm install
npm run devThe frontend will run on http://localhost:3000
Edit the backend .env file:
PORT=3001
MQTT_BROKER=mqtt://broker.hivemq.comOr for a local Mosquitto broker:
MQTT_BROKER=mqtt://localhost:1883Update in Greenhouse_Struct_MQTT_V4.ino:
EspMQTTClient client(
"YOUR_WIFI_SSID", // WiFi SSID
"YOUR_WIFI_PASSWORD", // WiFi password
"broker.hivemq.com", // MQTT broker
"", // MQTT username (if required)
"", // MQTT password (if required)
"greenhouse_client", // Client ID
1883 // MQTT port
);- Start the backend server:
cd backend && npm start - Start the frontend:
cd frontend && npm run dev - Open browser to
http://localhost:3000
The dashboard shows:
- Real-time sensor readings
- Control switches for all actuators
- Automatic mode toggle
- Live connection status
Use the control panel to:
- Toggle Automatic Mode for intelligent automation
- Control Light (230V lamp)
- Control Ventilation (fan and servo)
- Control Irrigation (water pump)
When enabled, the system automatically:
- Activates ventilation when temperature > 28°C
- Turns on heating when temperature < 23°C
- Starts irrigation when soil moisture < 30%
- Stops irrigation when soil moisture > 70%
- Ensure Home Assistant has MQTT configured
- Copy files from
homeassistant/directory - Add to
configuration.yaml:
# MQTT
mqtt:
broker: broker.hivemq.com
port: 1883
# Sensors
sensor: !include sensors.yaml
# Switches
switch: !include switches.yaml- Restart Home Assistant
- Add the dashboard using
dashboard.yaml
Sensors:
sensor.greenhouse_temperaturesensor.greenhouse_pressuresensor.greenhouse_soil_moisturesensor.greenhouse_soil_temperaturesensor.greenhouse_uv_indexsensor.greenhouse_rainsensor.greenhouse_light_intensitysensor.greenhouse_altitude
Switches:
switch.greenhouse_lightswitch.greenhouse_ventilationswitch.greenhouse_irrigationswitch.greenhouse_automation
Returns backend and MQTT connection status
Returns all sensor data and device states
Control the light
{ "state": "on" } // or "off"Control ventilation
{ "state": "on" } // or "off"Control irrigation
{ "state": "on" } // or "off"Toggle automatic mode
{ "state": "on" } // or "off"Connect to ws://localhost:3001 for real-time updates
Messages received:
{
"type": "initial", // or "update"
"data": {
"climate": { /* sensor data */ },
"manager": { /* device states */ }
}
}Contributions are welcome! Please feel free to submit a Pull Request.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- Original greenhouse design and hardware setup
- ESP32 and Arduino community
- Home Assistant community



