Running a shell script under python 2.7

Posted on
Wed Nov 04, 2015 9:37 am
DaveL17 offline
User avatar
Posts: 6759
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Running a shell script under python 2.7

Hi Håvard - No worries! You're not being unclear. I think you're just making it harder on yourself than it needs to be! :D

Try this line:
Code: Select all
textToSpeak = u"The weather is currently %s and the temperature is %s degrees." % (indigo.devices[DEV_ID].states["currentWeather"], indigo.devices[DEV_ID].states["temp"])

You're using WUnderground for the data, yes? This line links the string to speak directly to the WUnderground device states. No need to use a variable at all. Be sure to replace DEV_ID (both of them) with the ID number of your WUnderground Weather device. You might also have a look at the WUnderground How To on speaking the weather: http://forums.indigodomo.com/viewtopic.php?f=149&t=12818

I don't think you need to use the %%v:########%% substitution method here.
Dave

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

[My Plugins] - [My Forums]

Posted on
Wed Nov 04, 2015 9:58 am
haavarda offline
User avatar
Posts: 702
Joined: Aug 18, 2012
Location: Norway

Re: Running a shell script under python 2.7

Yes. That can work for WU. But my idea was that speaking variables was a robust way to speak dynamic messages. I have for instance a variable named time of day or where last motion was detected etc. So the idea was that I from any trigger could just have an action that sets the desired text with necessary variable references and a second later speak with sonos... But I have no idea if it is possible

Håvard

Posted on
Wed Nov 04, 2015 10:09 am
DaveL17 offline
User avatar
Posts: 6759
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Running a shell script under python 2.7

Certainly possible! Using the line I proposed above, changed for variable values:

Code: Select all
    textToSpeak = u"The text to speak is %s" % (indigo.variables[VAR_ID].value)


Then the value of the variable you want spoken should only contain the actual text to be spoken (as Karl mentioned above, all variable values are strings--even numbers.)
Dave

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

[My Plugins] - [My Forums]

Posted on
Thu Nov 05, 2015 3:21 am
haavarda offline
User avatar
Posts: 702
Joined: Aug 18, 2012
Location: Norway

Re: Running a shell script under python 2.7

Thank you Dave.
After a bit of thinking, and getting rid of the idea that I have to store what is to be spoken in a variable. I found out that I can definitely do this as you proposed. I also expanded your example yesterday, and that worked perfect.

I knew how I wanted it to be, but had no idea how to do it, so a big thanks to Karl, Dave and Jay for your help.

My tts solution now has a set of pre defined mp3s that will always work (undependent of the online service). Like: The garage has been left open for 20 minutes, etc. And I can generate mp3s online with dynamic messages like weather forecast, news headlines etc.

I will update with my working solution on the link below when I have it all up and running.
http://forums.indigodomo.com/viewtopic.php?f=107&t=14932&p=104717#p104717

Håvard

Posted on
Thu Nov 05, 2015 4:38 am
DaveL17 offline
User avatar
Posts: 6759
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Running a shell script under python 2.7

That's great news Håvard. Glad that you were able to make it work! I also think that it's a smart approach to have canned "pre-recorded" messages that will play regardless of Ivona status. You might consider a pre-recorded message to play when the Ivona service is unavailable (that you would play in place of your dynamic messages.)

Code: Select all
try:
    textToSpeak = u"The text to speak is %s" % (indigo.variables[VAR_ID].value)
except:
    textToSpeak = u"I'm terribly sorry, but I'm unable to contact the Ivona service at this time."

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 23 guests