Rapsberry-pi Thermostat for chicken.
Backend python 3 - fastapi / frontend vuejs - vuetify
- Raspberry Pi (
zero
in that case, should work with all the other) - Temperature sensor
DS18B20
using1-wire
(example) - Relay hat (example)
Enable 1-wire
:
Add following lines to your /boot/config.txt
:
[all]
dtoverlay=w1-gpio,gpiopin=3
# default pin is 4 but it enter in conflict with relay hat
This project is meant to run as a service (see next section), but to give it a try you can instal it as a normal user (lets assume as pi
default user).
# install from pip repository
pip install rpi-thermo-chick
# create empty configuration file
sudo pi-thermo-chick.service configure
# edit configuration file (See configuration section)
sudo nano /root/.config/rpi-thermo-chick/config.json
All the following command are prefix by sudo cause the service will be run as a service (as root user).
# install from pip repository
sudo pip install rpi-thermo-chick
# create empty configuration file
sudo pi-thermo-chick.service configure
# edit configuration file (See configuration section)
sudo nano /root/.config/rpi-thermo-chick/config.json
# install service (register in systemd)
sudo rpi-thermo-chick.service install
# now enable(auto start) and start the service
sudo systemctl enable rpi-thermo-chick.service
sudo systemctl start rpi-thermo-chick.service
# check if the service is properly running
sudo systemctl status rpi-thermo-chick.service
Now service should be running (open http://<pi-ip>:8000/app
to check) and will start automatically with the pi.
You have to configure 2 things, the pins you use for the relay and the device id of the thermometers.
To create default config file run:
pi-thermo-chick.service configure
It will create a config file in you current user configuration directory, edit that file (with nano
or any other file editor).
For example if you user is pi
, config file will be be /home/pi/.config/rpi-thermo-chick/config.json
.
Configuration file content is a simple json and look like:
{
"relays": [
{ "pin": 4 }, { "pin": 7 } ],
"thermometers": [
{ "device": "28-3c01d0751fcd", "name": "inside" }, { "device": "28-3c01d075db96", "name": "outside" } ],
"influxdb": {
"url": "http://localhost:8086",
"bucket": "bucket",
"org": "org",
"token": "<token>"
}
}
To know your thermometer device id run the following command:
ls /sys/bus/w1/devices | grep 28-*
It will return something like:
28-3c01d0751fcd
28-3c01d075db96
Update your configuration file with your own values.
Simply update the config file with the physical gpio pins wired to the relays.
Data history is stored in influxdb
(2.x), to enable this feature pass a valid influxdb url/org/bucket/token in the config file.
Obviously the token must provide write permission so relays and temperature sensor data can be stored.
Setup of influxdb is out of the scope of this project, please see https://hub.docker.com/_/influxdb or https://docs.influxdata.com/influxdb/v2.4/install/.
git clone https://github.com/vrince/rpi-thermo-chick.git
cd rpi_thermo_chick
# build and activate a virtual env (optional)
# install in dev mode
pip install -e .
# see configuration
nano config.json
# run it locally with the config you just created
rpi-thermo-chick --config-file config.json --port 8000
- Open
http://<pi-ip>:8000/app
to see thevuejs
app - Open
http://<pi-ip>:8000
to see current state json payload
Note: replace <pi-ip>
by you actual raspberry pi address, like 192.168.2.205
You can still run and develop on a machine that is not a rpi and that has nothing plug to it, temp dat will be random but everything will still work
As the API use fast-api
the documentation of the API can be access at http://<pi-ip>:8000/docs