I am struggling with Modules not being found , even though they are in the same folder as one another.
I have stored my scripts here: /Users/brian/Documents/Home Automation/Python Scripts
I can use any of these scripts from inside of Indigo, server, script action, and choose any of the scripts, but I want to leverage reusable functions, and trying to get one script file to import functions from a master script file.
I had no PYTHONPATH, so I tried establishing one to the path above
macserver:~ brian$ echo $PYTHONPATH
/Users/brian/Documents/Home Automation/Python Scripts
It seems I still cannot get the modules to import. I managed to use nano to write a bash file (like I have any idea what that all means ) and even included my python folder in the main path statement:
macserver:~ brian$ echo $PATH
/Users/brian/Documents/Home Automation/Python Scripts:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Server.app/Contents/ServerRoot/usr/bin:/Applications/Server.app/Contents/ServerRoot/usr/sbin
It appears I am on an old version of Python, and the tutorials for importing seem to differ depending on the version.
macserver:~ brian$ python --version
Python 2.7.10
Are spaces in the folder structure a problem, I can rename them , just need to tweak my action groups to reflect a new script location, but I can do that if it will help.
Can anyone point me in the right direction?
PS . I am also not a developer, but learning a little every week. I included code below from a file I wrote, welcome any tips on making better python scripts. I find myself making small tweaks during the week. You may notice some references not yet used, like light level, that is for future features.
My biggest frustration learning python was the spacing in python that VBA just does not care about... Thanks to all in this forum for helping me out with that hurdle.
Many thanks!
- Brian
- Code: Select all
import datetime
import time
import calendar
airfoilPlugin = indigo.server.getPlugin("com.perceptiveautomation.indigoplugin.Airfoil")
SlidingLightLevel = indigo.devices[495566140]
BackYardLightLevel = SlidingLightLevel.sensorValue * -0.1
myVar = indigo.variables[461896218] # GoodNight Variable
timestamp = datetime.datetime.now().time() # Throw away the date information
TimetooEarly = datetime.time(9, 30)
TooLate = datetime.time(19)
KitchenOnly = datetime.time(20)
indigo.actionGroup.execute(165084610) # "Audio_SaveAudioState"
indigo.variable.updateValue(1817154897, value=str("Daniel Message: Motion near Basement Door!"))
indigo.actionGroup.execute(1183881012) # "TextBrianLore"
SpeakMessage = "Well, Beam me up Scotty! Its good to see you old LAD! Glad you could pop-inn, we may be enjoying a nice Fire, but , We'll be right down!"
SpeakMessageGarage = "Someone is down near the garage."
def KitchenOnlyspeakers():
airfoilPlugin.executeAction("connectToSpeaker",props={'speaker':"com.rogueamoeba.group.EE8788B6A5AB46D3B0A46B74895D064A"}) #KitchenOnly
airfoilPlugin.executeAction("setVolume", props={'volume':"40", 'speakerIds':["3C15C2EF2E0F"]}) # testing
airfoilPlugin.executeAction("changeAudioSource", props={'sourceType':"application", 'appSource':'com.apple.speech.speechsynthesisd'}) #Speaks Audio
def MuteAll():
airfoilPlugin.executeAction("setVolume", props={'volume':"0", 'speakerIds': ["741BB2D2612E","28CFE97EA754","20C9D098FA04","28CFE980B651","3C0754600711","3C15C2EF2E0F"]})
def DayTimeSpeakers():
airfoilPlugin.executeAction("connectToSpeaker",props={'speaker':"com.rogueamoeba.group.796E96D7229F4750B60A35C3F86BBE4B"})
airfoilPlugin.executeAction("setVolume", props={'volume':"50", 'speakerIds': ["741BB2D2612E","28CFE97EA754","20C9D098FA04","28CFE980B651","3C0754600711","3C15C2EF2E0F"]})
airfoilPlugin.executeAction("changeAudioSource", props={'sourceType':"application", 'appSource':'com.apple.speech.speechsynthesisd'}) #Speaks Audio
MuteAll()
# Its too early , speaks early Message only in Kitchen
if myVar.value == "false" and indigo.variables[1335916415].value == "false" and timestamp < TimetooEarly : # not goodnight and Dark out
#indigo.server.speak("Not Goodnight, and not daytime, but it is before 21 oclock")
KitchenOnlyspeakers()
time.sleep(3)
indigo.server.speak(SpeakMessageGarage) # Speaks the desired message
indigo.server.speak("I have turned on some lights for your convenience!")
indigo.device.turnOn("Backyard Lower Table Lamps")
indigo.device.turnOff("Backyard Lower Table Lamps", delay=600)
#indigo.server.speak("Lux level Night")
time.sleep (16)
indigo.actionGroup.execute(1142413630) # "Audio_RestoreAudioState"
# Speaks Message on Daytime speakers
if myVar.value == "false" and indigo.variables[1335916415].value == "true" : # Not goodnight and daylight
indigo.actionGroup.execute(368503121)#Toggles Speaker Mute
DayTimeSpeakers()
#indigo.server.speak("Not Goodnight, and daytime")
time.sleep (3)
indigo.actionGroup.execute(368503121)#Toggles Speaker Mute
indigo.server.speak(SpeakMessage) # Speaks the desired message
#indigo.server.speak("Lux level Day")
time.sleep (16)
indigo.actionGroup.execute(1142413630) # "Audio_RestoreAudioState"
# Speaks URGENT MESSAGE @ Night
if myVar.value == "true" :
indigo.actionGroup.execute(881497783) # "ag_Urgent Message”
# Need to account for arriving home late at night, and for dog Motion
indigo.server.speak("Hello There! We were not expecting Cabanna Visitors. Proceed to the front door and ring the door bell.")
indigo.server.speak("I have turned on some lights for your convenience, also , so I can take good photos of you for the authorities")
indigo.actionGroup.execute(513003517) # "Backyard On"
indigo.device.turnOff("Backyard Lower Table Lamps", delay=600)
# Its too late, play only in kitchen
if myVar.value == "false" and indigo.variables[1335916415].value == "false" and timestamp > KitchenOnly : # plays in kitchen only after 8 PM
indigo.device.turnOn("Backyard Lower Table Lamps")
KitchenOnlyspeakers()
#indigo.server.speak("Not Goodnight, and not daytime, and it is after 20 oclock")
time.sleep (3)
indigo.server.speak(SpeakMessageGarage) # Speaks the desired message
indigo.server.speak("I have turned on some lights for your visitors convenience!")
indigo.device.turnOff("Backyard Lower Table Lamps", delay=600)
time.sleep (17)
indigo.actionGroup.execute(1142413630) # "Audio_RestoreAudioState"