From 0a791ca48ccdcc904a6600a7641221260ae5fc29 Mon Sep 17 00:00:00 2001 From: coon Date: Fri, 26 Sep 2025 23:09:13 +0200 Subject: [PATCH] mqtt_client.py: add auto discovery for home assistant --- mqtt_client.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/mqtt_client.py b/mqtt_client.py index 3f96c78..12a7f04 100644 --- a/mqtt_client.py +++ b/mqtt_client.py @@ -2,20 +2,44 @@ import argparse import json +import time import paho.mqtt.client as mqtt import mixer from mixer import Mixer + MQTT_SERVER_PORT = 1883 -MQTT_TOPIC = "homeassistant/device/mixer" +MQTT_DISCOVERY_TOPIC = "homeassistant/button/mixer/config" +MQTT_COMMAND_TOPIC = "livingroom/voc/allen_heath_qu16_mixer" m: Mixer = None +def mqtt_autodiscovery(client): + j = json.dumps( + { + "name": "Reset Settings", + "command_topic": MQTT_COMMAND_TOPIC, + "command_template": '{"command": "scene_recall", "args": {"scene_id": 0}}', + "device": { + "name": "Mischpult", + "model": "Qu-16", + "manufacturer": "Allen & Heath", + "suggested_area": "livingroom", + "identifiers": "Mischpult", + }, + "unique_id": "mischpult_reset_settings", + } + ) + + client.publish(MQTT_DISCOVERY_TOPIC, payload=j, qos=0, retain=False) + + def on_connect(client, userdata, flags, reason_code, properties): print(f"Connected: {reason_code}") - client.subscribe(MQTT_TOPIC) + client.subscribe(MQTT_COMMAND_TOPIC) + mqtt_autodiscovery(client) def on_message(client, userdata, msg):