Mercurial > code > home > repos > mqtt_metrics
diff mqtt_metrics.py @ 6:bc2a93b306e9
port over the powermeter measurements
author | drewp@bigasterisk.com |
---|---|
date | Sat, 10 Aug 2024 23:03:57 -0700 |
parents | 8390d5d0d512 |
children | a640efa9fb01 |
line wrap: on
line diff
--- a/mqtt_metrics.py Sat Aug 10 23:02:51 2024 -0700 +++ b/mqtt_metrics.py Sat Aug 10 23:03:57 2024 -0700 @@ -59,10 +59,27 @@ return message +async def requestStatuses(client: aiomqtt.Client, period=10): + '''shellys post status updates periodically, but I want them more often.''' + while True: + for topic in [ + "do-r-power/command/switch:0", + "ga-fridge-power/command/switch:0", + "ga-washer-power/command/switch:0", + "tt-fridge-power/command/switch:0", + "ws-bench-power/command/switch:0", + "ws-desk-power/command/switch:0", + "ws-solder-power/command/switch:0", + ]: + await client.publish(topic, 'status_update') + await asyncio.sleep(period) + + async def mqttTask(metrics: MetricsWriter): try: client = aiomqtt.Client('mqtt2.bigasterisk.com', identifier="mqtt-exporter") async with client: + asyncio.create_task(requestStatuses(client)) await client.subscribe('#') async for mqttMessage in client.messages: try: