This bot receives information from sensors that are installed in the wall clock. Copy the file read_sensors.py from the Smart Home section to the folder with your bot.
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 |
import settings from telegram.ext import * from telegram import * from read_sensors import read_sensors def report_keyboard(): report_keyboard = [['report the microclimate at home']] return report_keyboard def start(update, context): if not update.message.chat_id == settings.my_chat_id: return update.message.reply_text("press the button to get information about the microclimate in the house",\ reply_markup=ReplyKeyboardMarkup(report_keyboard(), resize_keyboard=True)) def microclimate(update, context): if not update.message.chat_id == settings.my_chat_id: return micro_climate = read_sensors() update.message.reply_text(micro_climate, reply_markup=ReplyKeyboardMarkup(report_keyboard(), resize_keyboard=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('^report the microclimate at home'),microclimate)) # Start the Bot updater.start_polling() updater.idle() if __name__ == '__main__': main() |