[SOLVED]iTunes Pause and Speak script

Posted on
Fri Dec 26, 2014 6:32 pm
achterberg offline
Posts: 93
Joined: Feb 22, 2005
Location: Texas

[SOLVED]iTunes Pause and Speak script

I have a trigger action that updates variables at a device state change (on a temperature change), one of them named alertDesc. The script below should check the value of alertDesc and if "None" (currently hard-coded into the variable) abort the script. The idea being that if it gets populated with real data, the script should run, and the alertDesc variable is updated with "None" to prevent execution every time the trigger is fired. But it runs at every trigger action. It is being called as an external python script, to prevent the embedded timeout issue, at the end of the trigger action populating the variables. Is there a better way of doing this?

Code: Select all
itunesId = "com.perceptiveautomation.indigoplugin.itunes"
itunesPlugin = indigo.server.getPlugin(itunesId)
if itunesPlugin.isEnabled():
    alertDesc = indigo.variables[8234576]
    if alertDesc.value == "None":
         return
    else:
         spokenString = "Alert %s  Expires %s." % (alertDesc.value, alertExpire.value)
         itunesPlugin.executeAction("pauseAndSay", deviceId=88947230, props={'message':spokenString})

indigo.variable.updateValue(alertDesc, "None")
alertDesc.refreshFromServer()

Posted on
Sat Dec 27, 2014 9:28 am
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: iTunes Pause and Speak script

I'm not sure what is going wrong. Try putting some debug logging into the script, such as:

indigo.log("alertDesc.value is %s" % alertDesc.value)

to see if you can deduce exactly what is occurring.

Image

Posted on
Sat Dec 27, 2014 8:53 pm
jay (support) offline
Site Admin
User avatar
Posts: 18185
Joined: Mar 19, 2008
Location: Austin, Texas

Re: iTunes Pause and Speak script

Are you sure you're inserting the word "None" rather than just setting it to the empty string?

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Dec 27, 2014 10:24 pm
achterberg offline
Posts: 93
Joined: Feb 22, 2005
Location: Texas

Re: iTunes Pause and Speak script

Yes, the word "None", I know it's confusing; I used other terms thinking almost the same thing. The only way this works (so far), is to check the value of alertDesc (in an embedded python script that is tacked on to the end of a trigger action) against the variable value. That script calls an action group that calls an external .py script which does the speaking part if the check fails. I will probably end up deleting the action group call if this continues to work.

Running the entire script as an external .py script fails. It doesn't even find the alertDesc.value part in the logging test suggested by Matt. (I think he also meant indigo.server.log in his message).

I'm posting another question in the wunderground plugin forum later with another idea.

Posted on
Sun Dec 28, 2014 11:38 am
achterberg offline
Posts: 93
Joined: Feb 22, 2005
Location: Texas

Re: iTunes Pause and Speak script

I have abandoned the variable route and am keying off of values in the plugin, thanks to assistance from another post.

This compiles but doesn't return:
Code: Select all
pluginId = "com.fogbert.indigoplugin.wunderground"
plugin = indigo.server.getPlugin(pluginId)
if plugin.isEnabled():
   dev = indigo.devices[540318992]
   idS = dev.states["alertStatus"]
   if idS == 'false': # or "false", 'False', "False"
        return
   # if dev.states["alertStatus"] == 'false':    # obviously, this doesn't work either
      # return
   else:
      execfile('/Library/Python/2.5/site-packages/Alert1.py')


This return works:
Code: Select all
pluginId = "com.fogbert.indigoplugin.wunderground"
plugin = indigo.server.getPlugin(pluginId)
if plugin.isEnabled():
    dev = indigo.devices[540318992]
    idS = str(int(dev.states["alertStatus"]))
    if idS == "0":    # executes file Alert1.py if hardcoded as 1
        return
    else:
        execfile('/Library/Python/2.5/site-packages/Alert1.py')
[/code]

Posted on
Sun Dec 28, 2014 5:02 pm
achterberg offline
Posts: 93
Joined: Feb 22, 2005
Location: Texas

Re: iTunes Pause and Speak script

