This bot is designed to control household devices via an infrared or radio channel via telegrams. The bot uses a universal Broadlink remote control described in the Smart Home Can section. For example, I made the bot only two buttons: ‘TV’ and ‘HOOVER’. You can do more. Device management is completely safe because the script only works from a unique chat-id telegram.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import settings from telegram.ext import * from telegram import * import re import sys, os, subprocess def remote_keyboard(): remote_keyboard = [['TV','HOOVER']] return remote_keyboard def start(update, context): if update.message.chat_id == settings.my_chat_id: update.message.reply_text("remote control mode", reply_markup=ReplyKeyboardMarkup(remote_keyboard(), resize_keyboard=True)) def remote(update, context): if update.message.chat_id == settings.my_chat_id: text = '' if update.message.text == 'TV': text = 'TV power' cmd = '/home/pi/bot/python-broadlink/broadlink_cli type 0x279d host 192.168.1.36 mac 780f77fd7532 learnfile HOME-TV.power' if update.message.text == 'HOOVER': text = 'Hover power' cmd = '/home/pi/bot/python-broadlink/broadlink_cli type 0x279d host 192.168.1.36 mac 780f77fd7532 learnfile HOME-TV.power' update.message.reply_text(text, reply_markup=ReplyKeyboardMarkup(remote_keyboard(), resize_keyboard=True)) subprocess.Popen(cmd, shell = True) def main(): updater = Updater(settings.TELEGRAM_API_KEY, use_context=True) dp = updater.dispatcher dp.add_handler(CommandHandler("start", start)) dp.add_handler(MessageHandler(Filters.regex('^(TV)|(HOOVER)'),remote)) # Start the Bot updater.start_polling() updater.idle() if __name__ == '__main__': main() |