This is a telegram bot hosted by a Raspberry Pi equipped with a temperature and humidity sensor. The bot is capable of sending plots and readings.
This project is composed of 3 main files:
bot.pyis used to host the telegram bot.
Graphclass, used to make graphs.
TemperatureSensorclass, used to write and read from the sqlite3 database, as well as the function that reads the temperature and humidity values from the sensor.
bot.py will call both the
Raspberry Pi setup
To make this project i used a Raspberry Pi Zero W with an AM2302 temperature and humidity sensor.
The humidity sensor has 3 pins:
- DATA, connected to the GPIO 4 port, it sends the readings to the Raspberry Pi.
- GROUND, connected to one of the ground ports.
- VCC, connected to one of the 5V ports.
Once your sensor is connected to your Raspberry Pi, go ahead and proceed to install a clean version of Raspberry Pi OS Lite.
To install raspy-temperature-bot:
- Ssh into your Raspberry Pi
- Clone the repository
git clone https://github.com/Kirgnition/raspy-temperature-bot.git
- cd into the repository and install the requirements.
cd ./raspy-temperature-bot pip3 install -r ./requirements.txt
Paste your bot token in the
Create a service for the temperature sensor:
Create a file called
sudo nano /etc/systemd/system/temperature_sensor.service
Paste the following:
[Unit] Description=ROT13 demo service After=network.target StartLimitIntervalSec=0 [Service] Type=simple Restart=always RestartSec=1 User=username ExecStart=python3 /path/to/sensor.py [Install] WantedBy=multi-user.target
Set your username after
User=and the path to
Enable the service by issuing on the terminal:
systemctl start temperature_sensor.service systemctl enable temperature_sensor.service
From the moment you start the service a reading will be taken by the sensor every 5 minutes and saved in a sqlite3 database.
Create a service for the telegram bot in an analogous way.
Your bot should be now active, in case of restart both the bot and the sensor will start automatically.
Once the bot is installed and running, send the
/start command on telegram to receive the list of available commands.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.