Control Your Smart Home Devices with Telegram and n8n– Integrating Telegram with n8n to control your smart home devices gives you a fast, secure, and highly customizable way to manage your lights, fans, appliances, and more. With just a few commands in Telegram, you can turn devices ON or OFF instantly, even when you’re away from home. This detailed guide will walk you through every step — from setting up a Telegram bot to sending commands through n8n workflows that trigger your devices via API calls or Home Assistant.
1. Prerequisites for Setting Up Telegram + n8n Smart Home Control
Before starting, ensure you have:
- n8n Installed — You can run n8n locally, in Docker, or through the n8n cloud platform.
- A Telegram Bot — Created through BotFather.
- Smart Home Devices with API Access — Examples: Tuya, Shelly, Sonoff, or any brand supported by Home Assistant or MQTT.
- API Endpoints or MQTT Broker Details — These are necessary to control the devices.
- Basic Networking Knowledge — Helps with configuring authentication and API requests.
2. Create a Telegram Bot for Smart Home Control
You need a Telegram bot to receive your ON/OFF commands.
- Open Telegram and search for BotFather.
- Send the command:
- /newbot
- Assign a name and a username for your bot.
- BotFather will provide a Bot Token — save it securely, as it will be used in n8n.
3. Set Up a Webhook Trigger in n8n
In n8n, the Telegram Trigger Node will listen for incoming messages from your bot.
- Open the n8n dashboard.
- Create a new workflow.
- Add a Telegram Trigger Node:
- Mode: Webhook (recommended) or Polling.
- Bot Token: Paste the token from BotFather.
- Trigger Action: Listen for specific text commands like /on or /off.
- Save and activate the workflow.
This ensures that every time you send a command to your Telegram bot, n8n will process it.
4. Parse the Telegram Commands in n8n
We need to differentiate between ON and OFF commands.
- After the Telegram Trigger Node, add a Switch Node or IF Node.
- Configure the conditions:
- Case 1: If message.text equals /on.
- Case 2: If message.text equals /off.
This setup ensures the correct device action is executed depending on your Telegram command.
5. Send Device Control Commands via API
You can control your smart devices in two main ways:
A. Using Direct HTTP Requests to the Device API
You can send ON/OFF commands directly if your device supports a REST API.
Example for Tuya Cloud API:
http POST https://openapi.tuya.com/v1.0/devices/{device_id}/commands Headers: Content-Type: application/json Authorization: Bearer YOUR_ACCESS_TOKEN Body: { "commands": [ { "code": "switch_1", "value": true } ] }
- Replace {device_id} with your actual device ID.
- Set “value”: false for turning OFF.
B. Using Home Assistant for Device Control
If your devices are integrated into Home Assistant, you can use its REST API:
http POST http://YOUR_HOME_ASSISTANT_IP:8123/api/services/switch/turn_on Headers: Authorization: Bearer YOUR_LONG_LIVED_ACCESS_TOKEN Content-Type: application/json Body: { "entity_id": "switch.living_room_light" }
- Change the switch to living_room_light to match your Home Assistant entity.
- Use switch/turn_off for OFF commands.
6. Sending Confirmation Messages Back to Telegram
To confirm actions, send a Telegram Message Node after the device control step:
If the device is turned ON, send:
- graphql
- Device successfully turned ON.
If the device is turned OFF, send:
- vbnet
- Device successfully turned OFF.
This feedback ensures you always know if the command worked.
7. Testing Your Setup
Once configured, test the automation:
- In Telegram, type /on.
- The connected device should turn ON.
- You should receive a confirmation message.
- Type /off.
- The device should turn OFF.
- A confirmation message will appear.
8. Adding Multiple Devices and Custom Commands
You can extend your workflow to control multiple devices:
- Custom Commands:
- /fanon — Turn on fan.
- /fanoff — Turn off fan.
- /lighton — Turn on lights.
- /lightoff — Turn off lights.
- Workflow Changes:
- Add extra Switch Node conditions for each device.
- Link each case to its corresponding HTTP Request.
9. Using MQTT for Non-API Devices
If your smart device doesn’t have a public API but supports MQTT, n8n can still control it:
- Install and configure MQTT Broker (e.g., Mosquitto).
- Use n8n’s MQTT Node to publish ON/OFF messages.
- Your device must subscribe to the corresponding MQTT topic.
Example MQTT message:
json
{
“state”: “ON”
}
10. Security and Best Practices
To ensure safe remote access:
- Use strong BotFather tokens and never share them.
- Restrict n8n webhook URLs to trusted IPs.
- Use HTTPS for secure API calls.
- Store API keys in n8n’s credentials manager, not in plain text.
11. Example Workflow Overview in n8n
- Telegram Trigger Node — Receives the command.
- Switch Node — Decides ON/OFF or other device commands.
- HTTP Request / MQTT Node — Sends command to device.
- Telegram Node — Sends back confirmation.
Wrap Up
By combining Telegram with n8n, you can create a fast, reliable, and secure smart home control system that works from anywhere in the world. The setup is highly customizable, supports multiple devices, and works with APIs, MQTT, and Home Assistant integrations.
You now have the power to control your entire home with just a few Telegram commands.
Ask Follow-up Question from this topic With Google Gemini: Control Your Smart Home Devices with Telegram and n8n – Complete Step-by-Step Guide

Selva Ganesh is the Chief Editor of this blog. A Computer Science Engineer by qualification, he is an experienced Android Developer and a professional blogger with over 10 years of industry expertise. He has completed multiple courses under the Google News Initiative, further strengthening his skills in digital journalism and content accuracy. Selva also runs Android Infotech, a widely recognized platform known for providing in-depth, solution-oriented articles that help users around the globe resolve their Android-related issues.
Leave a Reply