add hass_button_emulator.py with mqtt test
This commit is contained in:
parent
872d56fcbd
commit
2ae803ebfe
1 changed files with 36 additions and 0 deletions
36
hass_button_emulator.py
Executable file
36
hass_button_emulator.py
Executable file
|
@ -0,0 +1,36 @@
|
|||
#!/bin/python
|
||||
|
||||
import time
|
||||
import paho.mqtt.client as mqtt
|
||||
import json
|
||||
|
||||
MQTT_SERVER_ADDRESS = "localhost"
|
||||
MQTT_SERVER_PORT = 1883
|
||||
MQTT_TOPIC = "homeassistant/device/mixer"
|
||||
|
||||
|
||||
def on_connect(client, userdata, flags, reason_code, properties):
|
||||
print(f"Connected: {reason_code}")
|
||||
client.subscribe("#")
|
||||
|
||||
|
||||
def on_message(client, userdata, msg):
|
||||
print(f"{msg.topic}: {msg.payload.decode()}")
|
||||
|
||||
|
||||
client = mqtt.Client(callback_api_version=mqtt.CallbackAPIVersion.VERSION2)
|
||||
client.on_connect = on_connect
|
||||
client.on_message = on_message
|
||||
|
||||
client.connect(MQTT_SERVER_ADDRESS, MQTT_SERVER_PORT, 60)
|
||||
client.loop_start()
|
||||
|
||||
j = json.dumps({"command": "scene_recall", "args": {"scene_id": 42}})
|
||||
# j = json.dumps({'command': 'shutdown'})
|
||||
|
||||
client.publish(MQTT_TOPIC, payload=j, qos=0, retain=False)
|
||||
|
||||
time.sleep(2)
|
||||
|
||||
client.loop_stop()
|
||||
client.disconnect()
|
Loading…
Add table
Add a link
Reference in a new issue