A Telegram Bot that controls IOT devices on a Raspberry Pi Zero W and brings API data to the chat.
background: This project was first developed to monitor a server room's temperature using telegram bot to receive the values. As the time didn't help at that moment, I didn't finish the project. But now let's go.
Today it's a bot with multi-functions and programmable to receive more functions.
- Any Raspberry Pi - I'm using Raspberry Pi Zero W on headless
- DHT11 temperature and humidity sensor
- BC548 Transistor
- 10k Ohms Resistor
- 5VDC Relay module - 110/220VCC
- Telegram Bot API token
- Create with
@BotFather
on Telegram and it will give you the bot token - Enable inline commands and make the ones you want
Run pinout
on raspberry's terminal to see which pin to connect - see map
of the GPIO to see the connections.
- Install pip
sudo apt install python3-pip
- Install Adafruit DHT
pip3 install Adafruit_DHT
- Install Telepot
pip3 install telepot
- Install Python dotenv
pip3 install python-dotenv
- Copy scripts to raspberry pi home
./tempsense/settg.sh
- On Raspberry home, run
./start.sh
to begin the application,./stop.sh
to stop and./psaux.sh
to check if the application stopped.
Now just chat with the bot or add it on a group or channel. Functions below!
I'm leaving the other files to further study, so just ignore them - or don't.
Soon more info.
- Copy the service file to systemd directory
sudo cp tempsense.service /etc/systemd/system/
- Test to see if the script runs (you can stop it too)
sudo systemctl start tempsense.service
- Enable the autostart on boot
sudo systemctl enable tempsense.service
Any change on the system, remember to modify it on the service file.
- /temperature - Verifies the room's temperature 🌡
- /lumiere - Allumer la lampe 💡
- /led - Accendere il LED 🔦
- /naozhong - Dǎkāi nàozhōng ⏰
- /fala - Conversas aletórias 🗣️
- /miseru - 写真を見せる 📸
- /dailyinfo - Info about the mars or astronomy picture of the day 📝
- /astronomydaily - The astronomy picture of the day 🔭
- /marsdaily - The latest mars picture 🚀
- /listagem - Listagem de los comandos disponibles 📜
- /whoami - 🗣️
extra: /update - updates within repository
This is the transistor BC548 used to toggle 3v3 to the input of the relay.
- Add echo function
- Add dot env file - pass the token and chat ID there
- Add alarms functions
- Add new temperature function based on time
- Allow only known IDs
- Allow to update through git in outside network [in progress]
- New component -> relay (inside messages module).
- Now you can control something through a command in Telegram, like a lamp, some system, etc.
- In the way to do some IOT smart thing whatever.
- New script with Telegram bot. Interact with a bot to get temperature and humidity values.
- Raspberry GPIO pinout
- ASCII art with python
- Documentation learnt from @mislav poignant-guide repo
- Markdown mastering
- ADAFRUIT-DHT install
- ADAFRUIT-DHT python install
- DHT on adafruit example
- DHT on adafruit examples 2
- Telepot documentation
- File manager with python
- Dot env documentation
- Autostart on boot
WARNING: I don't know why, but if you add the bot already running in a group, the code AND the bot cracks, and it stops working forever, I lost like 4 bots doing that. If you know why please contact me or send and issue or PR i dunno. Thanks a lot!