diff bots/doorbell.py @ 0:96f842f12121

start
author drewp@bigasterisk.com
date Tue, 28 Jan 2025 23:30:02 -0800
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bots/doorbell.py	Tue Jan 28 23:30:02 2025 -0800
@@ -0,0 +1,28 @@
+import asyncio
+import logging
+
+import aiomqtt
+
+from bigastbot import BigAstBot
+
+logging.basicConfig(level=logging.INFO,
+                    format='%(asctime)s %(levelname)s %(name)s %(message)s',
+                    datefmt='%Y-%m-%d %H:%M:%S')
+log = logging.getLogger()
+
+
+async def main():
+    bot = BigAstBot(email='doorbell-bot@chat.bigasterisk.com')
+
+    async with aiomqtt.Client("mqtt2.bigasterisk.com", ) as client:
+        await client.subscribe("doorbell/button")
+        log.info("waiting for messages")
+        async for message in client.messages:
+            if message.payload == b'pressed':
+                ret = bot.send_to_channel(channelName="front-door",
+                                          topic="doorbell",
+                                          content="🔔 ring!")
+                log.info(f"sent: {ret!r}")
+
+
+asyncio.run(main())