Mercurial > code > home > repos > zulip
view 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 source
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())