A Telegram bot for controlling a Tuya-based automatic pet feeder over the local network.
Feed your pet on demand or set up scheduled daily feedings — all from a Telegram chat.
- On-demand feeding — dispense food portions with a single
/feedcommand - Device status — query the feeder's current state and data points
- Scheduled timers — set up recurring daily feedings at specific times
- Multi-user access — authorize additional Telegram users on the fly
- Local communication — talks directly to the Tuya device on your LAN via tinytuya (no cloud dependency)
- Docker-ready — ships with a multi-stage
Dockerfileanddocker-compose.yml - Persistent config — timers and user list survive restarts
| Command | Description |
|---|---|
/start |
Greet and verify access |
/help |
Show available commands |
/myid |
Get your Telegram user ID (no auth required) |
/feed |
Dispense food (configured number of portions) |
/status |
Query and display the device state |
/addtimer HH:MM portions |
Schedule a daily feeding (e.g. /addtimer 08:00 2) |
/timers |
List all scheduled feedings |
/deletetimer HH:MM |
Remove a scheduled feeding |
/adduser <user_id> |
Add a Telegram user to the allowed list |
- Python 3.12+
- A Tuya-compatible automatic pet feeder on your local network
- Tuya device credentials (
device_id,local_key) — see the tinytuya setup guide - A Telegram Bot token from @BotFather
- Docker and Docker Compose (for containerized deployment)
git clone https://github.com/YOUR_USERNAME/petfeeder-bot.git
cd petfeeder-bot
cp petfeeder.conf.example petfeeder.conf
Edit petfeeder.conf and fill in your values:
[telegram]
bot_token = YOUR_BOT_TOKEN_HERE
allowed_user_ids = 123456789
[device]
device_id = YOUR_DEVICE_ID
ip_address = 192.168.1.100
local_key = YOUR_LOCAL_KEY
version = 3.5
feed_dp = 3
portions = 1
[logging]
level = INFO
file = petfeeder.logTip: Use @userinfobot on Telegram to find your user ID, or send
/myidto the bot once it's running.
docker compose up -d --build
The bot uses host networking so that tinytuya can reach the feeder over your local network.
Check logs:
docker compose logs -f
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python petfeeder_bot.py
| Option | Description |
|---|---|
bot_token |
Telegram Bot API token from @BotFather |
allowed_user_ids |
Comma-separated list of authorized Telegram user IDs |
| Option | Description |
|---|---|
device_id |
Tuya device ID |
ip_address |
Local IP address of the feeder |
local_key |
Tuya device local key |
version |
Tuya protocol version (3.1, 3.3, 3.4, or 3.5) |
feed_dp |
Data point index that triggers feeding |
portions |
Default number of portions per feed command |
| Option | Description | Default |
|---|---|---|
timezone |
IANA timezone for timer scheduling (e.g. Europe/Moscow) |
UTC |
| Option | Description | Default |
|---|---|---|
level |
Log level: DEBUG, INFO, WARNING, ERROR, CRITICAL |
INFO |
file |
Log file path (empty = stdout only) | (empty) |
The project includes a production-ready Docker setup:
- Multi-stage build — keeps the final image small
- Non-root user — runs as
appuser(UID 1000) for security - Health check — built-in process liveness check
- Host networking — required for local Tuya device communication
- Volume mounts — config file (read-only) and logs directory are mounted from the host
| Variable | Description | Default |
|---|---|---|
TZ |
Container timezone (for log timestamps) | UTC |
A deployment script is included for pushing updates to a remote server:
./deploy.sh USER@HOST:/path/to/petfeeder-bot "Optional commit message"
The script will:
- Commit and push local changes via Git
- Copy the config file to the remote server (if present)
- Rebuild the Docker image and restart the container on the remote host
- Display deployment status and recent logs
petfeeder-bot/
├── petfeeder_bot.py # Main bot application
├── petfeeder.conf.example # Example configuration file
├── requirements.txt # Python dependencies
├── Dockerfile # Multi-stage Docker build
├── docker-compose.yml # Docker Compose service definition
├── deploy.sh # Deployment automation script
├── .gitignore
└── .dockerignore
| Package | Purpose |
|---|---|
python-telegram-bot >=21.0 |
Telegram Bot API framework (with job queue for timers) |
tinytuya >=1.13.0 |
Local Tuya device communication |
To control your feeder locally, you need the device_id, local_key, and protocol version. Follow the tinytuya setup instructions which involves:
- Creating a Tuya IoT developer account
- Linking your Tuya/Smart Life app
- Running
python -m tinytuya wizardto extract credentials
You can also use python -m tinytuya scan to discover the device's local IP address and protocol version.
This project is provided as-is for personal use.