hey I am just trying to trigger a shortcut on a PC after I push a button (mqtt) is that possible?
yes, i put together one way with MQTT, Send an MQTT message from HA, and there’s a script that runs on your pc to carry out the actions. Launch an app on a Windows PC
I found it easier to use node red to carry out the actions,(Above) but it can all be done in HA
+1 for paho mqtt - minimal python script setup to run netflix in browser, launch plex media player below…
You’d run this on your HTPC and fill in the details to connect it to your MQTT broker e.g. mosquitto (installs in 5mins)
import paho.mqtt.client as mqtt
import subprocess
import ujson, webbrowser
MQ_CHANNEL = "SOME_CHANNEL_NAME"
USERNAME = "YOUR_MQTT_USERNAME"
PASSWORD = "YOUR_MQTT_PASSWORD"
MQTT_HOST = "127.0.0.1"
MQTT_PORT = 1883
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
client.subscribe(f"{MQ_CHANNEL}/#")
def extract_payload(payload):
try:
return ujson.loads(payload.decode())
except Exception:
return payload.decode()
def command_plex(data):
if data.get("args") == "start":
subprocess.call(['C:\\Program Files\\Plex\\Plex Media Player\\PlexMediaPlayer.exe'])
def command_chrome(data):
chrome_path = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s"
if data.get("args") == "start_netflix":
webbrowser.get(chrome_path).open("www.netflix.com")
def router(data):
if data.get("command") == "plex":
return command_plex(data)
elif data.get("command") == "chrome":
return command_chrome(data)
def on_message(client, userdata, msg):
channel = msg.topic.replace(f"{MQ_CHANNEL}/", "")
data = extract_payload(msg.payload)
print(f"Received message on channel: {channel}, message: {data}")
router(data)
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.username_pw_set(USERNAME, PASSWORD)
client.connect(MQTT_HOST, MQTT_PORT, 10)
client.loop_forever()
publish MQTT data from home assistant as json payloads:
- service: mqtt.publish
data:
payload: '{ "command": "plex", "args": "start" }'
topic: SOME_CHANNEL_NAME/myhtpcname
- service: mqtt.publish
data:
payload: '{ "command": "chrome", "args": "start_netflix" }'
topic: SOME_CHANNEL_NAME/myhtpcname