External python files acts as if it is an embedded file

Posted on
Sat Jun 20, 2020 10:20 am
topsm offline
Posts: 8
Joined: Mar 30, 2015

External python files acts as if it is an embedded file

Hello, I have little knowledge about scripting but have been able to convert an applescript to python and it looks like I don't understand how to make the python file external.
I read in the forum that the EXTERNAL python file should be placed at /Library/Python/2.7/site-packages
I placed my python file there but when I run function from this file from within Indigo it kills the process because of too long processing time, most likely because of a time.sleep command of more than 10 seconds.
It seems to me that Indigo thinks it's an embedded python file.
Can anyone tell me how I can see the difference if a script is embedded or external.

Thanks in advance,

Marcel Tops

Posted on
Sat Jun 20, 2020 11:43 am
FlyingDiver online
User avatar
Posts: 5351
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: External python files acts as if it is an embedded file

Show how you're doing it now. Screenshot of the action dialog would be best.

And that location is where Python libraries go. Your personal scripts should be in '/Library/Application Support/Perceptive Automation/Python2-includes', I think.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sat Jun 20, 2020 12:40 pm
topsm offline
Posts: 8
Joined: Mar 30, 2015

Re: External python files acts as if it is an embedded file

Hi Joe,

Thanks for the fast response.

