giomania Posted January 16, 2022 Posted January 16, 2022 I realize this is probably a dumb question, but I was wondering if it is possible to run Python scripts on the Polisy? A member of AVS Forum wrote and shared basic script that retrieves the numeric volume level from an Audio/Video Processor (The Monolith HTP-1) and displays the volume level on a Video Processor (the Lumagen Radiance Pro). The HTP-1 does not have an OSD, and if the unit is behind a cabinet door, the display on the unit cannot be seen, so this is a very handy tool. He runs this script on a Rasberry Pi, but I figured this might work on the Polisy Pro. I looked at the NodeServer store, and if there is something in there that would facilitate this, I missed it. Here is the post, for any interested in the provenance, and below is the code he wrote. Thanks for any input / advice. Mark Python: # A very basic example showing how to do # Lumagen OSD volume messages from HTP1 using Python 3.7 # Probably very bad. But it does work. import asyncio import websockets import json import re import time import serial # edit to be host name / IP address of HTP1 htp1ip = "192.168.10.185" global volume volume = 0 # This function actually does the listening for JSON on websockets, # working out if it is a volume message and setting it if it is async def htp1(): print ("start htp1") global volume uri = "ws://" + htp1ip + "/ws/controller" async with websockets.connect(uri) as websocket: while True: message = await websocket.recv() if message.startswith ("msoupdate ["): # strip the "msoupdate " from the returned message message = message[10:] jsonlist = json.loads (message) for jsondict in jsonlist: # if this was a volume message, set the volume value if jsondict['path'] == '/volume': volume = jsondict['value'] await asyncio.sleep(0.01) # This function sends simple OSD messages to the Lumagen. # It is lazy and sets the OSD colours every message as that # avoids dealing with any messages from the Lumagen. async def lumagen (): print ("start lumagen") global volume prev_volume = 0 ser = serial.Serial('/dev/ttyUSB0',9600,timeout=0.1) while True: if prev_volume != volume: prev_volume = volume osdStr='ZY4180000000\r\n' ser.write(bytes(osdStr,'ascii')) osdStr='ZY4181FFFFFF\r\n' ser.write(bytes(osdStr,'ascii')) osdStr='ZY4182000004\r\n' ser.write(bytes(osdStr,'ascii')) ostring = str(volume) ostring = ostring + "\n" ostring = "ZT1" + ostring ser.write(bytes(ostring,'ascii')) await asyncio.sleep(0.01) # main loop, if there is an exception sleep for 5s and try again. async def main(): print ("main loop") while True: try: taskhtp1 = asyncio.create_task (htp1()) tasklumagen = asyncio.create_task (lumagen()) await taskhtp1 await tasklumagen except: print ("An exception occurred. Retry in 5 seconds") time.sleep (5) asyncio.run(main())
larryllix Posted January 17, 2022 Posted January 17, 2022 I run several python3 scripts on my polisy. I had them running with PG1 but when PG2 was released they began to fail about once per month or so. I switched them back to a RPi for a time and now they are back on my polisy again, running without problems, so far. Time will tell. My ~25 WiFi RGBCW bulbs and strips run off this software on polisy, as a bridge between ISY NR and WiFi signals. You may need to upgrade your script to python3 syntax. I don't know much about python2 code but I doubt the print statements will run without losing the space between print and "(". 1
giomania Posted January 17, 2022 Author Posted January 17, 2022 Thanks Larry, Sounds like it is doable, but unfortunately not possible for me to do this on my own, as I would have no idea without a step-by-step, lol. Mark
larryllix Posted January 17, 2022 Posted January 17, 2022 4 minutes ago, giomania said: Thanks Larry, Sounds like it is doable, but unfortunately not possible for me to do this on my own, as I would have no idea without a step-by-step, lol. Mark I don't know all the nuances of python2 to python3 but there wasn't that many unless you did some uncommon code things. AFAIK you should be able to just delete the spaces behind the print statement and it should work on polisy. Since print() is a function in python3 it should look like this print("xxxxxx") If you are not familiar with python you should likely stay away from your polisy and use a RPi as your "proving grounds" first. After you are confident the code works and understand some of the basics hen port it over.
giomania Posted January 17, 2022 Author Posted January 17, 2022 10 hours ago, larryllix said: I don't know all the nuances of python2 to python3 but there wasn't that many unless you did some uncommon code things. AFAIK you should be able to just delete the spaces behind the print statement and it should work on polisy. Since print() is a function in python3 it should look like this print("xxxxxx") If you are not familiar with python you should likely stay away from your polisy and use a RPi as your "proving grounds" first. After you are confident the code works and understand some of the basics hen port it over. I did not write the code, an AVS Forum member did, and he is using it on a RPi. My initial thought was to get a Pi and copy his code over, but then I was wondering if I could run it on Polisy, so I posted here. I'm not sure it makes sense to get a Pi only for this, function, but I will think about it. Realistically, it is probably over my pay grade, since I do not even know where to enter the syntax. That said, I have not searched for any step-by-step guides that may exist. Now if someone made a Polyglot where you could just paste in the code, then I could probably manage to figure that out. Thanks again for the input.
mmb Posted January 17, 2022 Posted January 17, 2022 @giomania I run several Python scripts (Alarm system, UPS monitor, etc) on a separate server and those scripts remotely set variables on the ISY. I have ISY Programs watching and reporting on those variables. I haven't explored using Polyglot for these scripts but I do use PG for weather reporting. 1
Recommended Posts