Received a freeze alert and the script seems to work with a real world "true". I'm still not sure why it didn't (doesn't) return with "false". For the Error "speak string too long" is that an Indigo limitation; if so, for reference, what is the limit? I deleted the speak message substitution, not important for this exercise anyway.

Posted on
Mon Dec 29, 2014 12:33 pm
jay (support) offline
Site Admin
User avatar
Posts: 18185
Joined: Mar 19, 2008
Location: Austin, Texas

Re: iTunes Pause and Speak script

achterberg wrote:
Received a freeze alert and the script seems to work with a real world "true". I'm still not sure why it didn't (doesn't) return with "false". For the Error "speak string too long" is that an Indigo limitation; if so, for reference, what is the limit? I deleted the speak message substitution, not important for this exercise anyway.


Sorry, not following you at all on this one. Can you clarify what you're seeing and what's not working (it doesn't seem to relate to your earlier post)?

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Dec 29, 2014 1:50 pm
achterberg offline
Posts: 93
Joined: Feb 22, 2005
Location: Texas

Re: iTunes Pause and Speak script

Sorry, it does kind of ramble doesn't it, it made sense to me when I sent it. I'll do a list:
1. Received a freeze alert and the script seems to work with a real world "true". (this is good!)
2. I'm still not sure why it didn't (doesn't) return with "false". (I'm waiting until the alerts expire and the plugin returns "false" to check this again)
3. In the Alert1.py file that is called by the trigger (code in previous message), I was keying to the alertMessage1 value in the plugin that sets a variable for pauseandsay to speak. Doing this creates an error "speak string too long" in the log file, because the value of alertMessage1 is too long. Deleted the message variable because it wasn't necessary anyway and the script works fine (no error). It is not a matter of it not working; it seems to be doing what it should. I was just curious, for reference, what the limitation is in Indigo (or whatever is causing the error message) to cause/not cause an error of "speak string too long"?
I'll add 4. This is a proof of concept and a learning python exercise (trying to convert all applescripts to python to the extent possible); this will probably be modified for other things besides getting the weather alerts every time the temperature changes. So #2 above is a mystery (probably some coding error on my part), #3 is a curious question, and other than an erroneous date (which is not the plugin or Indigo, just bad data apparently), all is good.

Posted on
Mon Dec 29, 2014 4:11 pm
jay (support) offline
Site Admin
User avatar
Posts: 18185
Joined: Mar 19, 2008
Location: Austin, Texas

Re: iTunes Pause and Speak script

Can't answer #2 - that's dependent on what the plugin inserts for the state value.

I don't recall off the top of my head what the text limit is on spoken text. Can you copy/paste the exact line from the event log? I don't recall anyone hitting the limit before... ;)

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Dec 29, 2014 4:52 pm
achterberg offline
Posts: 93
Joined: Feb 22, 2005
Location: Texas

Re: iTunes Pause and Speak script

The original one is long gone in another log file so I made a fresh one for you:

Code: Select all
  Error                           speak string too long


text is red, of course.

Posted on
Mon Dec 29, 2014 7:41 pm
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: iTunes Pause and Speak script

The limitation on the number of letters that can be spoken (which was 512) has been removed. That change will be in Indigo 6.0.19.

Image

Posted on
Mon Dec 29, 2014 8:09 pm
achterberg offline
Posts: 93
Joined: Feb 22, 2005
Location: Texas

Re: iTunes Pause and Speak script

Great, thanks.


Sent using Tapatalk

Posted on
Wed Dec 31, 2014 5:15 pm
achterberg offline
Posts: 93
Joined: Feb 22, 2005
Location: Texas

Re: iTunes Pause and Speak script

Just for anyone's future reference:
Code: Select all
pluginId = "com.fogbert.indigoplugin.wunderground"
plugin = indigo.server.getPlugin(pluginId)
if plugin.isEnabled():
   dev = indigo.devices[540123992]
   # if dev.states["alertStatus"] == 'false':    # python can't compare different types, in this case a boolean and string
    if not dev.states["alertStatus"]:    # this works
        return
   else:
      execfile('/Library/Python/2.5/site-packages/Alert1.py')

Posted on
Wed Dec 31, 2014 6:28 pm
jay (support) offline
Site Admin
User avatar
Posts: 18185
Joined: Mar 19, 2008
Location: Austin, Texas

Re: iTunes Pause and Speak script

In Python, you use the word False to represent the boolean (no quotes) - so this would work as well:

Code: Select all
if dev.states["alertStatus"] == False:

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Dec 31, 2014 6:44 pm
DaveL17 offline
User avatar
Posts: 6739
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: iTunes Pause and Speak script

jay (support) wrote:
In Python, you use the word False to represent the boolean (no quotes) - so this would work as well:

Code: Select all
if dev.states["alertStatus"] == False:
Thanks Jay.

Right now, the state ['alertStatus'] is value type string. This is something that I plan to address before taking the plugin out of beta status.

Dave

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Who is online

Users browsing this forum: No registered users and 0 guests