I don't know how to make the screenshot so I try to explain in text.
I call the function (Bioscoop_SK) (It's in dutch) in an action group:

from Bioscoop_SK import BioscoopSK

BioscoopSK("SK TV")

If I place the python files in the location you suggest, what should I then do to be able to call the function from these python files.
Placing the files where I did makes them embedded if I understand right.

Thanks,

Marcel

Posted on
Sat Jun 20, 2020 12:46 pm
FlyingDiver online
User avatar
Posts: 5351
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: External python files acts as if it is an embedded file

You're calling that as an embedded script that just happens to load the script file from a file on disk. But if the import and function call are in the box, then it's embedded. For an external script, you need to just specify the file to run:
Attachments
Screen Shot 2020-06-20 at 2.44.35 PM.png
Screen Shot 2020-06-20 at 2.44.35 PM.png (112.98 KiB) Viewed 565 times

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sat Jun 20, 2020 1:36 pm
topsm offline
Posts: 8
Joined: Mar 30, 2015

Re: External python files acts as if it is an embedded file

Hi Joe,

This is clarifying the embedded behaviour then but if I select file than there is no possibility to call the function(parameter) here, in this case BioscoopSK("SK TV")
I want to call this function with different parameters in different action groups.

As you can see I have very little understanding how this function calling works.

Posted on
Sat Jun 20, 2020 1:51 pm
FlyingDiver online
User avatar
Posts: 5351
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: External python files acts as if it is an embedded file

You'll probably need to change from the "execute script" action to the "run shell script" action. And make your Python script executable, and have it pick up the parameter from the command line.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sat Jun 20, 2020 2:56 pm
topsm offline
Posts: 8
Joined: Mar 30, 2015

Re: External python files acts as if it is an embedded file

Not yet sure how this all works as I have very little knowledge of unix as well but you set me on the right path regarding the embedded versus external file execution.
I will be looking further into the command line instructions tomorrow.

That you very much for your information, Will let you know when I succeeded.

Marcel

Posted on
Sun Jun 21, 2020 8:47 am
topsm offline
Posts: 8
Joined: Mar 30, 2015

Re: External python files acts as if it is an embedded file

Unfortunately I can not get the external script to work.
I used the command: Python /Library/Application\ Support/Perceptive\ Automation/Python2-includes/Bioscoop_SK.py "Kijk TV" in a shell for test and there it returns an error: ImportError: No module named indigo. When I run it from within Indigo action group shell script nothing happens and no messages displayed.

I want to run the python file from an action group with the argument "Kijk TV" which is used in the module BioscoopSK(mode). See code below (hack of collected bits and pieces from the forum and internet)

Is it possible to get this script to run external?

Code: Select all
#!/usr/bin/env python
# This Python file uses the following encoding: utf-8

import random, time, calendar
import indigo
import applescript
import os

# From a file
script_file_path = "/Library/Application Support/Perceptive Automation/Scripts_External/Indigo2iRed_Ext.scpt"
iRed = applescript.AppleScript(path=script_file_path)

def BioscoopSK(mode):

    versterker = 0
    tv = 0
    mediaplayer = 0
    bioscooplicht = 0

    SK_Bioscoop_var = indigo.variables[1389824491].getValue(str)          # read variable "SK_Bioscoop"
    SK_Bioscooplicht_var = indigo.variables[1923317447].getValue(str)     # read variable "SK_Bioscooplicht"
    SK_Kijk_Film_var = indigo.variables[367201486].getValue(str)          # read variable "SK_Kijk_Film"
    SK_Kijk_TV_var = indigo.variables[1991888223].getValue(str)           # read variable "SK_Kijk_TV"
    SK_Luister_Muziek_var = indigo.variables[1625817234].getValue(str)    # read variable "SK_Luister_Muziek"

    SK_MediaPlayer_var = indigo.variables[704464969].getValue(str)        # read variable "SK_MediaPlayer”
    SK_TV_var = indigo.variables[1033771403].getValue(str)                # read variable "SK_TV”
    SK_Versterker_var = indigo.variables[769372050].getValue(str)         # read variable "SK_Versterker”

    isDaylight_var = indigo.variables[517482721].getValue(str)            # read variable "isDaylight"
    Zon_Onder_Lux_var = indigo.variables[1778341929].getValue(str)        # read variable "Zon_Onder_Lux"

    # -- set variabeles depending on theatre mode
    if mode == "SK Bioscoop UIT":
        iRed.call("RemoteControl", "DENON AVR3312", "DENON/Receiver", "Mute", "IRTrans LAN")
        time.sleep(1)
        if SK_Bioscoop_var == "OFF":
            indigo.server.speak("Slaapkamer, Bioscoop is al uitgezet")
        else:
            indigo.server.speak("Slaapkamer, bioscoop wordt uitgezet")
            indigo.variable.updateValue(1389824491, value="OFF")                    # set variable "SK_Bioscoop" to "OFF"
            indigo.variable.updateValue(367201486, value="OFF")                     # set variable "SK_Kijk_Film" to "OFF"
            indigo.variable.updateValue(1991888223, value="OFF")                    # set variable "SK_Kijk_TV" to "OFF"
            indigo.variable.updateValue(1625817234, value="OFF")                    # set variable "SK_Luister_Muziek" to "OFF"

    if mode == "SK TV":
        if SK_Kijk_TV_var == "ON":
            indigo.server.speak("Slaapkamer, TV Kijken is al actief")
        else:
            indigo.server.speak("Slaapkamer, Kijk TV")
            indigo.variable.updateValue(1389824491, value="ON")                     # set variable "SK_Bioscoop" to "ON"
            tv = 1
            bioscooplicht = 1
    elif mode == "SK MediaPlayer":
        indigo.server.speak("Slaapkamer, Kijk film met X, treamer")
        indigo.variable.updateValue(1389824491, value="ON")                         # set variable "SK_Bioscoop" to "ON"
        mediaplayer = 1
        tv = 1
        bioscooplicht = 1

    # =====================================================================================================

    # -- Check if theater lights have to be on (Only after sunset)
    indigo.server.log("-- LUX -> variable isDaylight = " + isDaylight_var)
    indigo.server.log("-- LUX -> variable Zon_Onder_Lux = " + Zon_Onder_Lux_var)
    indigo.server.log("")

    if isDaylight_var == "false" or Zon_Onder_Lux_var == "true":
        indigo.server.log("-- LUX -> currently it's night time")
        if SK_Bioscooplicht_var == "OFF" and bioscooplicht == 1:
            indigo.server.log("-- LIGHTS -> switching theater lights on")
            indigo.actionGroup.execute(74020290)                                    # Execute Action Group: SK_Bioscoop_Licht_AAN
            time.sleep(1)
            indigo.server.speak("Bioscoop licht is aangezet")
            indigo.variable.updateValue(1923317447, value = "ON")                   # set variable "SK_BioscoopLicht" to "ON"
    else:
        indigo.server.log("-- LUX -> Currently it's day time")
    # =====================================================================================================

    # -- Check Variables and ON/OFF state of devices

    if SK_MediaPlayer_var == "OFF" and mediaplayer == 1:                            # switch mediaplayer on
        indigo.variable.updateValue(704464969, value = "ON")                        # set variable "SK_MediaPlayer" to "ON"
        indigo.device.turnOn(61763166)                                              # Turn Device ON "SK - iXtreamer")

    if SK_TV_var == "ON" and tv == 0:               # zet tv uit
        indigo.variable.updateValue(1033771403, value = "OFF")                       # set variable "SK_TV" to "OFF"
        iRed.call("RemoteControl", "LG TV", "LG Discrete/TV", "OFF", "IRTrans LAN")
        time.sleep(0.5)
        iRed.call("RemoteControl", "LG TV", "LG Discrete/TV", "OFF", "IRTrans LAN")
    elif SK_TV_var == "OFF" and tv == 1:            # zet tv aan
        indigo.variable.updateValue(1033771403, value = "ON")                        # set variable "SK_TV" to "ON"
        iRed.call("RemoteControl", "LG TV", "LG Discrete/TV", "ON", "IRTrans LAN")
        time.sleep(0.5)
        iRed.call("RemoteControl", "LG TV", "LG Discrete/TV", "ON", "IRTrans LAN")

    if SK_Versterker_var == "ON" and versterker == 0:                                # switch amplifier off
        indigo.variable.updateValue(769372050, value = "OFF")                        # set variable "SK_Versterker" to "OFF"
        iRed.call("RemoteControl", "DENON AVR3312", "DENON/Receiver", "Standby", "IRTrans LAN")
    elif SK_Versterker_var == "OFF" and versterker == 1:                             # switch amplifier on
        indigo.variable.updateValue(769372050, value = "ON")                         # set variable "SK_Versterker" to "ON"
        iRed.call("RemoteControl", "DENON AVR3312", "DENON/Receiver", "ON", "IRTrans LAN")

    # =====================================================================================================

    # -- Set Amplifier inputs depending of theatre mode
    if mode == "SK TV":
        if SK_Bioscoop_var == "ON":
            if SK_Kijk_Film_var == "ON":
                time.sleep(1)
                iRed.call("RemoteControl", "LG TV", "LG Discrete/TV", "TV", "IRTrans LAN")
        indigo.variable.updateValue(367201486, value = "OFF")         # set variable "SK_Kijk_Film" to "OFF"
        indigo.variable.updateValue(1991888223, value = "ON")         # set variable "SK_Kijk_TV" to "ON"
        indigo.variable.updateValue(1625817234, value = "OFF")        # set variable "SK_Luister_Muziek" to "OFF"
    elif mode == "SK MediaPlayer":
        if SK_Bioscoop_var == "ON":
            if SK_Kijk_TV_var == "ON":
                time.sleep(3)
                iRed.call("RemoteControl", "iXtreamer Player", "iXtreamer/MediaPlayer", "Standby", "IRTrans LAN")
                iRed.call("RemoteControl", "iXtreamer Player", "iXtreamer/MediaPlayer", "Standby", "IRTrans LAN")
                time.sleep(34)
                iRed.call("RemoteControl", "LG TV", "LG Discrete/TV", "HDMI2", "IRTrans LAN")
                time.sleep(5)
                iRed.call("RemoteControl", "iXtreamer Player", "iXtreamer/MediaPlayer", "ENTER", "IRTrans LAN")
                time.sleep(4)
                iRed.call("RemoteControl", "iXtreamer Player", "iXtreamer/MediaPlayer", "DOWN", "IRTrans LAN")
                time.sleep(1)
                iRed.call("RemoteControl", "iXtreamer Player", "iXtreamer/MediaPlayer", "DOWN", "IRTrans LAN")
                time.sleep(1)
                iRed.call("RemoteControl", "iXtreamer Player", "iXtreamer/MediaPlayer", "DOWN", "IRTrans LAN")
                time.sleep(1)
                iRed.call("RemoteControl", "iXtreamer Player", "iXtreamer/MediaPlayer", "ENTER", "IRTrans LAN")
                time.sleep(1)
            else:
                time.sleep(1)
        else:
            time.sleep(3)
            iRed.call("RemoteControl", "iXtreamer Player", "iXtreamer/MediaPlayer", "Standby", "IRTrans LAN")
            iRed.call("RemoteControl", "iXtreamer Player", "iXtreamer/MediaPlayer", "Standby", "IRTrans LAN")
            time.sleep(34)
            iRed.call("RemoteControl", "LG TV", "LG Discrete/TV", "HDMI2", "IRTrans LAN")
            time.sleep(5)
            iRed.call("RemoteControl", "iXtreamer Player", "iXtreamer/MediaPlayer", "ENTER", "IRTrans LAN")
            time.sleep(4)
            iRed.call("RemoteControl", "iXtreamer Player", "iXtreamer/MediaPlayer", "DOWN", "IRTrans LAN")
            time.sleep(1)
            iRed.call("RemoteControl", "iXtreamer Player", "iXtreamer/MediaPlayer", "DOWN", "IRTrans LAN")
            time.sleep(1)
            iRed.call("RemoteControl", "iXtreamer Player", "iXtreamer/MediaPlayer", "DOWN", "IRTrans LAN")
            time.sleep(1)
            iRed.call("RemoteControl", "iXtreamer Player", "iXtreamer/MediaPlayer", "ENTER", "IRTrans LAN")
            time.sleep(1)
        indigo.variable.updateValue(367201486, value = "ON")          # set variable "SK_Kijk_Film" to "ON"
        indigo.variable.updateValue(1991888223, value = "OFF")        # set variable "SK_Kijk_TV" to "OFF"
        indigo.variable.updateValue(1625817234, value = "OFF")        # set variable "SK_Luister_Muziek" to "OFF"

    if mode == "WK Bioscoop UIT":
        iRed.call("RemoteControl", "DENON AVR3312", "DENON/Receiver", "Mute", "IRTrans LAN")
        indigo.variable.updateValue(1389824491, value="OFF")          # set variable "SK_Bioscoop" to "OFF"
        indigo.variable.updateValue(367201486, value = "OFF")         # set variable "SK_Kijk_Film" to "OFF"
        indigo.variable.updateValue(1991888223, value = "OFF")        # set variable "SK_Kijk_TV" to "OFF"
        indigo.variable.updateValue(1625817234, value = "OFF")        # set variable "SK_Luister_Muziek" to "OFF"
    else:
        indigo.variable.updateValue(1389824491, value="ON")           # set variable "SK_Bioscoop" to "ON"

    # =====================================================================================================

    # -- Check if theater lights have to be switched off.
    if isDaylight_var == "false" or Zon_Onder_Lux_var == "true":
        if SK_Bioscooplicht_var == "ON" and bioscooplicht == 0:
            indigo.actionGroup.execute(394630618)                     # Action Group: SK_Alle_Lichten_uit
            time.sleep(0.5)
            indigo.server.speak("Slaapkamer, Bioscoop licht is uit gezet")
            indigo.variable.updateValue(1923317447, value = "OFF")    # set variable "SK_BioscoopLicht" to "OFF"

    # -- Check if Mediaplayer must be switched off
    if SK_MediaPlayer_var == "ON" and mediaplayer == 0:                             # switch mediaplayer off
        indigo.variable.updateValue(704464969, value = "OFF")                       # set variable "SK_MediaPlayer" to "OFF"
        time.sleep(23)
        indigo.device.turnOff(61763166)                                             # Turn Device OFF "SK - iXtreamer")

    # =====================================================================================================

    indigo.server.speak("Klaar")
    return

Posted on
Sun Jun 21, 2020 10:35 am
FlyingDiver online
User avatar
Posts: 5351
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: External python files acts as if it is an embedded file

Yeah, I may have led you down the wrong path. You need to use the "Execute Script" action in order for "import indigo" to work. So instead of trying to pass the mode as a command line argument, do it as the value of a variable. So your action group would consist of two actions, the first to set the mode variable, the second to call the external script. Make sure you delay the script call by a second (or less) to make sure the variable has been set before the script executes.

Then your script would start with something like:

Code: Select all
#! /usr/bin/env python
# -*- coding: utf-8 -*-
####################

import random, time, calendar
import indigo
import applescript
import os

script_file_path = "/Library/Application Support/Perceptive Automation/Scripts_External/Indigo2iRed_Ext.scpt"
iRed = applescript.AppleScript(path=script_file_path)
mode = indigo.variables[987654321].getValue(str)
BioscoopSK(mode)

def BioscoopSK(mode):

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sun Jun 21, 2020 11:22 am
topsm offline
Posts: 8
Joined: Mar 30, 2015

Re: External python files acts as if it is an embedded file

Joe, thank you very much,

After a small change in the example you sent me it's now working.
I got an error that BioscoopSK was not yet defined so I moved the line: BioscoopSK(mode) after the last line: Return

Finally got this to work after searching for days.
Again, thank you very very very much

Marcel

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest