Greenhouse Controllder to monitor and control:
- Multiple temperature monitors, each controlling a plant propagator with outputs to control a relay powering a propagator heater element.
- Air temperature monitor controlling an air heater.
- Light level monitor controlling lighting.
- Temperature and humidity monitor.
Requires:
- The GPIO Library (Already on most Raspberry Pi OS builds).
- The Flask web server. Install command:
- sudo apt-get install python3-flask
- The Astral sun position calculator:
- pip3 install astral
- Note: the version of Python on my Raspberry Pi precluded using the latest Astral so version 1.10.1 is required.
- A Raspberry Pi with Raspbian Stretch OS installed (require python3.5 to support Influxdb).
- Database setup in Influxdb. The intention behind logging measurements to a database is to allow graphical monitoring of the greenhouse history. My plan is to use Grafana - see How to install Grafana+InfluxDB on the Raspberry Pi for more information, although at this stage full documentation is not presented here for using Grafana with the Greenhouse Controller.
- Hardware with MAX31855 temperature monitors.
- Hardware to control a heater elements. In my case this was one propagator with a faulty control unit re-wired to drive the relay from the Raspberry Pi and an eight-relay board to switch mains voltages.
- Hardware with BH1750 Digital 16-bit ambient light sensor.
- Hardware with AM2320 Humidity and temperature sensor.
- Hardware with DS18B20 one wire temperature sensor
Installation:
- Copy files to a folder on the Raspberry Pi.
- Edit /etc/rc.local to autorun application:
- sudo nano /etc/rc.local
- Add: python /home/pi/.../greenhouse.py where ... is the location of your file.
- Install supplementary software:
- sudo apt-get install python3-flask
- sudo apt-get install python3-w1thermsensor
- Install Influxdb and assume that Raspbian Stretch OS is installed. My instructions are based on How to install Grafana+InfluxDB on the Raspberry Pi
- curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -
- source /etc/os-release
- echo deb https://repos.influxdata.com/debian stretch stable | sudo tee /etc/apt/sources.list.d/influxdb.list
- sudo apt-get update && sudo apt-get install influxdb
- sudo service influxdb start
- sudo nano /etc/influxdb/influxdb.conf
- Edit the configuration to enable http on port 8086 with no authentication.
- sudo service influxdb restart
- sudo pip install influxdb
- python3 -m pip install influxdb
- influx -precision rfc3339
- create database greenhouse
- Install Grafana and assume that Raspbian Stretch OS is installed. My instructions are based on How to install Grafana+InfluxDB on the Raspberry Pi
- sudo apt-get install apt-transport-https curl
- curl https://bintray.com/user/downloadSubjectPublicKey?username=bintray | sudo apt-key add -
- echo "deb https://dl.bintray.com/fg2it/deb stretch main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
- sudo apt-get update
- sudo apt-get install grafana
- sudo /bin/systemctl daemon-reload
- sudo systemctl enable grafana-server
- sudo service grafana-server start
- sudo systemctl start grafana-server
- http://ip.address:3000/ – where ip.addresss is the IP address of your Raspberry Pi. Default is user admin, password admin
- Setup the data source:
- Name = greenhouse
- Type = Influxdb
- URL = http://ip.address:3000/ – where ip.addresss is the IP address of your Raspberry Pi.
- Access = Server
- Database = greenhouse
- user = root
- password = root
- Min time interval = 10m (the write interval of data)
- Create dashboards. As a start import those in the Grafana dashboards folder.
- Edit config.xml to define your system hardware. The defaults match my hardware.
Recommendations (to make life easier):
- Set a static IP address.
- Define a hostname.
- Create a fileshare.
- Install VNC for full headless access.
- Install Grafana to monitor the performance over time.
See wiki.
Add control of lighting to extend spring. Sunrise is simulated an offset number of days in the future.
Add e-mail config to display of config.
Added configuration option for XML and/or database logging.
Restricted relay activations if there has been a recent activation.
Added write of activations to configuration XML file.
Added count of relay activations.
Added command line option for fake lighting.
Added delay before temperature offset is calculated as the first measurement showed no error.
Added ability to globally enable or disable e-mail notifications.
Added test code to fake the lighting control for testing.
Added setting for Lighting induced temperature offset to print of configuration.
Add count for number of errors detected on thermocouple per logging period.
Add overall e-mail enable/disable.
Corrected failure to detect lights being turned on.
Added write debug to a file for analysis.
Added adjustment of temperature due to interference from lighting.
Turning on of growlights caused a sudden drop in measured temperature and a similar increase when the lights turn off; this is likely due to EMC interference from the lights on the thermocouples. This causes the propagator heating to turn on and overheat the propagator (compared to the set temperature). To avoid this, an optional (defined in the configuration file), setting to measure the offset caused, per propagator, when the lights are on is added.
Disabled creation of some errors when hardware is disabled.
Limit error disable of propagator relay to only if more than a defined number of consecutive error states occur. Avoids current condition where the temperature can be below the defined level, but due to error conditions the relay turns the heater off and the configured temperature is not acheived.
Limit maximum change of temperature per measurement cycle. Observed that some channels once deployed occasionally jump (e.g. from 20degC to 0degC) within one 10s measurement cycle. It is not generally possible to jump big temperature differences in one measurement cycle, even if the heater is enabled; the exception to this could be adding cold water. The result on a large jump is to (unnecessarily) turn on the heater for one (or a few) measurement cycle(s). This will cause unnecessary wear on the relay (reducing the lifetime of the system) and unnecessary energy consumption. By limiting the temperature change, incorrect measurements have no/minimal effect (the correct temperature will soon be read) and genuine large jumps will take a few measurement cycles to be established (but short in the overall scheme of a greenhouse controller).
Modified config schedules.
Installed in greenhouse.
Corrected config display of calibration vs measurement.
Added calibration for humidity sensor.
Added e-mail alert if air temperature sensor is missing on restart.
Corrected debug log of air temperature in the event the sensor fails.
Moved e-mail into a thread, allowing for network outages without throwing an exception and maintaining a queue up to max 10 e-mails.
Added ability of e-mail text to include non alphanumeric codes through MIME encoding.
Added hysteresis to monitor of CPU core temperature
Added monitor of CPU core temperature.
Modified min/max calculation of thermocouple temperatures to cope with errors.
Added exception if humidity sensor is not connected/faulty.
Detection if one-wire temperature sensor is not connected.
Added test for all relays on - maximum power consumption.
New config for the actual hardware build.
Defined logging to align to the boundary of the minute interval
Added function to self-test hardware implementation as defined by the configuration.
Added calculation of average lighting on time.
Added calculation of average air heating on time.
Removed temprary code as there was no calculation error.
Added error checking code for heating air temperature sensor. NOT yet tested for sensore failure as the sensor is soldered into the test board.
Added temporary code to print propagator heater logging values as there may be a calculation error.
Added checking for sensor errors before adding data to database
Enabled logging based on config file setting
Added initial setting of logging state from config file
Modifed values so that parameters that are/could be floats are stored into the database with the type float as the type cannot subsequently be changed.
Added database logging.
Corrected CSV logging.
Added all parameters to web status page.
Modified all measurement threads to be the only place in which sensors are read, saving readings for use elsewhere.
Added raise exception if humidity sensor fails.
Added e-mail notification of sensor failure or paramter exceeding defined value.
Individual monitoring of min, max temperature, heater state, proportion of heating time per propagator.
Separated air heater and propagator heater set temperatures.
Removed unneccessary defintion of global variables.
Added missing defintion of air temperature logging variables.
Added detection of fault in reading humidity sensor.
Added detection of fault in reading light sensor. Default to turn lighting on for the timed duration.
Added individual enable/disable for each control
Added timed control of lighting
Completed display of defined configuration
Added one-wire temperature sensor and control of air heater
Added option to display the defined configuration
Added basic control of lighting relay with a fixed lux level
Moved print output into debug function so that when complete the application runs with a cleaner interface, with optional debug output
Split control elements into separate threads
Added reading of humidity/temperature sensor
Added reading of light sensor
Updated to match recommended style https://www.python.org/dev/peps/pep-0008/
Converted to Python3
Made file executable
Initial code copied from Propagator Thermostat project