0
|
1 import asyncio
|
|
2 import logging
|
|
3
|
|
4 import aiomqtt
|
|
5
|
|
6 from bigastbot import BigAstBot
|
|
7
|
|
8 logging.basicConfig(level=logging.INFO,
|
|
9 format='%(asctime)s %(levelname)s %(name)s %(message)s',
|
|
10 datefmt='%Y-%m-%d %H:%M:%S')
|
|
11 log = logging.getLogger()
|
|
12
|
|
13
|
|
14 async def main():
|
|
15 bot = BigAstBot(email='doorbell-bot@chat.bigasterisk.com')
|
|
16
|
|
17 async with aiomqtt.Client("mqtt2.bigasterisk.com", ) as client:
|
|
18 await client.subscribe("doorbell/button")
|
|
19 log.info("waiting for messages")
|
|
20 async for message in client.messages:
|
|
21 if message.payload == b'pressed':
|
|
22 ret = bot.send_to_channel(channelName="front-door",
|
|
23 topic="doorbell",
|
|
24 content="🔔 ring!")
|
|
25 log.info(f"sent: {ret!r}")
|
|
26
|
|
27
|
|
28 asyncio.run(main())
|