Python Websockets to control QLC
Posted: Wed Dec 06, 2023 8:45 pm
Hi I'm new to the forum I hope this is in the right place. I was wondering if anyone could throw some light on this (see what I did there) I have a small podcast and have built quiz buttons that are controlled through esp33 wifi and Python, what I'm trying to do is have the lights change to the teams colours when their quiz button is pressed, I have set up the scenes on the virtual desk and they all work when I press the the button in QLC+ also I can get them to change on the web app and the Web test app by putting in the button ID and 255 for on and 0 for off. The problem I have is finding the right command to change the value of the button with Python using websockets. I can't find documentation to do this anywhere. I only mess with coding so It will be my fault, I have tried searching but I'm still turning up blank. I thought I would reach out and ask if anyone else has had any luck.
This is the code I have so far its taken from the forum and modified to try and change the value to from 0 to 255.
It basically checks and prints the value of button 0 then tries to change the value and rechecks and prints it again.
import asyncio
import websockets
async def test():
async with websockets.connect('ws://192.168.1.164:9999/qlcplusWS') as websocket:
await websocket.send("QLC+API|" + "getWidgetsList")
response = await websocket.recv()
widgets = []
llista = iter(response.split('|')[2:])
for i in llista:
widget = [i, next(llista)]
widgets.append(widget)
for i in widgets:
await websocket.send("QLC+API|" + "getWidgetType" + '|' + i[0])
response = await websocket.recv()
print("Button ID: ",i[0], response.split('|')[2])
await websocket.send("QLC+API|" + "getWidgetStatus" + '|' + i[0])
response = await websocket.recv()
print("Current Button value:", response)
await websocket.send("QLC+API|WidgetSetValue|0|BUTTON|255")
response = await websocket.recv()
print("Set Button to 255:", response)
await websocket.send("QLC+API|" + "getWidgetStatus" + '|' + i[0])
response = await websocket.recv()
print("New value:", response)
asyncio.get_event_loop().run_until_complete(test())
This is the line I'm struggling with websocket.send("QLC+API|WidgetSetValue|0|BUTTON|255") I'm not sure what should be in the widgetsetvalue
this is the result I'm getting the value stays at 0
Button ID: 0 Button
Current Button value: QLC+API|getWidgetStatus|0
Set Button to 255: QLC+API|WidgetSetValue|
New value: QLC+API|getWidgetStatus|0
hoping someone can help thanks Joe
This is the code I have so far its taken from the forum and modified to try and change the value to from 0 to 255.
It basically checks and prints the value of button 0 then tries to change the value and rechecks and prints it again.
import asyncio
import websockets
async def test():
async with websockets.connect('ws://192.168.1.164:9999/qlcplusWS') as websocket:
await websocket.send("QLC+API|" + "getWidgetsList")
response = await websocket.recv()
widgets = []
llista = iter(response.split('|')[2:])
for i in llista:
widget = [i, next(llista)]
widgets.append(widget)
for i in widgets:
await websocket.send("QLC+API|" + "getWidgetType" + '|' + i[0])
response = await websocket.recv()
print("Button ID: ",i[0], response.split('|')[2])
await websocket.send("QLC+API|" + "getWidgetStatus" + '|' + i[0])
response = await websocket.recv()
print("Current Button value:", response)
await websocket.send("QLC+API|WidgetSetValue|0|BUTTON|255")
response = await websocket.recv()
print("Set Button to 255:", response)
await websocket.send("QLC+API|" + "getWidgetStatus" + '|' + i[0])
response = await websocket.recv()
print("New value:", response)
asyncio.get_event_loop().run_until_complete(test())
This is the line I'm struggling with websocket.send("QLC+API|WidgetSetValue|0|BUTTON|255") I'm not sure what should be in the widgetsetvalue
this is the result I'm getting the value stays at 0
Button ID: 0 Button
Current Button value: QLC+API|getWidgetStatus|0
Set Button to 255: QLC+API|WidgetSetValue|
New value: QLC+API|getWidgetStatus|0
hoping someone can help thanks Joe