AllSkyHeating
This repository contains a Python script that controls relays based on temperature, time of day, and weather conditions. It calculates sunrise and sunset times using the ephem library and displays relay status, temperatures, sunrise, sunset, and snowfall in an HTML file. The HTML page also allows manual relay control.
Requirements
Raspberry Pi
Python 3
CircuitPython libraries
DS18B20 temperature sensors
Relays
OneWire bus
Installation
Install the required Python modules:
- pip3 install adafruit-circuitpython-ds18x20
pip3 install adafruit-blinka
pip3 install ephem
pip3 install requests
- Create a file named
main.pyand paste the code from this repository. - Connect the DS18B20 sensors and relays to your Raspberry Pi based on the specified pinout.
- Run the code using the command:
python3 main.py
Usage The code will control the relays based on the conditions and update the status in the status.html file. To view the status, open the status.html file in a web browser.
Configuration The following settings can be configured in the main.py file:
- location: The latitude and longitude of your location.
- api_key: Your API key from OpenWeatherMap.
- relay_1_pin: The GPIO pin for Relay 1.
- relay_2_pin: The GPIO pin for Relay 2.
Adding BMP280 as an Optional Component
To connect the BMP280:
- Connect the SDA pin of the BMP280 to the SDA pin (Serial Data) of your microcontroller.
- Connect the SCL pin of the BMP280 to the SCL pin (Serial Clock) of your microcontroller.
- Connect the VCC pin of the BMP280 to the supply voltage (3.3V or 5V) of your microcontroller.
- Connect the GND pin of the BMP280 to the ground (GND) of your microcontroller.
Please ensure correct pin connections and voltage compatibility. If using a different microcontroller, refer to its I2C connection pins and manufacturer instructions.
The BMP280 can be integrated as an additional option within your existing setup.
To set up the script as a systemd service, follow these steps:
- Create a new systemd service unit file for your script:
sudo nano /etc/systemd/system/your-script.service
Replace your-script with a suitable name for your service.
- Add the following content to the your-script.service file:
[Unit]
Description=Your Python Script Autostart
After=multi-user.target
[Service]
ExecStart=/usr/bin/python3 /path/to/your/main.py
WorkingDirectory=/path/to/your/script/directory
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi # Change this to your username if not using "pi"
[Install]
WantedBy=multi-user.target
Replace /path/to/your/main.py and /path/to/your/script/directory with the actual paths.
Enable the systemd service:
- sudo systemctl enable your-script.service
Start the service to ensure it's working:
- sudo systemctl start your-script.service
Check the status of the service with:
- sudo systemctl status your-script.service
Contributing
Contributions are welcome! Please fork this repository and submit a pull request.