A Raspberry Pi-based temperature, light, and UV controller for gecko vivarium monitoring and control.
- Real-time temperature and humidity monitoring via SHT31 sensor
- UV spectrum monitoring (UVA/UVB/UVC) via AS7331 sensor
- Automated light cycle control with configurable schedules
- Temperature-based heating control with day/night settings
- OLED status display showing:
- Current time
- Temperature and humidity readings
- Target temperature
- UV levels with status indicators
- Light and heat status
- Time until next light transition
- Web interface for:
- Real-time environmental monitoring
- Temperature and light schedule configuration
- Historical data visualization
- Mobile-friendly responsive design
- Logging of environmental conditions
- MQTT Home Assistant integration with auto-discovery
- Automatic sensor entity creation
- Real-time data publishing
- No manual configuration required
- Raspberry Pi (any model with GPIO pins)
- SSH1106 OLED Display (I2C interface)
- SHT31 Temperature/Humidity Sensor
- AS7331 Spectral UV Sensor
- DS3231 Real-Time Clock (I2C interface, address 0x68)
- 2x Relay modules (for light and heat control)
- Compatible 5V power supply
- I2C-compatible cables and connectors
-
Enable I2C and configure RTC on your Raspberry Pi:
sudo raspi-config # Navigate to Interface Options > I2C > Enable # Add RTC overlay to /boot/firmware/config.txt: echo "dtoverlay=i2c-rtc,ds3231" | sudo tee -a /boot/firmware/config.txt # Reboot for changes to take effect sudo reboot
-
Install the package:
sudo apt update sudo apt install gecko-controller
-
The controller service will start automatically. Check its status with:
sudo systemctl status gecko-controller
-
Start and enable the web interface:
sudo systemctl start gecko-web sudo systemctl enable gecko-web
-
Enable I2C as described above
-
Clone the repository:
git clone https://github.com/yourusername/gecko-controller.git cd gecko-controller -
Install required packages:
python3 -m pip install RPi.GPIO smbus2 Pillow Flask paho-mqtt
-
Run the controller:
python3 gecko_controller/controller.py
-
In a separate terminal, run the web interface:
python3 -m gecko_controller.web.app
The web interface is accessible at http://<raspberry-pi-ip>/ and provides:
- Real-time monitoring dashboard
- Current temperature and humidity
- UV levels with status indicators
- Light and heat status
- Historical data graphs
- Temperature and humidity trends
- UV exposure levels
- Configuration panel
- Temperature thresholds
- Light schedule
- UV warning levels
Create or modify /etc/gecko-controller/config.py with your settings:
# Gecko Controller Configuration File
# This file will be installed to /etc/gecko-controller/config.py
# You can modify these values to customize your gecko enclosure settings
# The service must be restarted after changes: sudo systemctl restart gecko-controller
# Display I2C
DISPLAY_ADDRESS = 0x3c
# GPIO Pins
LIGHT_RELAY = 17
HEAT_RELAY = 4
DISPLAY_RESET = 21
# Temperature Settings
MIN_TEMP = 15.0
DAY_TEMP = 30.0
TEMP_TOLERANCE = 1.0
# Time Settings
LIGHT_ON_TIME = "07:30"
LIGHT_OFF_TIME = "19:30"
# UV Thresholds # μW/cm²
UVA_THRESHOLDS = {
'low': 50.0,
'high': 100.0
}
UVB_THRESHOLDS = {
'low': 2.0,
'high': 5.0
}
# UV View Factor Correction
SENSOR_HEIGHT = 0.2
LAMP_DIST_FROM_BACK = 0.3
ENCLOSURE_HEIGHT = 0.5
SENSOR_ANGLE = 90
# MQTT Settings for Home Assistant Integration
MQTT_ENABLED = True
MQTT_BROKER = "homeassistant.local"
MQTT_PORT = 1883
MQTT_USERNAME = "mqtt"
MQTT_PASSWORD = "mqtt"
MQTT_TOPIC_PREFIX = "gecko"
MQTT_DEVICE_ID = "gecko_controller"
MQTT_PUBLISH_INTERVAL = 60 # seconds| Component | GPIO Pin | Notes |
|---|---|---|
| Light Relay | GPIO 4 | Active HIGH for ON |
| Heat Relay | GPIO 17 | Active HIGH for ON |
| Display Reset | GPIO 21 | Optional, HIGH for normal |
| I2C SDA | GPIO 2 | For all I2C devices |
| I2C SCL | GPIO 3 | For all I2C devices |
The gecko controller automatically publishes sensor data to Home Assistant via MQTT with zero configuration required on the Home Assistant side.
- Ensure MQTT is enabled in your Home Assistant installation
- Configure MQTT settings in
/etc/gecko-controller/config.py - Restart the gecko-controller service:
sudo systemctl restart gecko-controller
cd /home/ian/gecko-controller
python3 test_mqtt.pyTo remove test devices if needed:
python3 cleanup_mqtt_test.pyThe following sensors will automatically appear in Home Assistant:
- Temperature - Current vivarium temperature (°C)
- Humidity - Current humidity level (%)
- UVA Level - UVA radiation (μW/cm²)
- UVB Level - UVB radiation (μW/cm²)
- UVC Level - UVC radiation (μW/cm²)
- Light Relay - Light relay control state (ON/OFF based on schedule)
- Heat Relay - Heat relay control state (ON/OFF based on temperature)
- Target Temperature - Current temperature setpoint (°C)
- Next Light Change - Next scheduled light transition (e.g., "→OFF at 19:30")
- Time Until Change - Countdown to next transition (e.g., "2h50m")
- Controller Time - Current time on the controller
- Light Schedule - Daily light schedule (e.g., "ON 07:30 - OFF 19:30")
- No device in Home Assistant: Check MQTT broker connectivity with
python3 test_mqtt.py - Duplicate devices: Run
python3 cleanup_mqtt_test.pyto remove test devices - No data updates: Verify service is running:
sudo systemctl status gecko-controller - Connection issues: Check firewall rules and ensure port 1883 is accessible
-
Check I2C devices are detected:
sudo i2cdetect -y 1 # Expected devices: # 0x3c - OLED Display # 0x44 - SHT31 Temperature/Humidity Sensor # 0x68 - DS3231 RTC # 0x74 - AS7331 UV Sensor
-
Verify RTC is working:
# Check if RTC device exists ls -la /dev/rtc* # Read hardware clock time sudo hwclock --show # Check system time configuration timedatectl status
-
View service logs:
journalctl -u gecko-controller -f
-
Common issues:
- If display shows no data, check I2C connections and addresses
- If UV readings show as "None", verify AS7331 sensor connection
- For temperature/humidity errors, check SHT31 sensor wiring
- If time is incorrect after reboot:
- Ensure RTC overlay is in
/boot/firmware/config.txt:dtoverlay=i2c-rtc,ds3231 - Verify RTC is detected at address 0x68 with
sudo i2cdetect -y 1 - Check RTC battery voltage (should be ~3V)
- Ensure RTC overlay is in
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For issues, questions, or contributions, please open an issue on the GitHub repository.
