Mercurial > code > home > repos > zulip
view bots/doorbell.py @ 1:2a288d2cb88c
add unread_to_mqtt bridge
author | drewp@bigasterisk.com |
---|---|
date | Tue, 11 Feb 2025 19:20:47 -0800 |
parents | 96f842f12121 |
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())