mqtt_client.py: add auto discovery for home assistant
This commit is contained in:
parent
6b8c57441f
commit
5ae6d1f832
2 changed files with 26 additions and 3 deletions
|
@ -28,7 +28,7 @@ def main():
|
||||||
j = json.dumps({"command": "scene_recall", "args": {"scene_id": 0}})
|
j = json.dumps({"command": "scene_recall", "args": {"scene_id": 0}})
|
||||||
# j = json.dumps({'command': 'shutdown'})
|
# j = json.dumps({'command': 'shutdown'})
|
||||||
|
|
||||||
client.publish(mqtt_client.MQTT_TOPIC, payload=j, qos=0, retain=False)
|
client.publish(mqtt_client.MQTT_COMMAND_TOPIC, payload=j, qos=0, retain=False)
|
||||||
|
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
|
|
|
@ -7,15 +7,38 @@ import paho.mqtt.client as mqtt
|
||||||
import mixer
|
import mixer
|
||||||
from mixer import Mixer
|
from mixer import Mixer
|
||||||
|
|
||||||
|
|
||||||
MQTT_SERVER_PORT = 1883
|
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
|
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):
|
def on_connect(client, userdata, flags, reason_code, properties):
|
||||||
print(f"Connected: {reason_code}")
|
print(f"Connected: {reason_code}")
|
||||||
client.subscribe(MQTT_TOPIC)
|
client.subscribe(MQTT_COMMAND_TOPIC)
|
||||||
|
mqtt_autodiscovery(client)
|
||||||
|
|
||||||
|
|
||||||
def on_message(client, userdata, msg):
|
def on_message(client, userdata, msg):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue