What I am trying to do is execute a python script from a lua script. Seems straight forward and cut and dry but I still have not figured out why it will not run.
Here is the lua script - triggered by the off action on an on/off switch - and how its executed in the device - Off Action: script://scripts\lus\stopcast.lua
Code: Select all
print("Stoping Chromecast ")
-- this is the line not executing
os.execute('start pythonw "C:\\Program Files (x86)\\Domoticz\\scripts\\python\\stop_casting.pyw"')
Here is the python code for - stop_casting.pyw. Its a script to force a Chromecast device to disconnect -Spotify constantly hanging
Code: Select all
import pychromecast
import urllib
import json
sun = urllib.request.urlopen("http://192.168.1.2:8080/json.htm?type=devices&rid=86")
data = sun.read().decode('utf-8')
parts = json.loads(data)
nord = parts['result'][0]['Data']
print(nord)
chromecasts = pychromecast.get_chromecasts()
cast = next(cc for cc in chromecasts if cc.device.friendly_name == "Den TV")
cast.wait()
status = cast.status.status_text
if (status == "Netflix" or status == "YouTube") and nord == "night":
data = urllib.request.urlopen("http://192.168.1.2:8080/json.htm?type=command¶m=switchlight&idx=86&switchcmd=Off")
data = urllib.request.urlopen("http://192.168.1.2:8080/json.htm?type=command¶m=switchscene&idx=3&switchcmd=On")
log = urllib.request.urlopen("http://192.168.1.2:8080/json.htm?type=command¶m=addlogmessage&message=Disconnected+Den+TV+Chromecast")
cast.quit_app()
quit()
Now if I rename the lue script to script_time_stopcast.lua - everything works as expected - every minute if casting to the device - its disconnected.
Things I have tried with no luck:
Run the python from the off action - nothing
Run a python script using a subprocess - thinking the script was taking to long. - nothing
Run a lua script using an io.popen statement:
Code: Select all
cmd ='cmd /C python "C:\\Program Files (x86)\\Domoticz\\scripts\\python\\stopCast.pyw"
local f = assert(io.popen(cmd, 'r'))'
Running Domoticz: 2020-2, Windows 10 and python 3.8.2
Any help, insight or shared experience - confirmation of this being a problem - would be greatly appreciated.