The Vera Community forums have moved!

Advanced => Plugins & Plugin Development => Programming => Sonos Plugin => Topic started by: parkerc on November 05, 2012, 04:42:06 pm

Title: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on November 05, 2012, 04:42:06 pm
Hi,

As i was keen to give me Veralite the image of some verbal intelligence @Guessed helped me with an earlier version of the Sonos Plugin to create some dynamic speech (See here http://forum.micasaverde.com/index.php/topic,11269.0.html)

I'm going to update this first section with any new dynamic 'say' commands i've pulled together.

The Talking Sonos Clock
http://forum.micasaverde.com/index.php/topic,12408.msg90986.html#msg90986

Period Of The Day Welcome
http://forum.micasaverde.com/index.php/topic,12408.msg92210.html#msg92210

Check The Status Of The Lights
http://forum.micasaverde.com/index.php/topic,12408.msg92209.html#msg92209

Random Words
http://forum.micasaverde.com/index.php/topic,12408.msg159478.html#msg159478

Simon Says Game
http://forum.micasaverde.com/index.php/topic,12408.msg161152.html#msg161152

All Zones Message
http://forum.micasaverde.com/index.php/topic,12408.msg159525.html#msg159525

---ooo000ooo---

What's The Temperature ?

This was my first one and testing it again, it still works, and it's great how Google & Sonos can tell me the temperatures of my kids rooms now..

Code: [Select]
url = require("socket.url")

local AV_DEV = 5
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local MN_SID = "urn:micasaverde-com:serviceId:MediaNavigation1"

local TEMP_SID = "urn:upnp-org:serviceId:TemperatureSensor1"
local benTemp = luup.variable_get(TEMP_SID,"CurrentTemperature", 42)
local emmaTemp = luup.variable_get(TEMP_SID,"CurrentTemperature", 48)
local lang = "en"
local speak = url.escape(string.format("Ben's Room is currently at %s degrees, and emmers is at %s ", benTemp, emmaTemp))

luup.call_action(LS_SID, "SetURIToPlay", {URIToPlay = string.format("x-rincon-mp3radio://translate.google.com/translate_tts?tl=%s&q=%s", lang, speak)},AV_DEV)
luup.call_action(MN_SID, "Play", {},AV_DEV)

Feel free to evolve this script and share any examples you might create here for others to use.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: guessed on November 05, 2012, 05:57:14 pm
You might want to try the "Say" action, of the Sonos1 SID, directly.  It'll handle building the URL, the appropriate URL value encoding, and the "Play" action all internally.  You'll just need to tell it to stop, since it will play in a loop...

The last 3 lines will be replaced with something akin to:

Code: [Select]
luup.call_action(LS_SID, "Say",
                 {Text = string.format("Ben's Room is currently at %s degrees, and emmers is at %s ", benTemp, emmaTemp)},
                 AV_DEV)
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on November 06, 2012, 03:25:26 am
Thanks @Guessed

Very Nice ! (And much less cluttered now..)

Code: [Select]
url = require("socket.url")

local AV_DEV = 5
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"

local TEMP_SID = "urn:upnp-org:serviceId:TemperatureSensor1"
local benTemp = luup.variable_get(TEMP_SID,"CurrentTemperature", 42)
local emmaTemp = luup.variable_get(TEMP_SID,"CurrentTemperature", 48)

luup.call_action(LS_SID, "Say", {Text = string.format("Ben's Room is currently at %s degrees, and Emmers is at %s ", benTemp, emmaTemp)}, AV_DEV)

@Guessed I've had a quick go at getting dates, but I only can get the unix ones. To help build dynamic message, shoul someone want their Songle* to "say" that a particular device was "last updated on 6th of November", are you aware of anything that could convert the unix clock to words and not numerical values that could then be spoken?

A search gave me this, but it's not something I can work out. http://forum.micasaverde.com/index.php/topic,5381.msg30660.html#msg30660

Also to do this I assume I would need to create some kind of conversion table etc. e.g 4 = April?

* = I'm testing out names for the Sonos/Google TTS set up  ;)

UPDATE

I found this online - which seems interesting - http://lua-users.org/wiki/DateFormattingFunctions
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: guessed on November 06, 2012, 08:32:05 am
For the first one, Lua's os.date accepts a string based format "pattern" that is used to convert the number into something of your choice.

A more complete list of the format elements can be found in pages like:
    http://linux.about.com/od/commands/l/blcmdl1_date.htm

You'd have to test to see which ones are really available.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on November 06, 2012, 06:13:01 pm
Thanks to Guessed for the os.date link, and now here's another TTS to share. This one is called..

'The Talking Sonos Clock' ;)

Code: [Select]
url = require("socket.url")

local AV_DEV = 5
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"

local TEMP_SID = "urn:upnp-org:serviceId:TemperatureSensor1"
local time = os.date('%M minutes past %I:')

luup.call_action(LS_SID, "Say", {Text = string.format("The time is currently %s", time)}, AV_DEV)

More to follow.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: guessed on November 06, 2012, 06:34:37 pm
Now that you're using the built-in Say action, you can strip out the need for the "require" call at the top (it's effectively inside the Sonos implementation)

For the use-case of the talking clock, you can also strip out the temperature declarations, so it'll get even smaller.

All in all, it gets to be fairly small:

Code: [Select]
local AV_DEV = 5
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local time = os.date('%M minutes past %I:')

luup.call_action(LS_SID, "Say", {Text = string.format("The time is currently %s", time)}, AV_DEV)
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on November 07, 2012, 02:45:39 pm
Thanks @guessed, that's what happens when you do things late at night, I missed the obvious ;)

My next challenge is to try and create a script that will carry out a series of checks on something, and then report back on it's findings. This way the resulting TTS could potentially be a different message depending on the results.

Sonos Status Reporting

For example

i)  Check all temperature sensors are over 20c

If they are then say "all sensors are reporting 20c or above" but if they're not, then say "not all sensors are reporting 20c or above". - it might even be possible for me to get it to say which one is not so it's more helpful and say "John's Bedroom is reporting 18.5c"

Others could be to

ii) Check all security devices are armed etc ..
iii) Check all lights are off etc..

To save the number of Google TTS requests needed, it might be better to just play an MP3 or WAV file from a NAS when everything is fine and just use the TTS for information/error verbal messages.

As always, all thoughts/ideas/input welcome..
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on November 09, 2012, 05:59:54 pm
Hi

It seems my new found coding skills have come up against a brick wall - I'm trying to check the status of 3 lights and depending on the results it should play a particular message. The logs seem to point to the very first line, I'm sure it's obvious but I just can't see it. :(

Code: [Select]
local LIGHT_ID1= 22
local LIGHT_ID2= 82
local LIGHT_ID3= 44
local AV_DEV = 5
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local SEC_SERV = "urn:upnp-org:serviceId:SwitchPower1"

local v = local function checkLightsOnOff()

local bedroomlight = luup.variable_get(SEC_SERV, "Status",LIGHT_ID1)
local halllight = luup.variable_get(SEC_SERV, "Status",LIGHT_ID2)
local loungelight = luup.variable_get(SEC_SERV, "Status",LIGHT_ID3)

if(bedroomlight == "0")then
if(halllight == "0")then
if(loungelight == "0")then

luup.log("v is " .. v) 
luup.call_action(LS_SID, "Say", {Text = string.format("All Lights Are Off")}, AV_DEV)

return true

else

luup.call_action(LS_SID, "Say", {Text = string.format("One Or More Lights Are On")}, AV_DEV)

return false

    end
end
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: oTi@ on November 10, 2012, 09:14:17 am
For one, there's more if's than end's.

Did you try it for a single light first (i.e. start with fewer code lines), then expand from there?
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on November 10, 2012, 10:11:05 am
Hi OTi

Thanks for responding.

Yes I tried it with just the one light and it still failed at the same place , the first line.
I pasted everything in just so people could see the whole thing that I'm trying to do and point out anything else that might be wrong ..

Log shows..

01   11/10/12 15:06:29.897   LuaInterface::LoadCode: [string "local LIGHT_ID1= 22..."]:6: unexpected symbol near 'local' <0x2fadc680>
01   11/10/12 15:06:29.899   JobHandler_LuaUPnP::RunLua failed: local LIGHT_ID1= 22
Title: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: teonebello on November 10, 2012, 10:58:45 am
If you have two voice command, how can we separate? Luup.sleep?

Any example to avoid long waiting to confirm the execution of a scene?

Thank you
Matteo
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on November 10, 2012, 02:51:35 pm
Hi Matteo

My goal was to have Vera check 3 lights in the house, if one or more was on it would 'say' one type of message, but if no lights were on then it should say a different type of message.

I was just looking for it to just run the once, but I guess it could have luup.sleep added so it repeats the check every xxxx seconds?

I'm just not sure what I have done wrong that it seems to fail on the first line, no matter which local value I choose to put there.

If I try a piece of code that I know works, it seems to go through ok..
Which makes this even more strange??
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: santoal on November 15, 2012, 12:37:47 am
Hi

If music or radio is already playing and I invoke a "say" command, is there a way or resuming whatever was playing?
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: guessed on November 15, 2012, 01:01:03 am
Its not built in at this time, but its possible to do it if you read back through the main post.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on November 17, 2012, 05:56:56 pm
Here you go, finally! Thanks for all the help from the Scene Scripting forum on getting this one to work in the end.

Check The Status Of The Lights

This one will check and tell you if all the lights are off or if one or more are still on.

Code: [Select]
local LI_DEV1 = 82
local LI_DEV2 = 22
local LI_DEV3 = 53
local AV_DEV = 5
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local SEC_SERV = "urn:upnp-org:serviceId:SwitchPower1"

local livingroomlight = luup.variable_get(SEC_SERV, "Status",LI_DEV2)
local bedroomlight = luup.variable_get(SEC_SERV, "Status",LI_DEV1)
local halllight = luup.variable_get(SEC_SERV, "Status",LI_DEV3)

if ((livingroomlight == "0") and (bedroomlight == "0") and (halllight == "0")) then
luup.log("All light are off")
luup.call_action(LS_SID, "Say", {Text = string.format("All lights are off ")}, AV_DEV)
else
luup.log("One or more lights is on")
luup.call_action(LS_SID, "Say", {Text = string.format("One or more lights are on ")}, AV_DEV)
end
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on November 17, 2012, 05:59:22 pm
Another new one for anyone who is interested..

Sonos Period Of The Day Greetings

This one will check the time of day and then great you with either Good Morning, Good Afternoon or Good Evening

Code: [Select]
url = require("socket.url")
local t = os.date('*t')

local AV_DEV = 5
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local current_second = t.hour * 3600 + t.min * 60 -- number of sec since midnight
local morning = 0 * 3600 +  0 * 60             -- 00:00
local afternoon = 12 * 3600 +  0 * 60       -- 12:00
local evening = 18 * 3600 +  0 * 60             -- 18:00
local name = "Chris"

   if (current_second > morning) and (current_second < afternoon) then
        luup.call_action(LS_SID, "Say", {Text = string.format("Good Morning %s ", name)}, AV_DEV)
   else
     
        if (current_second > afternoon) and (current_second < evening) then
             luup.call_action(LS_SID, "Say", {Text = string.format("Good Afternoon %s ", name)}, AV_DEV)
        else

             luup.call_action(LS_SID, "Say", {Text = string.format("Good Evening %s ", name)}, AV_DEV)
        end
   end
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: allmoney.ws on December 08, 2012, 07:18:31 pm
Can it speak in Russian?
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on December 09, 2012, 03:03:59 am
This suggests it does, http://googletranslate.blogspot.co.uk/2010/05/giving-voice-to-more-languages-on.html) - so have a go with the Sonos Plugin and try changing the language values in the 'say' command
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: guessed on December 09, 2012, 11:25:42 am
If I give it this string:
    Я хотел бы немного водки

It makes the attached TTS version of it.  I have no idea if this is the correct translation, but the original english string, prior to auto-translation, was:
   I would like some vodka

(rename attachment from Say.jpg to Say.mp3 to play it)
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: lolodomo on December 09, 2012, 01:57:01 pm
 ;D for the example.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: hek on December 11, 2012, 03:51:32 pm
My little snippet used when someone calls us... Feel free to modify for your needs...
This code works in Sweden.. but there is probably similar services in other countries that can be used for looking up phonenumbers.


Code: [Select]
--
-- Uses the swedish number-to-name service 188100.se to lookup who is calling (using Fritz!Box integration)
-- and announce it in your sonos speaker system
--
-- You need to install xpath.lua (found here: http://code.mios.com/trac/mios_genericutils/browser)
-- under /usr/lib/lua/ of your vera unit
--
-- Update the following parameters below:
--   apiKey118100 - Your personal api key requested here: http://utveckling.118100.se/node/10
--   AV_DEV - sonos device id
--   FB_DEV - Fritz!Box device id
--   sayText - Text you want the sonos to say (%s = name of caller)
--   sayLang - Laguage (sv = swedish, en=english, ...)
--   sayVolume - Volume of the announcement
--

local url = require("socket.url")
local xp = require ("xpath")
local lom = require ("lxp.lom")
local http = require('socket.http')

local AV_DEV = 115
local FB_DEV = 122
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local FB_SID = "urn:hek:serviceId:FritzBox1"
local apiKey118100 = "XXXXXXXXXXXXXX.XXXXXXXX"
local serviceUrl = "http://developer.118100.se:8080/openapi-1.1/appetizing?query=%s&key=%s"
local sayTextPrivate = "%s %s is calling"
local sayTextCompany = "The company %s is calling"
local sayLang = "sv"
local sayVolume = 30
local number = luup.variable_get( FB_SID, "Number", FB_DEV)

http.TIMEOUT = 5
luup.log("Incoming number: " .. number)
local result = http.request(string.format(serviceUrl, number, apiKey118100))

local lomobj = lom.parse(result)
local firstName = xpath.selectNodes(lomobj,"//individual/name[@type='first']/text()")[1]
local lastName = xpath.selectNodes(lomobj,"//individual/name[@type='last']/text()")[1]
local company = xpath.selectNodes(lomobj,"//company/name[@type='legal']/text()")[1]
local sayText = ""
if company then
    sayText = string.format(sayTextCompany, company)
else
    sayText = string.format(sayTextPrivate, firstName, lastName)
end


luup.log("Saying: " .. sayText)
luup.call_action(LS_SID, "Say", {Text = sayText, Language=sayLang, Volume=sayVolume}, AV_DEV)
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: turnerg100 on January 12, 2013, 11:28:11 pm
I cannot get the Say function in the device interface to work, though the device works fine with Sonos radio channels and other files. When I enter say "welcome home" and run it, an MP3 is called but no no sound plays, as if the MP3 is a blank recording.

Any ideas? Thank you!
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: hek on January 13, 2013, 05:02:28 am
Does your Vera have internet accces?
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: turnerg100 on January 13, 2013, 09:47:58 am
It does. I can stream pandora through sonos and write you now... etc. Using vera 3 as my wireless router.

Any ideas? Thank you!
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: hek on January 13, 2013, 12:47:10 pm
Weird.. And your Sonos speakers is also plugged into Vera?

I've got a Vera Light so there is another network topology.. The Say command uses some "magic" to get the Vera ipnumber which is needed to let your sonos speakers find the generated mp3.
I hope this magic works for Vera 3 aswell.... @guessed... you also run Vera3 right?
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: guessed on January 13, 2013, 03:39:20 pm
See the other thread, since it looks like a similar issue:
    http://forum.micasaverde.com/index.php/topic,13232.0.html
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: allmoney.ws on January 30, 2013, 06:11:38 pm
Any way to say temperature from weather.com, google search results or other services?
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Brientim on January 31, 2013, 12:37:15 am
As the work is already done with the Weather plugin you could install that and then use something similar to this *(which has maintained the conventions of the previous Say Temp).

Code: [Select]
url = require("socket.url")

local AV_DEV = Sonos DeviceID
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"

local TEMP_SID = "urn:upnp-org:serviceId:TemperatureSensor1"
local WUGTemp1 = luup.variable_get(TEMP_SID, "CurrentTemperature", Weather Underground Temperature DeviceId)

luup.call_action(LS_SID, "Say", {Text = string.format("The current temperature outside is %s degrees", WUGTemp1 )}, AV_DEV)


Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: allmoney.ws on January 31, 2013, 02:55:17 am
As the work is already done with the Weather plugin you could install that and then use something similar to this *(which has maintained the conventions of the previous Say Temp).

Code: [Select]
url = require("socket.url")

local AV_DEV = Sonos DeviceID
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"

local TEMP_SID = "urn:upnp-org:serviceId:TemperatureSensor1"
local WUGTemp1 = luup.variable_get(TEMP_SID, "CurrentTemperature", Weather Underground Temperature DeviceId)

luup.call_action(LS_SID, "Say", {Text = string.format("The current temperature outside is %s degrees", WUGTemp1 )}, AV_DEV)

Thanks a lot!
But why it say only 1st string, if I insert 2 lines, for example:

luup.call_action(LS_SID, "Say", {Text = string.format("The current temperature outside is %s degrees", WUGTemp1 )}, AV_DEV)
luup.call_action(LS_SID, "Say", {Text = string.format("Tomorrow will be %s degrees", WUGTemp1 )}, AV_DEV)

?
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Brientim on January 31, 2013, 03:46:34 am
You can have it get, return and say multiple variable as long as they are available.
You just need to declare where there are coming from... Once again, I will say with the precedence that has been displayed in previous posts.

E.g.
local WUGTempCurrent = luup.variable_get(TEMP_SID, "CurrentTemperature", 288)
local WUGTempHigh= luup.variable_get(TEMP_SID, "CurrentTemperature", 289)

So, in the example below
377 is the Sonos and the remaining are other devices that have a Variable called CurrentTemperature



Code: [Select]
url = require("socket.url")

local AV_DEV = 377
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"

local TEMP_SID = "urn:upnp-org:serviceId:TemperatureSensor1"
local RoomTemp1 = luup.variable_get(TEMP_SID,"CurrentTemperature", 389)
local RoomTemp2 = luup.variable_get(TEMP_SID,"CurrentTemperature", 36)
local RoomTemp3 = luup.variable_get(TEMP_SID,"CurrentTemperature", 381)
local WUGTempCurrent = luup.variable_get(TEMP_SID, "CurrentTemperature", 288)
local WUGTempHigh= luup.variable_get(TEMP_SID, "CurrentTemperature", 289)

luup.call_action(LS_SID, "Say", {Text = string.format("Bedroom1 is currently %s degrees  Room2 is currently at %s degrees, Room3 is currently %s degrees the outside is currently %s degrees" and the maximum excepted today is %s degrees, RoomTemp1,RoomTemp2,RoomTemp3,WUGTempCurrent,WUGTempHigh )}, AV_DEV)
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: allmoney.ws on January 31, 2013, 08:04:10 am
You can have it get, return and say multiple variable as long as they are available.
You just need to declare where there are coming from... Once again, I will say with the precedence that has been displayed in previous posts.

E.g.
local WUGTempCurrent = luup.variable_get(TEMP_SID, "CurrentTemperature", 288)
local WUGTempHigh= luup.variable_get(TEMP_SID, "CurrentTemperature", 289)

So, in the example below
377 is the Sonos and the remaining are other devices that have a Variable called CurrentTemperature



Code: [Select]
url = require("socket.url")

local AV_DEV = 377
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"

local TEMP_SID = "urn:upnp-org:serviceId:TemperatureSensor1"
local RoomTemp1 = luup.variable_get(TEMP_SID,"CurrentTemperature", 389)
local RoomTemp2 = luup.variable_get(TEMP_SID,"CurrentTemperature", 36)
local RoomTemp3 = luup.variable_get(TEMP_SID,"CurrentTemperature", 381)
local WUGTempCurrent = luup.variable_get(TEMP_SID, "CurrentTemperature", 288)
local WUGTempHigh= luup.variable_get(TEMP_SID, "CurrentTemperature", 289)

luup.call_action(LS_SID, "Say", {Text = string.format("Bedroom1 is currently %s degrees  Room2 is currently at %s degrees, Room3 is currently %s degrees the outside is currently %s degrees" and the maximum excepted today is %s degrees, RoomTemp1,RoomTemp2,RoomTemp3,WUGTempCurrent,WUGTempHigh )}, AV_DEV)

Question was about other thing :)
Why TTS not read 2nd line luup.call_action, without variables too. One more example:

luup.call_action(LS_SID, "Say", {Text = string.format("The current temperature outside is %s degrees", WUGTemp1 )}, AV_DEV) -- SAID
luup.call_action(LS_SID, "Say", {Text = string.format("Thanks you")}, AV_DEV) -- DIDN'T SAY
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: lolodomo on January 31, 2013, 11:39:24 am
Because the plugin is not able to say several things at the same time
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Brientim on January 31, 2013, 02:08:01 pm
Sorry, I missed answering your question. As lolodomo stated, and that is why the several things are included in the same string... In the example, there is actually four statements and uses the four variables.

So, including your two statements into the single string would appears like.
luup.call_action(LS_SID, "Say", {Text = string.format("The current temperature outside is %s degrees,        Thankyou", WUGTemp1 )}, AV_DEV)

So, if WUGTemp1 = 68 the response would be
"The current temperature outside is 68 degrees,        Thankyou"
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on February 03, 2013, 06:53:00 am
Another TTS template for people to look at and hopefully improve for me and others.

The intent here is to do a occupancy check of the house and then report back if the house is presumed to be empty of if someone is maybe still there.

Occupancy Check

Code: [Select]
local MO_DEV1 = 119
local MO_DEV2 = 124
local MO_DEV3 = 135
local SEC_SERV = "urn:micasaverde-com:serviceId:SecuritySensor11"

local AV_DEV = 5
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"


local livingroommotion = luup.variable_get(SEC_SERV, "Tripped",MO_DEV2)
local hallwaymotion = luup.variable_get(SEC_SERV, "Tripped",MO_DEV1)
local kitchenmotion = luup.variable_get(SEC_SERV, "Tripped",MO_DEV3)

if ((livingroommotion == "0") and (hallwaymotion == "0") and (kitchenmotion == "0")) then
luup.log("All motion sensor report no motion seen")
luup.call_action(LS_SID, "Say", {Text = string.format("All motion sensores report that no motion is being seen.")}, AV_DEV)
else
luup.log("One or more motion sensors have reported motion")
luup.call_action(LS_SID, "Say", {Text = string.format("One or more motion sensores have reported motion.")}, AV_DEV)
end

If anyone can work out how to extract which sensor is still reporting motion out of a list of devices, it would be a nice touch for Sonos to say e.g. "Motion Is Still Being Reported in the Living Room"
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: big517 on February 09, 2013, 05:44:57 am
I believe this is available in RTS Vera Alerts Plugin, and now you can send text directly from that Plugin to the Sonos Plugin his formatting may be better documented to create this dynamic string, and it may be very easy to push it to the sonos (or maybe not) I dont remember but it seemed to work well... I'm using THIS code to send the weather information via TTS to Vera Alerts that plays through my Sonos

Code: [Select]
local currentTemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 333)
local lowTemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 334)
local highTemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 335)
local currentCondition = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1", "Condition", 332)
local currentWind = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1", "WindCondition", 332)

local speakMessage = "{tone:1} Good Morning.  Current conditions are " .. currentCondition .. ".  The temperature is " .. currentTemp .. " degrees with a high today of " .. highTemp .. " and a low of " .. lowTemp

luup.call_action("urn:richardgreen:serviceId:VeraAlert1", "SendAlert",
                  {Message = speakMessage, Recipients = ""}, 397)


This was put together by Signal16 by the way.

So the last line there of luup.call_action would probably be where we would point the Vera Alerts plugin to deliver this message as "SAY" to the Sonos we choose.
Again, i'm not sure how to do that, but RTS would probably be able to advise fairly quickly.

Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: lolodomo on February 10, 2013, 02:58:13 am
You call the SendAlert action of the Vera Alerts plugin that will call the Say action of the Sonos plugin (forward) if the Vera Alerts is correctly setup. So it is just an indirect call to the Say action. That's mainly interesting if you want to use several kinds of notification at the same time.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: big517 on February 10, 2013, 05:38:01 am
You call the SendAlert action of the Vera Alerts plugin that will call the Say action of the Sonos plugin (forward) if the Vera Alerts is correctly setup. So it is just an indirect call to the Say action. That's mainly interesting if you want to use several kinds of notification at the same time.
Using the code I posted above, can you modify that to send to Sonos plugin?
Thank you.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: lolodomo on February 14, 2013, 01:47:34 pm
You have to setup how to forward to the Sonos plugin in a tab of the Vera Alerts device. It is explained in the wiki of Vera Alerts. The luup code you posted is, I suppose, correct.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: lolodomo on February 24, 2013, 05:13:26 am
Because the plugin is not able to say several things at the same time

Creating a queue for TTS is in my TODO list.



To come back to the subject of this topic, I would like Vera/Sonos telling me when e-mails arrive, not all time but for example when I come back to home. Any idea ?
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on February 24, 2013, 05:24:46 am
I would like Vera/Sonos telling me when e-mails arrive, not all time but for example when I come back to home. Any idea ?

To join the two - see here - as i want this too. http://forum.micasaverde.com/index.php/topic,13463.msg103821.html#msg103821
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: allmoney.ws on April 18, 2013, 11:37:04 am
PLease, help! Where is error in syntax? Can't find  :'(

Code: [Select]

local TEMP_SID = "urn:upnp-org:serviceId:TemperatureSensor1"
local WUGTemp1 = luup.variable_get(TEMP_SID, "CurrentTemperature", 27)
local WUGTempMIN = luup.variable_get(TEMP_SID, "CurrentTemperature", 28)
local WUGTempMAX = luup.variable_get(TEMP_SID, "CurrentTemperature", 29)

if (WUGTemp1 > 0) then
WUGTemp1 = "плюс " .. WUGTemp1
end
if (WUGTempMIN > 0) then
WUGTempMIN = "плюс " .. WUGTempMIN
end
if (WUGTempMAX > 0) then
WUGTempMAX = "плюс " .. WUGTempMAX
end
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: allmoney.ws on April 21, 2013, 06:18:22 am
PLease, help! Where is error in syntax? Can't find  :'(

Code: [Select]

local TEMP_SID = "urn:upnp-org:serviceId:TemperatureSensor1"
local WUGTemp1 = luup.variable_get(TEMP_SID, "CurrentTemperature", 27)
local WUGTempMIN = luup.variable_get(TEMP_SID, "CurrentTemperature", 28)
local WUGTempMAX = luup.variable_get(TEMP_SID, "CurrentTemperature", 29)

if (WUGTemp1 > 0) then
WUGTemp1 = "плюс " .. WUGTemp1
end
if (WUGTempMIN > 0) then
WUGTempMIN = "плюс " .. WUGTempMIN
end
if (WUGTempMAX > 0) then
WUGTempMAX = "плюс " .. WUGTempMAX
end

Thanks for all answers!! )) Found a solution:
tonumber(WUGTemp1) > 0
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Piwtorak on May 03, 2013, 04:41:08 pm
Hello Lolodomo  and anothers...

I would like to make my sonos speak something in portuguese, is it possible ?

luup.call_action(LS_SID, "Say", {Text = string.format("One or more motion sensores have reported motion.")}, AV_DEV)

in the line above where can be inputed the language parameter ?

I read in some place: it=italian, sw= sweden, maybe po= is equal portuguese not ?

thanks !
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Brientim on May 03, 2013, 05:10:52 pm

Hello Lolodomo  and anothers...

I would like to make my sonos speak something in portuguese, is it possible ?

luup.call_action(LS_SID, "Say", {Text = string.format("One or more motion sensores have reported motion.")}, AV_DEV)

in the line above where can be inputed the language parameter ?

I read in some place: it=italian, sw= sweden, maybe po= is equal portuguese not ?

thanks !
Try pt see


https://developers.google.com/adwords/api/docs/appendix/languagecodes
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Piwtorak on May 03, 2013, 05:47:17 pm
ok brientim ,
but in that line, where goes this parameter ?

thanks !
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Brientim on May 03, 2013, 06:05:17 pm

ok brientim ,
but in that line, where goes this parameter ?

thanks !

Refer to wiki there is an example of insert language parameters: http://code.mios.com/trac/mios_sonos-wireless-music-systems/wiki#
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Piwtorak on May 05, 2013, 10:53:27 am
Running fine the talking clock.
I would like only remove zeroes of the hours and minutes <10 , sounds no good :
Zero one hours and zero five minutes to 01:05

I would like the system talks one hour and five minutes..

I think this be in luup sintax some function to supress zero if that is at left.

In clipper we use: alltrim(str((val (hour)))
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: a-lurker on May 05, 2013, 07:16:38 pm
Use a pattern:

http://www.lua.org/pil/20.2.html
http://www.lua.org/manual/5.1/manual.html#5.4.1

Just guessing but this may work - if it doesn't read the above pages:

hour = hour:gsub("^0", "")

Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on May 12, 2013, 02:48:40 am
Hi @piwtorak

If you get it working, please post the full set of code here, I'll be interested to see how you did it.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Piwtorak on May 13, 2013, 07:20:12 am
Hello !!

I do not get working the talking hours with Zero in the front of the number when that is minor than 10...

my code now is:

local AV_DEV = 98
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local time = os.date('%I: horas e %M minutos')

luup.call_action(LS_SID, "Say", {Text = string.format("%s", time),Language="pt",Volume=60}, AV_DEV)


but I don't know where to put the gsub instruction supplied for a-lurker.
but is running fine !!!
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: a-lurker on May 18, 2013, 01:05:15 am
Try this.

Code: [Select]
local AV_DEV = 98
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"

local timeTable = os.date("*t")
local hour = tostring(timeTable.hour)
local min  = tostring(timeTable.min)

--local time = "The time is "..hour.." "..min   -- Language="en"
--local time = "L'ora "..hour.." "..min   -- Language="it"
local time = "O tempo "..hour.." "..min   -- Language="pt"

luup.call_action(LS_SID, "Say", {Text=time, Language="pt", Volume=60}, AV_DEV)

return true

Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Piwtorak on May 18, 2013, 01:01:15 pm
Thank you very much a-lurker !
My system now speaks perfectly.

I can see the difference in code, where can I find a good material to luup language ?

Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: RichardTSchaefer on May 18, 2013, 01:32:14 pm
Quote
Where can I find a good material to luup language ?

http://www.lua.org/docs.html
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: haavard on November 22, 2013, 07:54:10 am
Hello


Code: [Select]
url = require("socket.url")

local AV_DEV = 5
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local MN_SID = "urn:micasaverde-com:serviceId:MediaNavigation1"

local TEMP_SID = "urn:upnp-org:serviceId:TemperatureSensor1"
local benTemp = luup.variable_get(TEMP_SID,"CurrentTemperature", 42)
local emmaTemp = luup.variable_get(TEMP_SID,"CurrentTemperature", 48)
local lang = "en"
local speak = url.escape(string.format("Ben's Room is currently at %s degrees, and emmers is at %s ", benTemp, emmaTemp))

luup.call_action(LS_SID, "SetURIToPlay", {URIToPlay = string.format("x-rincon-mp3radio://translate.google.com/translate_tts?tl=%s&q=%s", lang, speak)},AV_DEV)
luup.call_action(MN_SID, "Play", {},AV_DEV)

Is this still the easiest way to get Vera to dynamically speak the temperature to me?
I dont know luup code, but I cant see where in code the volume of the zone is selected?
 
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Piwtorak on November 22, 2013, 08:25:25 am
Try this sintax in the line of say instruction.


luup.call_action(LS_SID, "Say", {Text=time, Language="pt", Volume=60}, AV_DEV)

Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: haavard on November 23, 2013, 05:53:29 am
So have I got this right if I want my sonos in the bedroom to tell me the temperature outside?
I dont understand how I make a reference to the required sonos player.

url = require("socket.url")

local AV_DEV = 5
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local MN_SID = "urn:micasaverde-com:serviceId:MediaNavigation1"

local TEMP_SID = "urn:upnp-org:serviceId:TemperatureSensor1"
local uteTemp = luup.variable_get(TEMP_SID,"CurrentTemperature", 232)
local lang = "en"
local speak = url.escape(string.format(?Outdoor temperature is currently at %s degrees", uteTemp))

luup.call_action(LS_SID, "Say", {Text=time, Language=?e?n, Volume=25}, AV_DEV)
luup.call_action(MN_SID, "Play", {},AV_DEV)
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Brientim on November 23, 2013, 06:04:39 am
local AV_DEV = 5
The "5 " is the device id of the Sonos. This is found in the Advanced tab of your Sonos device that you want the TTS sent too.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: haavard on November 23, 2013, 06:10:49 am
Thank you.
I did some more research and found that if I put in this code it works.
So now my sonos tells me the outdoor temperature in the morning.
How cool is that!



url = require("socket.url")

local AV_DEV = 254
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"

local TEMP_SID = "urn:upnp-org:serviceId:TemperatureSensor1"
local OutTemp = luup.variable_get(TEMP_SID,"CurrentTemperature", 232)

luup.call_action(LS_SID, "Say", {Text = string.format("The outdoor temperature is currently at %s degrees", OutTemp)}, AV_DEV)
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: haavard on November 26, 2013, 09:57:50 am
I have tried to evolve my dynamic message :)
But my lack of luup skills is killing me.

I have tried to modifie the working code that I have to include Weather underground "condition". But I get an error when I save the scene.
Can someone help me to see what is wrong with the code below?

Code: [Select]
url = require("socket.url")

local AV_DEV = 253
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"

local currentTemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 232)
local currentCondition = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1", "Condition", 115)

luup.call_action(LS_SID, "Say", {Text = string.format("The outdoor condtion is %s, and the temperature is currently at %s degrees",currentCondition, OutTemp,Volume=23)}, AV_DEV)
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: lolodomo on November 26, 2013, 11:53:18 am
You are using undefined variable OutTemp rather than currentTemp
+ parenthesis look wrong in the call_action command.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: haavard on November 27, 2013, 04:01:37 am
Thank you for looking at this :)

I had a copy fault in the currentTemp variable.
But I can not see what is wrong with the parenthesis?
I am on extremely thin ice when it comes to luup :(

 
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: haavard on November 27, 2013, 04:18:39 am
I managed to save this code.
I will see if it works when I get home.

Code: [Select]
url = require("socket.url")

local AV_DEV = 253
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"

local currentTemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 232)
local currentCondition = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1", "Condition", 115)

luup.call_action(LS_SID, "Say", {Text = string.format"The outdoor condtion is %s, and the temperature is currently at %s degrees",currentCondition, currentTemp,Volume=23}, AV_DEV)
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: lolodomo on November 29, 2013, 07:00:24 am
Code: [Select]
luup.call_action(LS_SID, "Say", {Text = string.format("The outdoor condtion is %s, and the temperature is currently at %s degrees",currentCondition, currentTemp) ,Volume=23}, AV_DEV)
Should probably be better like that ?
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: haavard on November 29, 2013, 02:50:32 pm
So I did a new try to get this to work. I am sure that it is correct to change the parenthesis. But the luup still doesn't  work.
So I tried to modify it again and I think I am closer now, but I still get an error when I try the luup. The code that I have now is as follows:

Code: [Select]
url = require("socket.url")

local AV_DEV = 253
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"

local TEMP_SID = "urn:upnp-org:serviceId:TemperatureSensor1"
local OutTemp = luup.variable_get(TEMP_SID,"CurrentTemperature", 232)
local Cond_SID = "urn:upnp-org:serviceId:Weather1"
local OutCond = luup.variable_get(Cond_SID,"Condition", 115)

luup.call_action(LS_SID, "Say", {Text = string.format("The outdoor condtion is %s, and the temperature is currently at %s degrees",OutCond, OutTemp) ,Volume=23}, AV_DEV)

The thing is that the temperature part is working. This whole project is about implementing the current condition from the weather underground app.
So I think something must be wrong with line 3 or 4. I created line 3 and 4 based on line 1 and 2, and according to similar codes found here on the forum.
Can you see something in the luup that doesn't make sense?
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: lolodomo on November 30, 2013, 05:37:49 am
Try this:
Code: [Select]
local OutCond = luup.variable_get(Cond_SID,"Condition", 115) or "bad"Then if TTS is working, it would mean that you probably don't use the right variable name or service id.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: p3tter on December 01, 2013, 06:12:18 pm
hello i had the same problem with sonos tts and the weather plugin. i could post my code, its working for me to say the condition.
Code: [Select]
local AV_DEV = 28
local MN_SID = "urn:micasaverde-com:serviceId:MediaNavigation1"
local device = 3
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local TEMP_SID = "urn:upnp-org:serviceId:TemperatureSensor1"
local WUGTemp1 = luup.variable_get(TEMP_SID, "CurrentTemperature", 21)
local time = os.date('%M minutes past %I:')
local t = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1", "ConditionGroup", 20)

luup.call_action("urn:micasaverde-com:serviceId:Sonos1", "PlayURI", {URIToPlay="Q:", Volume=20, Duration=20}, AV_DEV)



m = 60 --60 sek
luup.call_delay( 'switch_ON', m)
function switch_ON()
luup.call_action(LS_SID, "Say", {Text = string.format("Good morning. The time is currently %s. Current temperature outside is %s and the Condition outside is %s", time, WUGTemp1, t), Volume=40}, AV_DEV)
end

luup.call_delay( 'switch_off', 900) -- Call the switch off function after a delay of 2 seconds
function switch_off()
   luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue="0" },device)
   luup.call_action("urn:micasaverde-com:serviceId:Sonos1", "PlayURI", {URIToPlay="Q:", Volume=0 }, AV_DEV)
end

this play music for one minute and then it speaks the sentence: Good morning with the time, temperature and the condition outside, and then it goes back to play music for 900 sec.
hope this helps
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: haavard on December 02, 2013, 01:32:34 am
I did some tweaking on the code, and finally got it to work.
I am not 100% sure what did the trick. But the faultfinding help lolodomo got me on the right track.
The code that works for me is as follows:

Code: [Select]
url = require("socket.url")

local AV_DEV = 253
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"

local OutTemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature", 232)
local currentCondition = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1", "Condition", 115)

luup.call_action(LS_SID, "Say", {Text = string.format("The outdoor condition is %s, and the temperature is currently at %s degrees", currentCondition, OutTemp) ,Volume=23}, AV_DEV)




Thanks for your help!
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: a-lurker on December 02, 2013, 03:06:22 am
And you can remove this, as it's not referenced anywhere or needed:

Code: [Select]
url = require("socket.url")
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on December 19, 2013, 02:53:34 am
I just wanted it create a link to a really good TTS discussion that's going on elsewhere in the forum.

It's goal is to dynamical change the messages that are delivered via TTS.

http://forum.micasaverde.com/index.php/topic,13921.0.html
 
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on February 16, 2014, 05:44:00 am
Hi

Please could someone share some working code that groups a couple of Sonos zones players together so that it can Say a particular piece of text,  after which it should return to the previous state it was in (whatever that was.?)
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: lolodomo on February 16, 2014, 05:53:41 am
Hi

Please could someone share some working code that groups a couple of Sonos zones players together so that it can Say a particular piece of text,  after which it should return to the previous state it was in (whatever that was.?)

I will try to update the example in the wiki page. I just noted the corresponding paragraph as outdated in the wiki as it lacks few arguments and in particular the GroupZones argument.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on February 16, 2014, 06:15:09 am
Thanks @lolodomo -

That's where I went first to check, but like you said, it's still marked as 'outdated' - I'm looking forward to using the new group commands.

Just a thought - but is there scope to have a 'GroupSay' command created, one that does all the grouping of Zones for you, an alternative to the current singular 'Say' command ?
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: lolodomo on February 16, 2014, 06:32:54 am
Thanks @lolodomo -

That's where I went first to check, but like you said, it's still marked as 'outdated' - I'm looking forward to using the new group commands.

Just a thought - but is there scope to have a 'GroupSay' command created, one that does all the grouping of Zones for you, an alternative to the current singular 'Say' command ?

You can use "ALL" as value for the GroupZones argument.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on February 16, 2014, 11:00:25 am
Hi Lolodomo

Would you be able to give me an example of how that is used with a Say command?
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: lolodomo on February 17, 2014, 04:42:13 pm
Hi Lolodomo

Would you be able to give me an example of how that is used with a Say command?

It is now explained with several examples in the Wiki: http://code.mios.com/trac/mios_sonos-wireless-music-systems/wiki/WikiStart#MakingaSonosSaysomething
I hope I am clear in my explanations.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: jimpapa on February 20, 2014, 04:32:19 pm
I did some tweaking on the code, and finally got it to work.
I am not 100% sure what did the trick. But the faultfinding help lolodomo got me on the right track.
The code that works for me is as follows:

Code: [Select]
url = require("socket.url")

local AV_DEV = 253
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"

local OutTemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature", 232)
local currentCondition = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1", "Condition", 115)

luup.call_action(LS_SID, "Say", {Text = string.format("The outdoor condition is %s, and the temperature is currently at %s degrees", currentCondition, OutTemp) ,Volume=23}, AV_DEV)




Thanks for your help!

obsessed with the TTS

My Sonos device is 73 so I edited that.. 

Can someone point out what needs to be edited from the above working code..

My weather underground plug in is 74
But I'm doing something wrong here ..

Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on February 20, 2014, 04:43:30 pm
Hi

Just change the value next to AV_DEV to your own Sonos device number e.g.

Code: [Select]
Local AV_DEV = 73
And then add the rest of the code, updating the temperature from 232 to 74 and then the Condition device numbers from 115 to ??? (What ever it is?)
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: jimpapa on February 20, 2014, 04:48:39 pm
yes, I should have edited to say I did that:

OK GOT IT! .. items below are the variables that needed to be edited for the weather plugin and SONOS

local AV_DEV = 73
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"

local OutTemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature", 75)
local currentCondition = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1", "Condition", 74)

luup.call_action(LS_SID, "Say", {Text = string.format("The outdoor condition is %s, and the temperature is currently at %s degrees", currentCondition, OutTemp) ,Volume=23}, AV_DEV)

Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on February 20, 2014, 04:50:19 pm
Sorry I just updated my previous post, to use that piece of code you need all three of the device numbers..
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: jimpapa on February 20, 2014, 04:56:35 pm
Sorry I just updated my previous post, to use that piece of code you need all three of the device numbers..

... I must have got that telepathically!!
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on February 20, 2014, 05:14:19 pm
You got it !!
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: haavard on February 21, 2014, 03:25:48 am
Hi

Just change the value next to AV_DEV to your own Sonos device number e.g.

Code: [Select]
Local AV_DEV = 73
And then add the rest of the code, updating the temperature from 232 to 74 and then the Condition device numbers from 115 to ??? (What ever it is?)

Good to see that you got it working. I spent some time figuring this out since I am not a programmer.
The thing that can be a bit confusing I guess is that in this code the weather condition and temperature is coming from two different devices. I use a real outdoor sensor to report the temperature.
The code is working perfect for me, and I use it every morning when I turn on the lights in my kitchen.

regards
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: jimpapa on February 21, 2014, 07:36:03 am
@haavard

Yes, thanks!

So to use your own outdoor temp sensor.  Did you just have to change the device number
Ie: what I have as 75 to the device number of your sensor ?

Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: haavard on February 21, 2014, 07:45:49 am
What do you want the code to read info from? Weather Plugin only?

Code: [Select]
local OutTemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature", 232)
local currentCondition = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1", "Condition", 115)

115 is my device number for the Weather underground device.
232 is the device number for my local temperature sensor.

If you go into settings for the device and the advance part you will find the "CurrentTemperature" variable and the "Condition" variable
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: jimpapa on February 21, 2014, 09:33:10 am
ok.. Thats my observation, 232 is your temp sensor..

Thanks

It works great.. Using the OSX TTS engine with the "siri" voice (Samantha)

Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: haavard on February 21, 2014, 12:05:43 pm
How did you setup the plugin to work with osx tts?


Sent from my iPad using Tapatalk
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: jimpapa on February 21, 2014, 02:32:31 pm
I'm running Beta 3 that has the OSX_TTS support.

On the advanced tab just set the:

DefaultEngineTTS to OSX_TTS_SERVER

OSXTTSServerURL  http://YOUR_MACS_IP:8080

and on your MAC install this:

http://wolfpaulus.com/jounal/mac/ttsserver/

and configure from your web browser: http://YOUR_MACS_IP:8080


Works perfect  ;)
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on February 21, 2014, 06:52:06 pm
Here is new piece of TTS code to provide you with a way to have random words spoken, that way  each time you run it, it's potentially different. I've taken bits and pieces from other posts, so I cannot take any credit..

Play Random Words

Code: [Select]
url = require("socket.url")

local SONOS = 5
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local TEMP_SID = "urn:upnp-org:serviceId:TemperatureSensor1"

local greetings = { "Hi, ", "Hello, ", "Whatcha, " }
local greeting = greetings[math.random(table.getn(greetings))], "RAID"

local messages = { "How Ya Doing! ", "Hope You're Well! " }
local message = messages[math.random(table.getn(messages))], "RAID"

local introductions = { "My name is Vera! ", "This is your house talking, " }
local introduction = introductions[math.random(table.getn(messages))], "RAID"

local goodbyes = { "See Ya!", "Adios!", "Cheerrio,", "Goodbye, ", "Later, ", "Bye, "}
local goodbye = goodbyes[math.random(table.getn(goodbyes))], "RAID"

local frase = greeting .. message .. introduction .. goodbye

local benTemp = luup.variable_get(TEMP_SID,"CurrentTemperature", 210)
local emmaTemp = luup.variable_get(TEMP_SID,"CurrentTemperature", 211)

luup.call_action(LS_SID, "Say", {Text = string.format("%s, %s, I just wanted to let you know that Ben's room is at %s degrees, where as Emmers is at %s degrees,, %s ", greeting, message, benTemp, emmaTemp, goodbye)}, SONOS)

Let me know what you think..
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on February 22, 2014, 05:06:57 am
Here's a bit of fun, but it can be used for an all zones announcement. Just change you say command to include the GroupZones details below.

All Zones Message

(This one is out of respect to the UK TV show Red Dwarf)

Code: [Select]
local SONOS = 5
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"

luup.call_action(LS_SID, "Say", {Text="A-wooga! A-wooga! this is a test, A-wooga! A-wooga! this is a drill, A-wooga! A-wooga!.. No need to panic!! ", Language="en", GroupZones="ALL",Volume=30, SameVolumeForAll="true"},SONOS)
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Piwtorak on February 28, 2014, 04:12:28 pm
ParkerC,
thanks for the tip..

but what is the 5 in the SONOS variable, what this value set ?
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Brientim on February 28, 2014, 04:23:40 pm
ParkerC,
thanks for the tip..

but what is the 5 in the SONOS variable, what this value set ?
Looking at the script, it is the Device ID of the Sonos that will play the TTS
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on February 28, 2014, 06:06:54 pm
Simon Says Game

A big thank you to Rex for helping me get this one done, I never would've got there myself, it's all him..

The trouble with random selection is that you can get repetition - which doesn't work too well for Simon says. This version does not allow that to happen.

Code: [Select]
local count = math.random(2,5)
local prms = string.format("%d,%d",count,0)
luup.call_delay("simonSays",1,prms)

function simonSays(sprms)
local SONOS = 105
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local scnt,slst = string.match(sprms,"(%d+),(%d+)")
local cnt = tonumber(scnt)
local lst = tonumber(slst)
local says = {"put your hands on your head!", "put your hands on your hips!", "turn around!", "sit down!", "touch your nose!", "stand on one leg!", "Touch your toes!"}
local pick = math.random(1,table.maxn(says))
if pick == lst then
if pick == table.maxn(says) then
pick = pick - 1
else
pick = pick + 1
end
end
local thissay = says[pick]
if (cnt > 1) then thissay = "Simon says, " .. thissay end
luup.call_action(LS_SID, "Say", {Text = thissay}, SONOS)
cnt = cnt - 1
if cnt > 0 then
local parms = string.format("%d,%d",cnt,pick)
luup.call_delay("simonSays",10,parms)
end
end
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: jimpapa on February 28, 2014, 06:36:16 pm
Now just to make the adult version.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: RexBeckett on February 28, 2014, 07:01:41 pm
Now just to make the adult version.
Vera says, you're a bad boy!  ;)
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: pasqualz on May 07, 2014, 06:32:28 pm
These programming ideas are awesome and I plan to implement al of them. right now i'm coding a time triggered event that will check all door and window sensors, then verbally report to me which ones are open around bed time. does anyone know of a way to store values from a previous run so I can make the system talk louder if the same sensors are still tripped? i'm assuming the code can handle arrays, right? the question is how to clear the arrays after a certain time so that the system starts anew the next evening?

Also, a question about the simon says code. What's the best way to trigger this event to run on demand? can I create a virtual light switch that I can "turn on" from the dashboard, or better yet, my iphone Vera mobile app? Also, how can I stop the program from looping when i'm done with it?
thanks
Pasqual
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: RexBeckett on May 08, 2014, 12:15:34 am
Quote
does anyone know of a way to store values from a previous run so I can make the system talk louder if the same sensors are still tripped?

Just use a global variable (without a local tag). It will vanish after a restart so will return  nil.

Quote
i'm assuming the code can handle arrays, right?

Lua is very comfortable with arrays.

Quote
the question is how to clear the arrays after a certain time so that the system starts anew the next evening?

You could have another scene scheduled to run at a certain time that cleared the global variable.

Quote
What's the best way to trigger this event to run on demand?

Just run the scene.

Quote
can I create a virtual light switch that I can "turn on" from the dashboard, or better yet, my iphone Vera mobile app?

Yes. You could use VirtualSwitch or MultiSwitch.

Quote
Also, how can I stop the program from looping when i'm done with it?

It stops automatically after saying the last phrase (without Simon says).
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: pasqualz on May 13, 2014, 03:06:58 pm
I know that this post may be moved out of this section for being off topic, but it does have much relevance to dynamic TTS messages using the Sonos Plugin, so I thought I'd start here. So I'm planning to start programming some LUA code in a scene that will do the following:

1) Identify all door/window sensors and get their device IDs. I could hard code all my sensors into the script, but I think I can use the devices variable. I found this code in the Luup Lua extensions wiki page which seems to gather all attributes for attached devices. I can probably search for devices that are within a specific device type for my purposes:

for k, v in pairs(luup.devices) do
    for k2, v2 in pairs(v) do
        luup.log("Device #" .. k .. ":" .. k2 .. "=" .. tostring(v2))
    end
end

2) Loop through all the devices and check if any are tripped

3) Generate a dynamic TTS message that either tells me that all windows/doors are closed, or identify the open ones by name using the device information gathered in step 1.

I think this is pretty straightforward, and could put it together in a few hours, but in the spirit of community, I realized that others may have already created such a script and would be willing to post it here for consumption. This is where I'm probably going to be told to make my request in a more generic programming forum.
Thanks
Pasqual
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on May 13, 2014, 03:15:43 pm
Hi @pasqualz

This thread is largely focussed on sharing the end product, rather than the journey - but this is a community so we all try and help where we can :)

You  might however be better served in the Programming section of the forum.  However if it is a straight forward as you say, then please do post your code examples here, as I think it would be great to have some code that can more effectively scan all devices and report information via TTS.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: pasqualz on May 15, 2014, 11:21:56 pm
Door & Window Sensor Check and Annunciation
Ok, so it took more than "a few hours" but here it is!!! This script checks for all connected door/window sensors, announces how many there are and if any are open (tripped,) it tells you which ones. I need to do more tinkering with the speech strings to make them smoother and maybe a bit slower. I plan to have two scenes, one for upstairs sonos and one for downstairs. The variables should be self explanatory. Feel free to reply with questions, comments, improvements, etc.

-- Door/Window sensor check and speech annotation by Pasqual Zottola
local vol = 50
local son = 27 --mast bdr =33, kitch=27
local devcnt = 0
local devno = 0
local numopen = 0
local isare = "is"
local opensensors = " "
luup.log('Commencing sensor device search loop')
for deviceNo,d in pairs(luup.devices) do
   if d.category_num == 4 then
           
      local tripped = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", deviceNo) or "Nil"
     
      if (tripped == "1") then
         opensensors = opensensors .. ". " .. d.description
         --[[ This line will change to recording info to an array so sonos speaks only once.
luup.call_action("urn:micasaverde-com:serviceId:Sonos1", "Say",
     {Text=d.description .. " is Open", Language="en", Volume=vol}, son)
         --]]     
         -- luup.log(d.description .. " status was " .. tripped)
         numopen = numopen + 1
      end
   luup.log(d.description .. ' status:' .. tripped .. ' Dev #' .. deviceNo .. ' id:' .. d.id ..  ' cat #:' .. d.category_num .. ' type:' .. d.device_type)     
   devcnt = devcnt + 1
    end
end
if numopen == 0 then   --If there are no sensors tripped, log and announce!
   luup.log('There were ' .. devcnt .. ' door and window sensors found and all are closed')
   luup.call_action("urn:micasaverde-com:serviceId:Sonos1", "Say", {Text="There were " .. devcnt .. " door and window sensors found, and all are closed", Language="en", Volume=vol}, son)
   
else   --If there are any sensors tripped, log and announce!
   if numopen > 1 then
      isare = "are"
   end
      luup.log('There were ' .. devcnt .. ' door and window sensors found and ' .. numopen .. " " .. isare .. ' open' .. opensensors)
      luup.call_action("urn:micasaverde-com:serviceId:Sonos1", "Say", {Text="There were " .. devcnt .. " sensors found and " .. numopen .. " " .. isare .. " open." .. opensensors, Language="en", Volume=vol}, son)
     
end
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on May 16, 2014, 01:44:28 pm
Nice, thanks so much for sharing,

As is, it will look for everything that uses that service, so for example it will also report the status of the Ping Sensor plugin  and any motion sensors too e.g.

Quote
Ping Sensor status:0 Dev #9 id: cat #:4 type:urn:schemas-demo-ted-striker:device:PingSensor:1
_Motion Sensor status:1 Dev #246 id:30 cat #:4 type:urn:schemas-micasaverde-com:device:MotionSensor:1     
   

Maybe you could consider an option in your code so you can specify a certain device type, at least that could exclude the Ping sensor being reported.

If you click the '#' hash/number option on the tool bar, it will allow you to wrap your code up nicely with some HTML so it can stand out more
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: pasqualz on May 16, 2014, 08:50:12 pm
Thanks Parkerc, I had a feeling that there are more than just door/window sensors in category 4 but it was a simple starting point. Can anyone think of a specific attribute of these devices that is unique? I noticed that when I check the type of my devices, the Wintop sensors show up as motion sensors, and my Schlage sensors show up as window sensors so type doesn't seem reliable either. Since The names of all of my sensors have either the word "door" or "window" in them, I could add a string.find() command to look for either "door" or "window" in the description.
Thanks
Pasqual
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Brientim on May 16, 2014, 09:01:07 pm
You then need to look at sub-categories but as you may find, they are either not defined or incorrectly defined.
http://wiki.micasaverde.com/index.php/Luup_Device_Categories
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on May 17, 2014, 01:24:33 am
Hi Pasquel

As it is now - it actually works nicely for me as an 'occupancy checking tool' as the Ping sensor is used to track a few mobile phones.

Good idea about adding a filter, maybe if your code could allow for optional filters - so you could go from the top level Device, to the service, and then (if needed) down to aspects of the device description itself  - that would certainly give it flexibility to be used for any broad or specific set of TTS checks you would want done.

Another idea for you..

- add the ability to retrieve and use the 'name' of the room the sensor is in to the TTS - that way it could say "the <room name> door is open"
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: pasqualz on May 17, 2014, 04:02:08 pm
I'll definitely look into subcategories but was worried that one improperly reported device would mess that up. That's why I just decided to put the words "door" or "window" in the description. Of course there could be other devices with those words in there too!

Parkerc, I was going to retrieve and announce the room name for the devices, but my descriptions for the door & window sensors have the room name in them (i.e. Family Room Window 1, Front Door) bottom line is it would be minimal coding to add room names in if needed.
Thanks
Pasqual
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on May 18, 2014, 03:15:11 pm
Thanks @Pasqualz

I understand, people will have different set ups and like you I also have a some devices that have the room name in the description, however since adopting the room approach,  I've tried to change more of them over.

Keep up the good work, I like what you've done, mix your code with the random words post (previous page) and that could make it a little more dynamic/different.

I'm always excited to see how people are building TTS with Vera and Sonos - so please keep sharing :)
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Borat on August 06, 2014, 03:35:04 pm
Hi I just came across Pasqualz' script by accident and it addresses something I posted in a couple of other forums. I also want to announce tripped window and door sensors. I am trying to limit it only to door and window sensors though and not quite sure I understand what is going on. I thought I could just change the device in the following line to urn:schemas-micasaverde-com:device:DoorSensor:1, but that does not seem to work and it just reports all as closed. Why is this? Is there another way I can strip out motion sensors from the list?
local tripped = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1"

Excellent work by the way!
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on August 06, 2014, 04:00:01 pm
If I have understood you correctly - it looks like you have tried to replace a 'serviceId' with a 'device'. These are different things.

I'm not entirely sure how to do it myself, but you will need to add a device filter first, so it looks just for that device type, and then check for the serviceId or you could do it the other way round.

So when it finds everything that has tripped it then only speaks the ones that are a door/window sensor device.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Borat on August 06, 2014, 05:51:05 pm
I worked it out by adding subcategory in as motions are 3 and door window sensors are 1.

Cheers
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on August 06, 2014, 08:20:07 pm
Hi @borat

Great news - Feel free to post your updated code so others can make use of it
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Borat on August 11, 2014, 05:23:09 pm
Sure here you go:

-- Door/Window sensor check and speech annotation by Pasqual Zottola
local vol = 60
local son = 23
local devcnt = 0
local devno = 0
local numopen = 0
local isare = "is"
local opensensors = " "
luup.log('Commencing sensor device search loop')
for deviceNo,d in pairs(luup.devices) do
   if d.category_num == 4 and d.subcategory_num == 1 then
           
      local tripped = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", deviceNo) or "Nil"
     
      if (tripped == "1") then
         opensensors = opensensors .. ". " .. d.description .. ","
         numopen = numopen + 1
      end
   luup.log(d.description .. ' status:' .. tripped .. ' Dev #' .. deviceNo .. ' id:' .. d.id ..  ' cat #:' .. d.category_num .. ' type:' .. d.device_type)     
   devcnt = devcnt + 1
    end
end
if numopen == 0 then   --If there are no sensors tripped, log and announce!
   luup.log('There were ' .. devcnt .. ' door and window sensors found and all are closed')
   luup.call_action("urn:micasaverde-com:serviceId:Sonos1", "Say", {Text=devcnt .. " sensors were checked, and all are closed. House is secure. Goodbye!", Language="en", Volume=vol}, son)
   
else   --If there are any sensors tripped, log and announce!
   if numopen > 1 then
      isare = "are"
   end
      luup.log('There were ' .. devcnt .. ' door and window sensors found and ' .. numopen .. " " .. isare .. ' open' .. opensensors)
      luup.call_action("urn:micasaverde-com:serviceId:Sonos1", "Say", {Text="Warning! House may not be secure," .. devcnt .. " sensors were checked and " .. numopen .. " " .. isare .. " open. Check," .. opensensors, Language="en", GroupDevices="32", Volume=vol}, son)
     
end
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: sharadmenawat on September 18, 2014, 01:23:54 pm
Hi

I'm a non-programmer.

I was able to use this code to a certain extent. Some how I was not able to get the TTS work on this. I changed the device name to match mine in two places before using this code.

Any help is appreciated.

Sharad
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: RexBeckett on September 18, 2014, 01:34:17 pm
Hi

I'm a non-programmer.

I was able to use this code to a certain extent. Some how I was not able to get the TTS work on this. I changed the device name to match mine in two places before using this code.

Any help is appreciated.

Sharad

We may be able to help if you post the actual Lua code you are using and explain what does and doesn't work.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: sharadmenawat on September 19, 2014, 11:44:22 am
I've used the code given below. I was able to get change notifications when run the scene but some how the TTS part never returned the voice prompts. I changed the name for Sonos as it is in my Vera3.

Code:

-- Door/Window sensor check and speech annotation by Pasqual Zottola
local vol = 60
local son = 23
local devcnt = 0
local devno = 0
local numopen = 0
local isare = "is"
local opensensors = " "
luup.log('Commencing sensor device search loop')
for deviceNo,d in pairs(luup.devices) do
   if d.category_num == 4 and d.subcategory_num == 1 then
           
      local tripped = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", deviceNo) or "Nil"
     
      if (tripped == "1") then
         opensensors = opensensors .. ". " .. d.description .. ","
         numopen = numopen + 1
      end
   luup.log(d.description .. ' status:' .. tripped .. ' Dev #' .. deviceNo .. ' id:' .. d.id ..  ' cat #:' .. d.category_num .. ' type:' .. d.device_type)     
   devcnt = devcnt + 1
    end
end
if numopen == 0 then   --If there are no sensors tripped, log and announce!
   luup.log('There were ' .. devcnt .. ' door and window sensors found and all are closed')
   luup.call_action("urn:micasaverde-com:serviceId:Sonos", "Say", {Text=devcnt .. " sensors were checked, and all are closed. House is secure. Goodbye!", Language="en", Volume=vol}, son)
   
else   --If there are any sensors tripped, log and announce!
   if numopen > 1 then
      isare = "are"
   end
      luup.log('There were ' .. devcnt .. ' door and window sensors found and ' .. numopen .. " " .. isare .. ' open' .. opensensors)
      luup.call_action("urn:micasaverde-com:serviceId:Sonos", "Say", {Text="Warning! House may not be secure," .. devcnt .. " sensors were checked and " .. numopen .. " " .. isare .. " open. Check," .. opensensors, Language="en", GroupDevices="32", Volume=vol}, son)
     
end
-------------
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: RexBeckett on September 19, 2014, 11:52:08 am
Quote
I changed the name for Sonos as it is in my Vera3.

You have changed the service ID in the action calls. This is a constant regardless of what you call the device on your system. Change them back to "urn:micasaverde-com:serviceId:Sonos1" as in the original code.

Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: sharadmenawat on September 19, 2014, 12:49:56 pm
RexBeckett - I made the change and created a new scene for testing. I created a scene where a door sensor activates and then expects TTS output. But the TTS output not played on Sonos.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on September 19, 2014, 01:09:02 pm
Can you confirm TTS works normally , when you just enter text into the device ?

Also, please post the code you are testing here. That way people can help you see if any errors exist,
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: sharadmenawat on September 19, 2014, 02:21:56 pm
Can you confirm TTS works normally , when you just enter text into the device ?

Also, please post the code you are testing here. That way people can help you see if any errors exist,

Yes the TTS works when I enter the text in TTS box and use "Say".

The code I'm using is posted below:

-- Door/Window sensor check and speech annotation by Pasqual Zottola
local vol = 60
local son = 23
local devcnt = 0
local devno = 0
local numopen = 0
local isare = "is"
local opensensors = " "
luup.log('Commencing sensor device search loop')
for deviceNo,d in pairs(luup.devices) do
   if d.category_num == 4 and d.subcategory_num == 1 then
           
      local tripped = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", deviceNo) or "Nil"
     
      if (tripped == "1") then
         opensensors = opensensors .. ". " .. d.description .. ","
         numopen = numopen + 1
      end
   luup.log(d.description .. ' status:' .. tripped .. ' Dev #' .. deviceNo .. ' id:' .. d.id ..  ' cat #:' .. d.category_num .. ' type:' .. d.device_type)     
   devcnt = devcnt + 1
    end
end
if numopen == 0 then   --If there are no sensors tripped, log and announce!
   luup.log('There were ' .. devcnt .. ' door and window sensors found and all are closed')
   luup.call_action("urn:micasaverde-com:serviceId:Sonos1", "Say", {Text=devcnt .. " sensors were checked, and all are closed. House is secure. Goodbye!", Language="en", Volume=vol}, son)
   
else   --If there are any sensors tripped, log and announce!
   if numopen > 1 then
      isare = "are"
   end
      luup.log('There were ' .. devcnt .. ' door and window sensors found and ' .. numopen .. " " .. isare .. ' open' .. opensensors)
      luup.call_action("urn:micasaverde-com:serviceId:Sonos1", "Say", {Text="Warning! House may not be secure," .. devcnt .. " sensors were checked and " .. numopen .. " " .. isare .. " open. Check," .. opensensors, Language="en", GroupDevices="32", Volume=vol}, son)
     
end

Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: RexBeckett on September 19, 2014, 05:37:47 pm
RexBeckett - I made the change and created a new scene for testing. I created a scene where a door sensor activates and then expects TTS output. But the TTS output not played on Sonos.

I see that you are using a device number of 23 for your Sonos - as in the original code. I doubt that, by co-incidence, your Sonos is the same device number as the codes's author. Change this line:

Code: [Select]
local son = 23
to use the actual device number of your Sonos. You can get this from the Sonos device's Advanced tab.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: sharadmenawat on September 20, 2014, 05:55:07 pm
RexBeckett - I made the change and created a new scene for testing. I created a scene where a door sensor activates and then expects TTS output. But the TTS output not played on Sonos.

I see that you are using a device number of 23 for your Sonos - as in the original code. I doubt that, by co-incidence, your Sonos is the same device number as the codes's author. Change this line:

Code: [Select]
local son = 23
to use the actual device number of your Sonos. You can get this from the Sonos device's Advanced tab.

Yes this made the Sonos speak up  ;) but now when there are tripped devices I'm hearing only one message "Zero devcices are checked and all are closed. House is secure. Good Bye"

This is false sense of security. Can you help here?

Sharad
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: RexBeckett on September 20, 2014, 06:11:11 pm
Quote
Yes this made the Sonos speak up  ;) but now when there are tripped devices I'm hearing only one message "Zero devcices are checked and all are closed. House is secure. Good Bye"

You will get this message if the code does not find any devices in your system where the device_category is 4 and the sub_category is 1 (door & window sensors).

What sensors are you using? Check on each device's Advanced tab for the values in the category_num and subcategory_num fields. You may need to modify the code to suit your mix of devices.

FYI: These are the standard Device Categories (http://wiki.micasaverde.com/index.php/Luup_Device_Categories).
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: sharadmenawat on September 21, 2014, 08:42:26 am
Quote
Yes this made the Sonos speak up  ;) but now when there are tripped devices I'm hearing only one message "Zero devcices are checked and all are closed. House is secure. Good Bye"

You will get this message if the code does not find any devices in your system where the device_category is 4 and the sub_category is 1 (door & window sensors).

What sensors are you using? Check on each device's Advanced tab for the values in the category_num and subcategory_num fields. You may need to modify the code to suit your mix of devices.

FYI: These are the standard Device Categories (http://wiki.micasaverde.com/index.php/Luup_Device_Categories).

Rex Beckett - Thanks a lot. This works fine after the change suggested by you.  :D

Since I'm new to this and still experimenting, my thoughts keep maturing and newer ideas keep coming and I'm sure I'm not the first to hit them here. Here are few things that I want to achieve with this and help me wherever you can:

1. I want a code that should execute every time a sensor is tripped and announce the details of it. BUT before the announcement a DING DONG should play to grab attention and then followed by the announcement. This will help me understand which door has been opened (specially with kids I need to keep a track on them when they go out or come in). I think some tweaks to the existing code should do this.

2. I have two at this time and will add one more. All the announcements should play on the ALL Sonos in my home irrespective of grouping status or play mode of Sonos.

I might add more later as we grow with this.

Sharad
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: RexBeckett on September 21, 2014, 02:56:28 pm
Quote
I want a code that should execute every time a sensor is tripped and announce the details of it. BUT before the announcement a DING DONG should play to grab attention and then followed by the announcement. This will help me understand which door has been opened (specially with kids I need to keep a track on them when they go out or come in). I think some tweaks to the existing code should do this.

The existing code is designed to check all security sensors of the pre-determined type whenever the scene is run - usually on time schedules. You could just add triggers for each of your sensors so the scene is run whenever a sensor is tripped. Alternatively, instead of searching through all the sensors each time, you could set a global variable in each trigger's Luup Event with the number or name of the sensor and have simplified code in the scene's main Luup tab that speaks the required message.

To have a sound alert followed by a message you will need to have a delay in your code. See Delayed Actions (http://forum.micasaverde.com/index.php/topic,18679.msg154756.html#msg154756) for examples of how to program delays.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: sharadmenawat on September 25, 2014, 02:30:57 pm
Quote
Yes this made the Sonos speak up  ;) but now when there are tripped devices I'm hearing only one message "Zero devcices are checked and all are closed. House is secure. Good Bye"

You will get this message if the code does not find any devices in your system where the device_category is 4 and the sub_category is 1 (door & window sensors).

What sensors are you using? Check on each device's Advanced tab for the values in the category_num and subcategory_num fields. You may need to modify the code to suit your mix of devices.

FYI: These are the standard Device Categories (http://wiki.micasaverde.com/index.php/Luup_Device_Categories).

All the announcements should play on the ALL Sonos in my home irrespective of grouping status or play mode of Sonos.

Sharad

Any solution for announcing on ALL Sonos and reverting back to individual state (may be un-grouped) after announcement.

Sharad
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: lolodomo on September 25, 2014, 07:16:12 pm
Use ALL as value for GroupZones parameter.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: sharadmenawat on September 26, 2014, 11:52:47 am
Use ALL as value for GroupZones parameter.

While using ALL, I found that zones don't announce in Sync and that's annoying when three zones announce with time lag. Any suggestions?

Sharad
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: lolodomo on September 28, 2014, 03:47:57 am
Use ALL as value for GroupZones parameter.

While using ALL, I found that zones don't announce in Sync and that's annoying when three zones announce with time lag. Any suggestions?

Sharad

Normally impossible with Sonos system. In my case, groups are always in sync ... but I only own 2 Sonos in my home.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: SteveZ on November 02, 2014, 01:14:46 pm
I did some tweaking on the code, and finally got it to work.
I am not 100% sure what did the trick. But the faultfinding help lolodomo got me on the right track.
The code that works for me is as follows:

Code: [Select]
url = require("socket.url")

local AV_DEV = 253
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"

local OutTemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature", 232)
local currentCondition = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1", "Condition", 115)

luup.call_action(LS_SID, "Say", {Text = string.format("The outdoor condition is %s, and the temperature is currently at %s degrees", currentCondition, OutTemp) ,Volume=23}, AV_DEV)




Thanks for your help!


Thanks for this! I tweaked your code a bit to add the high temp for the day

Code: [Select]
local AV_DEV = 125
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"

local OutTemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature", 165)
local currentCondition = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1", "Condition", 164)
local HighTemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature", 167)

luup.call_action(LS_SID, "Say", {Text = string.format("Good morning. The outdoor condition is %s, and the temperature is currently at %s degrees with a high of %s degrees", currentCondition, OutTemp, HighTemp) ,Volume=23}, AV_DEV)
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: tb001 on November 02, 2014, 01:32:12 pm
I did some tweaking on the code, and finally got it to work.
I am not 100% sure what did the trick. But the faultfinding help lolodomo got me on the right track.
The code that works for me is as follows:

Code: [Select]
url = require("socket.url")

local AV_DEV = 253
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"

local OutTemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature", 232)
local currentCondition = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1", "Condition", 115)

luup.call_action(LS_SID, "Say", {Text = string.format("The outdoor condition is %s, and the temperature is currently at %s degrees", currentCondition, OutTemp) ,Volume=23}, AV_DEV)




Thanks for your help!


Thanks for this! I tweaked your code a bit to add the high temp for the day

Code: [Select]
local AV_DEV = 125
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"

local OutTemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature", 165)
local currentCondition = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1", "Condition", 164)
local HighTemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature", 167)

luup.call_action(LS_SID, "Say", {Text = string.format("Good morning. The outdoor condition is %s, and the temperature is currently at %s degrees with a high of %s degrees", currentCondition, OutTemp, HighTemp) ,Volume=23}, AV_DEV)

This is great! I'm just getting started with luup commands, so it's so helpful to have a template to work from. Is there an easy way to add in an 'if this, then that' command? If so, should that be added in same call action or a second action? For example, if the current condition is rainy, to say 'It's wet out, don't forget your galoshes!'

Also, if I enter this into the 'test luup code' box, should it be working? Probably a dim question, I know!

Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: SteveZ on November 02, 2014, 02:58:43 pm
To test just enter in the test luup code box but change the device ID numbers to match your devices, in my case my sonos device is 125, temp is 165, weather is 164, and high temp is 167.

as far as your other question goes, I have no idea but I seem to remember seeing someone here doing just that. if I come across it ill let you know
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: tb001 on November 02, 2014, 03:06:33 pm
Thank you! I had switched the sonos dvc id, but missed the others. Rookie mistake...
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Pseudomizer on November 25, 2014, 12:06:17 am
Guys,

I have a problem which I cannot explain. I created a trigger if the proper code is being punched into my Yale Door lock, it will trigger the scene "Welcome home".

Here is the LUUP code:
Code: [Select]
local AV_DEV = 132
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local time = os.date('%M minutes past %I:')
luup.sleep (2000)
luup.call_action(LS_SID, "Say", {Text = string.format("Welcome Home. The current time is %s", time),Volume=50}, AV_DEV)

For whatever reason it does not execute all the time. In most of the times it simply says nothing. When I go back into the Automation section, open the luup code, don't change any code but press save luup code, then save changes, then it will work one time and that's it.

In some situations it does start off saying what it is supposed to say but while saying it, it stops in the middle of the sentence or during the time saying process.

I tried rebooting the lock by removing the batteries, I rebooted Vera and I rebooted my router. Unless I go into the system and save the luup code it doesn't say what it is supposed to say.

I should point out that it worked perfectly before the last Sonos Plugin Update but I don't know if this is related. I should also point out that I did check the checklist as well posted in this forum before posting here.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: RexBeckett on November 25, 2014, 03:20:04 am
To debug this, you need to find out which part of the sequence is failing. Check LuaUPnP.log at the time when the code is entered into the lock. You should be able to see if the scene is being triggered, the Say action is being fired and if something else is happening to stop it working.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: charlesrg on December 08, 2014, 11:52:18 pm
If you guys are interested, here is my scene some may want as example:
Code: [Select]
local SONOS_ID = 127
local SONOS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local SONOS_ZONES="Kitchen"
local SONOS_ZONES="ALL"
local WEATHER_ID = 129
local WEATHER_SID = "urn:upnp-micasaverde-com:serviceId:Weather1"

local time = os.date('It is %H:%M.')
local weatherCurrCondition = luup.variable_get(WEATHER_SID, "Condition", WEATHER_ID)
local weatherForecast           = luup.variable_get(WEATHER_SID, "Forecast.0.Condition", WEATHER_ID)
local weatherLow                  = luup.variable_get(WEATHER_SID, "Forecast.0.LowTemperature", WEATHER_ID)
local weatherHigh                 = luup.variable_get(WEATHER_SID, "Forecast.0.HighTemperature", WEATHER_ID)
local weather = "The weather right now  is: " .. weatherCurrCondition .. ". The forecast for today is: " ..  weatherForecast .. " with a minimum of " .. weatherLow .. " and a maximum of " .. weatherHigh

luup.call_action(SONOS_SID, "Say",
                 {Text="Good morning." .. time .. weather .. ". Have a great day.", Language="en", GroupZones=SONOS_ZONES,
                  Volume=15, SameVolumeForAll="true"},
                 SONOS_ID)

function pandoraOn()
    luup.call_action(SONOS_SID, "PlayURI",
                 {URIToPlay="SF:Enya Radio", Volume=15},
                 SONOS_ID)
end
luup.call_delay("pandoraOn",60)

return true
This will tell the weather for the day and then play a radio. I like the military time format, I grew up with it.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Piwtorak on December 09, 2014, 05:20:53 pm
Very good Charlesrg...

if I need change the "morning" for "afternoon" when necessary...do you have some code for this ?
thanks !!
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: parkerc on December 09, 2014, 07:53:59 pm
if I need change the "morning" for "afternoon" when necessary...do you have some code for this ?
thanks !!

Hi @piwtorak

Have a look at this earlier post, maybe this will help..  -> http://forum.micasaverde.com/index.php/topic,12408.msg92210.html#msg92210
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: charlesrg on December 09, 2014, 10:12:57 pm
Very good Charlesrg...

if I need change the "morning" for "afternoon" when necessary...do you have some code for this ?
thanks !!

Ok, here goes a little improvement. I found that the other code with seconds was not that neat.

Code: [Select]
local SONOS_ID = 127
local SONOS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local SONOS_ZONES="Kitchen"
local SONOS_ZONES="ALL"
local WEATHER_ID = 129
local WEATHER_SID = "urn:upnp-micasaverde-com:serviceId:Weather1"

local time = os.date('It is %H:%M.')
local weatherCurrCondition = luup.variable_get(WEATHER_SID, "Condition", WEATHER_ID)
local weatherForecast           = luup.variable_get(WEATHER_SID, "Forecast.0.Condition", WEATHER_ID)
local weatherLow                  = luup.variable_get(WEATHER_SID, "Forecast.0.LowTemperature", WEATHER_ID)
local weatherHigh                 = luup.variable_get(WEATHER_SID, "Forecast.0.HighTemperature", WEATHER_ID)
local weather = "The current weather is " .. weatherCurrCondition .. ". The forecast for today is " ..  weatherForecast .. " with a minimum of " .. weatherLow .. " and a maximum of " .. weatherHigh
local hour=tonumber(os.date('%H'))
local greeting=""

if  hour < 12  then
    greeting = "Good morning"
elseif hour < 17 then
    greeting = "Good afternoon"
elseif hour < 21 then
    greeting = "Good evening"
else
    greeting = "Good night"
end

luup.call_action(SONOS_SID, "Say",
                 {Text= greeting .. " Daisy and Charles. " .. time .. weather .. ". Goodbye.", Language="en", GroupZones=SONOS_ZONES,
                  Volume=15, SameVolumeForAll="true"},
                 SONOS_ID)

function pandoraOn()
    luup.call_action(SONOS_SID, "PlayURI",
                 {URIToPlay="SF:Enya Radio", GroupZones=SONOS_ZONES, SameVolumeForAll="true", Volume=15},
                 SONOS_ID)
end
luup.call_delay("pandoraOn",60)

return true
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Piwtorak on December 14, 2014, 11:50:38 am
Thanks Charlesrg,

I can not hear any sound from my sonos...

I have this code working fine on my kitchen...

luup.call_action("urn:micasaverde-com:serviceId:Sonos1","Say",{Text="Ola",Language="pt", Volume=50,GroupDevices=""},111)

I put my sonos ID (111) in your code and the ID of my Weather ProviderWUI (Weather Underground) is 25...

I have tapped out the pandora function because I do not have this service...

I can not listen any sound..

what could be wrong ?

thanks for help and clarify...
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: charlesrg on December 15, 2014, 09:56:47 pm
If you are on UI7 you can paste the code into the (APPS -> Develop Apps -> Test Luup Code.

Make sure the code works there before you put into your scene.

Perhaps something is wrong with your ID's. I copied and paste from my working setup.

I usually use Notepad++ to do syntax highlighting on the code so I'm sure I didn't miss any quote, try that.

Here is the code again just in case:

Code: [Select]
local SONOS_ID = 127
local SONOS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local SONOS_ZONES="Kitchen"
local SONOS_ZONES="ALL"
local WEATHER_ID = 129
local WEATHER_SID = "urn:upnp-micasaverde-com:serviceId:Weather1"

local time = os.date('It is %H:%M.')
local weatherCurrCondition = luup.variable_get(WEATHER_SID, "Condition", WEATHER_ID)
local weatherForecast           = luup.variable_get(WEATHER_SID, "Forecast.0.Condition", WEATHER_ID)
local weatherLow                  = luup.variable_get(WEATHER_SID, "Forecast.0.LowTemperature", WEATHER_ID)
local weatherHigh                 = luup.variable_get(WEATHER_SID, "Forecast.0.HighTemperature", WEATHER_ID)
local weather = "The current weather is " .. weatherCurrCondition .. ". The forecast for today is " ..  weatherForecast .. " with a minimum of " .. weatherLow .. " and a maximum of " .. weatherHigh
local hour=tonumber(os.date('%H'))
local greeting=""

if  hour < 12  then
    greeting = "Good morning"
elseif hour < 17 then
    greeting = "Good afternoon"
elseif hour < 21 then
    greeting = "Good evening"
else
    greeting = "Good night"
end

luup.call_action(SONOS_SID, "Say",
                 {Text= greeting .. " Hello,    excuse me, " .. greeting .. " Daisy and Charles. " .. time .. weather .. ". Goodbye.", Language="en", GroupZones=SONOS_ZONES,
                  Volume=20, SameVolumeForAll="true"},
                 SONOS_ID)

function pandoraOn()
    luup.call_action(SONOS_SID, "PlayURI",
                 {URIToPlay="SF:Enya Radio", GroupZones="ALL", SameVolumeForAll="true", Volume=20},
                 127)
end
luup.call_delay("pandoraOn",60)

return true
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Piwtorak on December 16, 2014, 08:16:27 am
Please Look if your plugin (source of information) is the same I have installed...

thanks

Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: charlesrg on December 20, 2014, 12:31:26 am
I'm using wundeground weather plugin for weather info and I'm on UI7.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: JoeyD on December 20, 2014, 04:45:27 pm
I just released a plug-in for exactly this purpose!   :)  ("Speaking the weather using data from Wunderground weather app....)

 
http://forum.micasaverde.com/index.php/topic,29522.0.html
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: teonebello on December 20, 2014, 08:06:21 pm
Do you think that it could be possible to translate it also in other languages? I saw that some some phrases are editable, but I don't know if all. Thanks
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: JoeyD on December 21, 2014, 11:31:39 am
Hi teonebello,

Currently you are able to edit the phrases to whatever you'd like, but there are other aspects of the grammatical sentences that are hard coded.

I can attempt to expose these so that they can be edited as well, but the difficulty there will be the underlying difference in language semantics.  In other words, I construct a current forecast like this:

[ For the immediate forecast we are expecting] [wonderfully clear skies] [with] [almost spring like temperatures] [ranging from] [40 to 50] [degrees].

The items in bold are ones that you can currently change to whatever you want since they are based on what the incoming weather values are.  I can expose the other phrases to be user editable, and that may allow you to construct a syntatically usable statement in your language, but it may not.

It's a good suggestion, and I 'll put it on my "to-do" list.  Thanks!

Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Hernan on January 01, 2015, 10:55:16 pm
Hi Guys,

I have a couple of SONOS 1, which have been pair (using SONOS APP) in order to create a stereo experience and say command does not work. SONOS plug in was setup selecting only one of the players and it works fine reproducing music and TTS on both speakers except when calling say lua command...it says nothing. 
Could someone please share some "Say" working code for a couple of SONOS players that are already grouped?

Here is what I have been trying to do:

local AV_DEV =59
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"

local TEMP_SID = "urn:upnp-org:serviceId:TemperatureSensor1"
local OutTemp = luup.variable_get(TEMP_SID,"CurrentTemperature", 38)

luup.call_action(LS_SID, "Say", {Text = string.format("The outdoor temperature is currently at %s degrees", OutTemp),Volume=45}, AV_DEV)

I did also try the command GroupZones="Kitchen" (Kitchen is the group name on SONOS APP) after the Volume parameter with no success.  :'(

Thanks,

Hernan
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Hernan on January 10, 2015, 12:50:21 pm
Hi guys,

Solved. I found that paired or synced sonos needs the GroupZones set to "Current" in order to get TTS working. This is all you need GroupZones="Current" in order to make TTS working from luup code within a scene. I did also test it on my paired set of sonos 3, with no issues.

Hopefully this can help to anyone else with same issue and wondering if this tip can be included on the sonos plug-in help page.

Thanks lodomo for this awesome plug-in.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: lolodomo on January 10, 2015, 01:46:00 pm
"Current" just bypasses the creation of a new group for TTS and just uses the current group setup.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: hkk1644 on February 05, 2015, 09:23:39 pm
I can see all the luup code that needs to be put in but is there anyone that can point out if anything else needs to be done? like what needs to change in the loop code to have it work with peoples veras? changing the name of the sonos maybe? or is there an id that needs to change?  do i need to do anything in the advance tab, like add the sonos and pick a command?

All I see is code for the luup and ive tried pasting that into a scene and running it but nothing will happen.  any help would be appreciated.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Brientim on February 05, 2015, 11:33:53 pm
Quote
See below extracts for what you may need to change
Code: [Select]

local LI_DEV1 = 82  *1 In this case the Device_Id for the the light and is reference later
local AV_DEV = 5 *2 This is the Sonos Device_Id and is reference later,
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local SEC_SERV = "urn:upnp-org:serviceId:SwitchPower1"

local livingroomlight = luup.variable_get(SEC_SERV, "Status",LI_DEV2)  *1 LI_DEV2

luup.call_action(LS_SID, "Say", {Text = string.format("All lights are off ")}, AV_DEV) *2 AV_DEV

Otherwise you may see it like this
Code: [Select]


local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local SEC_SERV = "urn:upnp-org:serviceId:SwitchPower1"

local livingroomlight = luup.variable_get(SEC_SERV, "Status",82) Note as it is not declared

luup.call_action(LS_SID, "Say", {Text = string.format("All lights are off ")}, 5) Note as it is not declared

Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: hkk1644 on February 06, 2015, 12:11:41 pm
So all that needs to be done is putting in the luup code?  no devices in the advance tab need to be selected?  also i kind of see where the name of the sonos needs to be changed.  Is there someone who has a video of doing this? maybe just a walk through of putting in the code?
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Brientim on February 06, 2015, 02:10:35 pm
In the first post is the links to the code for various functional examples.

Really, that is it at the moment. You need to get the device Id that match you Vera and look in the example in the logical places I pointed you too.  Look for numbers.

If it does not work and you need more help, come back here, but ensure you paste the code you are trying to fix. From there someone will assist identify what you need to look at, such as Services and how to  verify other aspects of data required.

Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Brientim on February 06, 2015, 02:12:48 pm
Yes, you need to go to the devices Advanced tab and get their Device Id (the number) not their name. This is what you are replacing
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: hkk1644 on February 06, 2015, 03:11:53 pm
alright so this is the code I am putting in, all i want to do is create a scene that i can trigger when i walk in the door. If someone could let me maybe Bold or italicize what i need to change with some type of guidance I would really appreciate it, once again I really have looked through as much as i can of the forums and cannot find anything to help me.  thank you very much for any help

url = require("socket.url")
local t = os.date('*t')

local AV_DEV = 5
local LS_SID = "urn:micasaverde-com:serviceId:Sonos"
local current_second = t.hour * 3600 + t.min * 60 -- number of sec since midnight
local morning = 0 * 3600 +  0 * 60             -- 00:00
local afternoon = 12 * 3600 +  0 * 60       -- 12:00
local evening = 18 * 3600 +  0 * 60             -- 18:00
local name = "Chris"

   if (current_second > morning) and (current_second < afternoon) then
        luup.call_action(LS_SID, "Say", {Text = string.format("Good Morning %s ", name)}, AV_DEV)
   else
     
        if (current_second > afternoon) and (current_second < evening) then
             luup.call_action(LS_SID, "Say", {Text = string.format("Good Afternoon %s ", name)}, AV_DEV)
        else

             luup.call_action(LS_SID, "Say", {Text = string.format("Good Evening %s ", name)}, AV_DEV)
        end
   end
Title: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Brientim on February 06, 2015, 03:25:17 pm
local AV_DEV = 5  Change the 5 to match your Sonos Device# from the Advance tab as per the attached screen shot, it would be 404.  You will then need to set the trigger to activate the scene.

Some YouTube stuff, the first is Vera Traing the the other two are specific to Automating Sonos. I have not watched them but there were referenced in other threads and created by a member of the forum to assist in these cases...
https://m.youtube.com/user/veratraining

http://youtu.be/hCvsC0MmoV4

https://m.youtube.com/watch?v=9uff1VQFdpA
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: hkk1644 on February 06, 2015, 04:18:50 pm
url = require("socket.url")
local t = os.date('*t')

local AV_DEV = 24 ------I changed this to myg device
local LS_SID = "urn:micasaverde-com:serviceId:Sonos" -------what is this do i have to change this to whatever my sonos zone is called?
local current_second = t.hour * 3600 + t.min * 60 -- number of sec since midnight
local morning = 0 * 3600 +  0 * 60             -- 00:00
local afternoon = 12 * 3600 +  0 * 60       -- 12:00
local evening = 18 * 3600 +  0 * 60             -- 18:00
local name = "Chris" -----what is this? do i have to change this to my username?

   if (current_second > morning) and (current_second < afternoon) then
        luup.call_action(LS_SID, "Say", {Text = string.format("Good Morning %s ", name)}, AV_DEV)
   else
     
        if (current_second > afternoon) and (current_second < evening) then
             luup.call_action(LS_SID, "Say", {Text = string.format("Good Afternoon %s ", name)}, AV_DEV)
        else

             luup.call_action(LS_SID, "Say", {Text = string.format("Good Evening %s ", name)}, AV_DEV)
        end
   end
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: hkk1644 on February 06, 2015, 04:21:34 pm
is there anything else I need todo in the advance tab or the devices tab like add something with a specific command? thank you so much
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Brientim on February 06, 2015, 04:50:14 pm
url = require("socket.url")
local t = os.date('*t')

local AV_DEV = 24 ------I changed this to myg device
local LS_SID = "urn:micasaverde-com:serviceId:Sonos" -------There is an error with the Service ID see below for change. There are a number of ways to verify this and http://forum.micasaverde.com/index.php/topic,29454.msg209151.html#msg209151 for more details
local current_second = t.hour * 3600 + t.min * 60 -- number of sec since midnight
local morning = 0 * 3600 +  0 * 60             -- 00:00
local afternoon = 12 * 3600 +  0 * 60       -- 12:00
local evening = 18 * 3600 +  0 * 60             -- 18:00
local name = "Chris" -----what is this? This is used later and announcement of the name recorded here, so change to your name, but I have changed it below to make it more clearer

   if (current_second > morning) and (current_second < afternoon) then
        luup.call_action(LS_SID, "Say", {Text = string.format("Good Morning %s ", name)}, AV_DEV)
   else
     
        if (current_second > afternoon) and (current_second < evening) then
             luup.call_action(LS_SID, "Say", {Text = string.format("Good Afternoon %s ", name)}, AV_DEV)
        else

             luup.call_action(LS_SID, "Say", {Text = string.format("Good Evening %s ", name)}, AV_DEV)
        end
   end

Code: [Select]
url = require("socket.url")
local t = os.date('*t')

local AV_DEV = 24
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local current_second = t.hour * 3600 + t.min * 60
local morning = 0 * 3600 +  0 * 60           
local afternoon = 12 * 3600 +  0 * 60     
local evening = 18 * 3600 +  0 * 60             
local myName = "Your Name"

   if (current_second > morning) and (current_second < afternoon) then
        luup.call_action(LS_SID, "Say", {Text = string.format("Good Morning %s ", myName)}, AV_DEV)
   else
     
        if (current_second > afternoon) and (current_second < evening) then
             luup.call_action(LS_SID, "Say", {Text = string.format("Good Afternoon %s ", myName)}, AV_DEV)
        else

             luup.call_action(LS_SID, "Say", {Text = string.format("Good Evening %s ", myName)}, AV_DEV)
        end
   end
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: hkk1644 on February 06, 2015, 05:18:27 pm
Hi, I clicked on the link you had to help fix the error code for the "local service id".  The 2 links that had screenshots when hovered over are dead and the other one where it said to paste this following link into my browser only took me to google search results.

http://<veraip>/port_3480/data_request?id=lu_status&output_format=xml

what is...service id? is it anything i can find clicking around UI5?

Once again thank you for being a great help, i looked around on the posts to give you a thumbs up or something similar but didnt see anything
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Brientim on February 06, 2015, 05:23:49 pm
The link needs to be changed <veraip> must be modified to reflect the IP address of your Vera e.g 192.168.1.55/port...., etc

There are also a number of apps that contain the links internal to vera but I can't remember them at the moment.

An example of how to find the service id is found at
http://forum.micasaverde.com/index.php/topic,13003.msg96037.html#msg96037

Lua Invoke will provide a drill down:
http://vera_ip/port_3480/data_request?id=lu_invoke
Of course as above change vera_ip to match your vera's IP address and then paste into your browser
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: hkk1644 on February 06, 2015, 05:33:45 pm
GOT IT! now what am i looking for...i would paste it in here but its way too much.  Is it something correlated to the sonos or the vera itself?  if so what can i put in the search box to pull it up, also what is it just a number or words?
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Brientim on February 06, 2015, 06:05:32 pm
Most of the codes have the respective data correct and only a few variable need modifying. Just by chance the one you selected to start with had the incorrect Service ID.. That did not help you. Did you try the code I pasted before with the corrected information? Match the Sonos device number and change to reflect your name.
Do not paste the user_data.xml  output as it contains sensitive information.

If you drill throught the lu_invoke you will see service ids and other variable used but only time will give you an understanding
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: hkk1644 on February 06, 2015, 06:09:08 pm
Oh I see what youre saying, let me give that a shot.  No I was using the one that was originally posted as the one to use.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: hkk1644 on February 06, 2015, 06:13:16 pm
AHHH, it worked ! thanks you so much for your help
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Brientim on February 06, 2015, 06:17:44 pm
That is fine... Now you have one working start on the next. Compare the changes I pointed out and for most, it will only require the Device id being updated. Good luck
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: hkk1644 on February 06, 2015, 06:24:44 pm
Yes most definitely now I have an idea of how and what needs to change from the code.  one more question if I wanted to assign a volume to it, what command and where would i put it?  Also is there a pdf file somewhere that addresses all of the different code and syntax for luup?
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Brientim on February 06, 2015, 06:54:26 pm
Look here for volume example
http://forum.micasaverde.com/index.php/topic,12408.msg94695.html#msg94695
:


http://wiki.mios.com/index.php/Luup_Lua_extensions

http://forum.micasaverde.com/index.php?topic=18679.5
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Brientim on February 06, 2015, 07:41:59 pm
@RexBeckett also has created a Lua test tool which will no doubt assist . It is referenced out at the bottom of the last link but for ease of reference
http://forum.micasaverde.com/index.php/topic,24018.0.html
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Dnomyar220 on February 12, 2015, 03:51:52 pm
Is anyone having trouble with the Sonos plugin with the latest firmware update to UI7?  Mine no longer will connect to the sonos, even though the static IP of the sonos connect is listed in the settings.

edit: a few resets in a row seem to have fixed this, if anyone else has the same issue.  All is well  ;D
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: becky on February 14, 2015, 03:35:07 pm
I've been playing around with the TTS and wanted some "morning announcements" that let our family know what's going on for the day before we get out of bed. The latest thing I did was use the GCal3 plugin to pull our events for the day and announce them. It's been really helpful! For my next trick, I'm hoping to figure out how to alert us to weather alerts when they happen, without it becoming annoying.

I have one hang-up and I know there has to be a simple solution that I'm missing somewhere. I can't seem to get my times to format properly so that it doesn't read off as a number (seven zero zero for instance instead of seven o'clock or even just 7.) Can anyone point me in the right direction, please?

url = require("socket.url")
local AV_DEV = 48
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local time = os.date('%I:%M')
local SONOSZONES="ALL"
local SameVolume="true"
local TEMP_SID ="urn:upnp-org:serviceId:TemperatureSensor1"
local WUGTempHigh = luup.variable_get(TEMP_SID, "CurrentTemperature", 33)
local currentCondition = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1", "Forecast.1.Condition", 30)
local GS_SID = "urn:srs-com:serviceId:GCalIII"
local jsonEvents = luup.variable_get(GS_SID, "gc_jsonEvents",52)
if ((jsonEvents == "[]") or (jsonEvents == nil)) then
  TodaysEvents="There are no events for today."
else
 TodaysEvents="Todays events are "
end
package.loaded.json = nil
local json = require("json")
local eventList =json.decode(jsonEvents)
local numberEvents = table.getn(eventList)
local startevent, startDate, startTime, endevent, endTime, eventname, event
for i = 1,numberEvents do
  startevent = eventList[ i ].eventStart
  startDate = os.date("%Y-%m-%d", startevent)
  startTime = os.date("%H:%M:%S", startevent)
  endevent = eventList[ i ].eventEnd
  endTime = os.date("%H:%M:%S", endevent)
  eventname = eventList[ i ].eventName
  TodaysEvents = TodaysEvents .. eventname ..  " .       "
  luup.log(event)
end
package.loaded.json = nil

luup.call_action(LS_SID, "Say", {Text = string.format("Good morning, Kirkwoods!  It is now %s. Here is your daily morning report. Today will be %s with a high of %s degrees. %s. Have a great day.", time, currentCondition, WUGTempHigh, TodaysEvents), GroupZones=SONOSZONES, SameVolumeForAll=SameVolume, Volume=50}, AV_DEV)
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: JoeyD on February 16, 2015, 01:41:15 pm
Hi Becky,

FYI, there is a specific plug-in called SayTheWeather (http://forum.micasaverde.com/index.php/topic,29522.0.html) that works along side Sonos to announce weather forecast and alerts.  You might want to check that out. :)

But to answer your question, I use a similar format that you have in your code (example, 07:00) and I don't recall any issues with the time being read as "seven-zero-zero" or "seven hundred."  Are you sure the final statement that is being sent to Sonos TTS includes the colon in the text?

Lastly, I myself use "en" as the Google rendering language.  It's possible if you're using a different language or dialect that it interprets "7:00" differently.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: becky on February 17, 2015, 08:41:59 am
Thanks JoeyD! I wrote the script before the saytheweather plugin was available, and this is really the only the place I use that function. Eventually I want to write a script that alerts us when there is a severe weather alert, but I'm trying to limit the number of moving parts on the vera as much as I can.

I'm using "en" as the rendering language. And I tweaked the code a tad. This morning it read it as seven hundred. I'll have to see if the ":" is in the time when it goes off to TTS, thank you for the tip!
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: kiethr on February 17, 2015, 10:35:52 am
Hey Becky,  I'm interested in having my sonos system speak my calendar events. Is there any way you would share your code?
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: becky on February 17, 2015, 10:47:24 am
I'd be happy to! Below are the lines that are specific to the calendar device. Make sure you have installed the Gcal3 device and the sonos device first. You have to do a little searching on the forum, but are excellent plugins and have really great documentation!! (kudos to the developers) You'll need to change my device numbers to reflect your own.

My code is a little sloppy, but it seems to work for us.
variable and device mumbo-jumbo:

url = require("socket.url")
local AV_DEV = 48
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local time = os.date('%I:%M')
local todaydate = os.date('%Y-%m-%d')
local SONOSZONES="ALL"
local SameVolume="true"
local TEMP_SID ="urn:upnp-org:serviceId:TemperatureSensor1"
local WUGTempHigh = luup.variable_get(TEMP_SID, "CurrentTemperature", 33)
local currentCondition = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1", "Forecast.1.Condition", 30)
local GS_SID = "urn:srs-com:serviceId:GCalIII"
local jsonEvents = luup.variable_get(GS_SID, "gc_jsonEvents",52)

checking to see if there are any events for the day. if not, tell us that there are no events for today.

if ((jsonEvents == "[]") or (jsonEvents == nil)) then
  TodaysEvents="There are no events for today."
else
 TodaysEvents="Todays events are "
end


unwrapping all the different variables in the device variable.

package.loaded.json = nil
local json = require("json")
local eventList =json.decode(jsonEvents)
local numberEvents = table.getn(eventList)
local startevent, startDate, startTime, endevent, endTime, eventname, event

looping around the dumping the variables into an array

for i = 1,numberEvents do
  startevent = eventList[ i ].eventStart
  startDate = os.date("%Y-%m-%d", startevent)
  startTime = os.date("%H:%M:%S", startevent)
  endevent = eventList[ i ].eventEnd
  endTime = os.date("%H:%M:%S", endevent)
  eventname = eventList[ i ].eventName

if the event happens today, add it to the TodaysEvents variable. if not, don't add it.

  if (startDate == todaydate) then
   TodaysEvents = TodaysEvents .. eventname ..  " .       "
   luup.log(event)
  end


end
package.loaded.json = nil


and then of course sending it all to the sonos device.

luup.call_action(LS_SID, "Say", {Text = string.format("Good morning, Kirkwoods!  It is now %s. Here is your daily morning report. Today will be %s with a high of %s degrees. %s. Have a great day.", time, currentCondition, WUGTempHigh, TodaysEvents), GroupZones=SONOSZONES, SameVolumeForAll=SameVolume, Volume=50}, AV_DEV)
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: becky on February 17, 2015, 11:37:19 am
Hi Becky,

FYI, there is a specific plug-in called SayTheWeather (http://forum.micasaverde.com/index.php/topic,29522.0.html) that works along side Sonos to announce weather forecast and alerts.  You might want to check that out. :)

But to answer your question, I use a similar format that you have in your code (example, 07:00) and I don't recall any issues with the time being read as "seven-zero-zero" or "seven hundred."  Are you sure the final statement that is being sent to Sonos TTS includes the colon in the text?

Lastly, I myself use "en" as the Google rendering language.  It's possible if you're using a different language or dialect that it interprets "7:00" differently.

I just installed say the weather and I think it's going to do exactly what I need for the severe weather alert. Thank you!!! That saves a lot of time and headache - perfect!
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: kiethr on February 17, 2015, 06:09:17 pm
Thanks becky, I have those apps already installed along with say the weather. There all great and really round off my automation project.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: tomgru on March 14, 2015, 04:02:14 pm
I want to use this to say the inside temperature of my house.  My challenges is that i actually don't have any sensors that read temp, other than my Ecobee thermostat.  Since Ecobee hasn't released the ability to read their remote sensors, i have to rely on the reading from the thermostat itself.  I can see this in the U15 dashboard, so i have a temp reading.... but i'm not sure how to get it into this LUA.

thoughts?
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Brientim on March 14, 2015, 04:28:28 pm
Follow the example in the first post.
http://forum.micasaverde.com/index.php?topic=12408
You'll need to  Device ID and Service ID you want to read in.

Two way to identify the Service ID as described in this post http://forum.micasaverde.com/index.php/topic,12408.msg218662.html#msg218662
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: tomgru on March 14, 2015, 04:53:55 pm
Follow the example in the first post.
http://forum.micasaverde.com/index.php?topic=12408
You'll need to  Device ID and Service ID you want to read in.

Two way to identify the Service ID as described in this post http://forum.micasaverde.com/index.php/topic,12408.msg218662.html#msg218662

Oh... that's handy.  thanks.  SO, if i did that right, this is the service id:

serviceId=urn:upnp-org:serviceId:TemperatureSensor1&action=GetCurrentTemperature

Modifying the example, i'm not sure what the '42' represents?  Would the code look like this?

local AV_DEV = 145 ? My sonos device ID
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"

local TEMP_SID = " urn:upnp-org:serviceId:TemperatureSensor1&action=GetCurrentTemperature "
local houseTemp = luup.variable_get(TEMP_SID,"CurrentTemperature", 42)
luup.call_action(LS_SID, "Say", {Text = string.format("The house temperature is currently at %s degrees ", houseTemp)}, AV_DEV)


EDIT.  I tried that in the test Lua field, and got "code failed". trying to think through this, i made these edits.  still failed.

local AV_DEV = 45
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local TEMP_SID = " urn:upnp-org:serviceId:TemperatureSensor1 "
local houseTemp = luup.variable_get(TEMP_SID,"GetCurrentTemperature ", 42)
luup.call_action(LS_SID, "Say", {Text = string.format("The house temperature is currently at %s degrees ", houseTemp)}, AV_DEV)
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Brientim on March 14, 2015, 05:56:10 pm
local houseTemp = luup.variable_get(TEMP_SID,"GetCurrentTemperature ", 42)
From the above GetCurrentTemperature should have been CurrentTemperature
Watch out for white spaced i.e "GetCurrentTemperature "


42 represented the device ID of the Thermometer that you are reading the temperature from. Remove the two comments once you update  -- This is the Thermostat Device # -- This is the Thermostat Device #


***************************Try this with correct devices and remove comments************
Code: [Select]
url = require("socket.url")

local AV_DEV = 452 -- This is the Sonos Device #
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"

local TEMP_SID = "urn:upnp-org:serviceId:TemperatureSensor1"
local TEMP_DEV = luup.variable_get(TEMP_SID, "CurrentTemperature", 531) -- This is the Thermostat Device #

luup.call_action(LS_SID, "Say", {Text = string.format("The current temperature is %s degrees", TEMP_DEV )}, AV_DEV)
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: tomgru on March 14, 2015, 09:35:35 pm
local houseTemp = luup.variable_get(TEMP_SID,"GetCurrentTemperature ", 42)
From the above GetCurrentTemperature should have been CurrentTemperature
Watch out for white spaced i.e "GetCurrentTemperature "


42 represented the device ID of the Thermometer that you are reading the temperature from. Remove the two comments once you update  -- This is the Thermostat Device # -- This is the Thermostat Device #


***************************Try this with correct devices and remove comments************
Code: [Select]
url = require("socket.url")

local AV_DEV = 452 -- This is the Sonos Device #
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"

local TEMP_SID = "urn:upnp-org:serviceId:TemperatureSensor1"
local TEMP_DEV = luup.variable_get(TEMP_SID, "CurrentTemperature", 531) -- This is the Thermostat Device #

luup.call_action(LS_SID, "Say", {Text = string.format("The current temperature is %s degrees", TEMP_DEV )}, AV_DEV)

worked perfectly.  thanks!!!! 
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: tomgru on March 14, 2015, 09:40:47 pm
So, my next question is how to get the time to sound better.  i used the code in this forum, but what it says is ... as an example:

"the current time is 38 minutes past oh six"... meaning 6:38pm

can i get it to say "38 minutes past 6 o'clock" ?

this is addicting.  :o
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Brientim on March 15, 2015, 01:32:51 am
Should be something like this:

Code: [Select]
url = require("socket.url")
local AV_DEV = 452
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"


local_hours = os.date('%I: o clock')
local_hours = local_hours:gsub("^0", "")
local_minutes = os.date('%M minutes')
local_minutes = local_minutes:gsub("^0", "")

luup.call_action(LS_SID, "Say", {Text = string.format("The time is %s  past %s", local_minutes, local_hours),Volume=60}, AV_DEV)

Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Brientim on March 15, 2015, 04:20:08 am
You probably should add the logical test to account for the exact hours e.g:

Code: [Select]
url = require("socket.url")
local AV_DEV = 452
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local time = os.date('%M minutes')

local_hours = os.date('%I: o clock')
local_hours = local_hours:gsub("^0", "")
local_minutes = os.date('%M minutes')
local_minutes = local_minutes:gsub("^0", "")

if local_minutes < "1" then
luup.call_action(LS_SID, "Say", {Text = string.format("The time is  %s",  local_hours),Volume=40}, AV_DEV)

else
luup.call_action(LS_SID, "Say", {Text = string.format("The time is %s  past %s", local_minutes, local_hours),Volume=60}, AV_DEV)

end
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: tomgru on March 15, 2015, 01:34:54 pm
You probably should add the logical test to account for the exact hours e.g:


That worked perfectly!  way out of my league!

I combined that with the time code.... and it all works.  One weird thing though.  the volume is significantly louder for the time part, vs the weather announcement.  all in the same Lua code.    Here's how i combined them.

Code: [Select]
url = require("socket.url")
local AV_DEV = 45
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"

local time = os.date('%M minutes')
local_hours = os.date('%I: o clock')
local_hours = local_hours:gsub("^0", "")
local_minutes = os.date('%M minutes')
local_minutes = local_minutes:gsub("^0", "")

local TEMP_SID = "urn:upnp-org:serviceId:TemperatureSensor1"
local TEMP_DEV = luup.variable_get(TEMP_SID, "CurrentTemperature", 196)

luup.call_action(LS_SID, "Say", {Text = string.format("Welcome home. The current temperature in the house is %s degrees", TEMP_DEV )}, AV_DEV)

if local_minutes < "1" then
luup.call_action(LS_SID, "Say", {Text = string.format("The time is  %s",  local_hours),Volume=40}, AV_DEV)
else
luup.call_action(LS_SID, "Say", {Text = string.format("The time is %s  past %s", local_minutes, local_hours),Volume=60}, AV_DEV)
end
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Brientim on March 15, 2015, 03:06:53 pm
The reason behind the differ volume was the time string includes the declared volume.

You could include the volume in the temp of combine them e.g

if local_minutes < "1" then
luup.call_action(LS_SID, "Say", {Text = string.format("Welcome home. The current temperature in the house is %s degree and the time is currently %s", , local_hours),Volume=40}, AV_DEV)
else
luup.call_action(LS_SID, "Say", {Text = string.format("Welcome home. The current temperature in the house is %s degree and the time is %s  past %s",TEMP_DEV, local_minutes, local_hours),Volume=60}, AV_DEV)
end
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Brientim on March 15, 2015, 03:35:46 pm
I see the second string the volume is set at "60" whereby, if it was on the hour as in the first string, the volume is set to "40"
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: tomgru on March 15, 2015, 10:31:02 pm
I see the second string the volume is set at "60" whereby, if it was on the hour as in the first string, the volume is set to "40"

perfect... thanks. I'm not sure where the weather statement was getting the volume setting from, but combining them fixed it perfectly, saved for the extra comma :-)

awesome.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Brientim on March 15, 2015, 11:48:26 pm
The original weather would have been at the last volume the Sonos was at.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: tomgru on March 16, 2015, 09:39:09 am
The original weather would have been at the last volume the Sonos was at.

That makes sense. Thanks for the help!
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: dp0100 on April 23, 2015, 12:44:04 pm
I've been using this code and it works great and just want to say what a great forum this is - everyone is really helpful.
So....in that light, I would like to add another piece of logic to the below that checks only "armed" sensors. I'm also kinda of new to the LUUP code so any help would be greatly appreciated!

I figured it out.... :)

Sure here you go:

-- Door/Window sensor check and speech annotation by Pasqual Zottola
local vol = 60
local son = 23
local devcnt = 0
local devno = 0
local numopen = 0
local isare = "is"
local opensensors = " "
luup.log('Commencing sensor device search loop')
for deviceNo,d in pairs(luup.devices) do
   if d.category_num == 4 and d.subcategory_num == 1 and d.armed == 1 then
           
      local tripped = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", deviceNo) or "Nil"
     
      if (tripped == "1") then
         opensensors = opensensors .. ". " .. d.description .. ","
         numopen = numopen + 1
      end
   luup.log(d.description .. ' status:' .. tripped .. ' Dev #' .. deviceNo .. ' id:' .. d.id ..  ' cat #:' .. d.category_num .. ' type:' .. d.device_type)     
   devcnt = devcnt + 1
    end
end
if numopen == 0 then   --If there are no sensors tripped, log and announce!
   luup.log('There were ' .. devcnt .. ' door and window sensors found and all are closed')
   luup.call_action("urn:micasaverde-com:serviceId:Sonos1", "Say", {Text=devcnt .. " sensors were checked, and all are closed. House is secure. Goodbye!", Language="en", Volume=vol}, son)
   
else   --If there are any sensors tripped, log and announce!
   if numopen > 1 then
      isare = "are"
   end
      luup.log('There were ' .. devcnt .. ' door and window sensors found and ' .. numopen .. " " .. isare .. ' open' .. opensensors)
      luup.call_action("urn:micasaverde-com:serviceId:Sonos1", "Say", {Text="Warning! House may not be secure," .. devcnt .. " sensors were checked and " .. numopen .. " " .. isare .. " open. Check," .. opensensors, Language="en", GroupDevices="32", Volume=vol}, son)
     
end
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: JS007 on May 05, 2015, 04:57:19 pm
wow, nice plugin, just got the sonos 1 and tts works nice
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: dp0100 on May 05, 2015, 05:29:49 pm
Also modified the below to send a vera alert notification in case any sensors are found open:

-- Door/Window sensor check and speech annotation by Pasqual Zottola
local vol = 10
local vol1 = 45
local son = 40
local devcnt = 0
local devno = 0
local numopen = 0
local isare = "is"
local opensensors = " "
luup.log('Commencing sensor device search loop')
for deviceNo,d in pairs(luup.devices) do
   if d.category_num == 4 and d.subcategory_num == 3 then
           
      local tripped = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", deviceNo) or "Nil"
     local armed = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1", "Armed", deviceNo) or "Nil"
      if (tripped == "1" and armed == "1") then
         opensensors = opensensors .. ". " .. d.description .. ","
         numopen = numopen + 1
      end
   luup.log(d.description .. ' status:' .. tripped .. ' Dev #' .. deviceNo .. ' id:' .. d.id ..  ' cat #:' .. d.category_num .. ' type:' .. d.device_type)     
   devcnt = devcnt + 1
    end
end
if numopen == 0 then   --If there are no sensors tripped, log and announce!
   luup.log('There were ' .. devcnt .. ' door and window sensors found and all are closed')
   luup.call_action("urn:micasaverde-com:serviceId:Sonos1", "Say", {Text=devcnt .. " sensors checked, House is secure.", Language="en", Volume=vol, GroupZones="Current"}, son)
   
else   --If there are any sensors tripped, log and announce!
   if numopen > 1 then
      isare = "are"
   end
      luup.log('There were ' .. devcnt .. ' door and window sensors found and ' .. numopen .. " " .. isare .. ' open' .. opensensors)
      luup.call_action("urn:micasaverde-com:serviceId:Sonos1", "Say", {Text="Warning! House may not be secure," .. devcnt .. " sensors were checked and " .. numopen .. " " .. isare .. " open. Check," .. opensensors, Language="en", GroupDevices="32", Volume=vol1}, son)
      luup.call_action("urn:richardgreen:serviceId:VeraAlert1", "SendAlert", {Message = "{tone:1} One of the doors are open, need to check", Recipient = "Davids_Phone"},21)
     
end
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: MNB on June 13, 2015, 10:37:08 pm
I'd be happy to! Below are the lines that are specific to the calendar device. Make sure you have installed the Gcal3 device and the sonos device first. You have to do a little searching on the forum, but are excellent plugins and have really great documentation!! (kudos to the developers) You'll need to change my device numbers to reflect your own.

My code is a little sloppy, but it seems to work for us.
variable and device mumbo-jumbo:

url = require("socket.url")
local AV_DEV = 48
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local time = os.date('%I:%M')
local todaydate = os.date('%Y-%m-%d')
local SONOSZONES="ALL"
local SameVolume="true"
local TEMP_SID ="urn:upnp-org:serviceId:TemperatureSensor1"
local WUGTempHigh = luup.variable_get(TEMP_SID, "CurrentTemperature", 33)
local currentCondition = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1", "Forecast.1.Condition", 30)
local GS_SID = "urn:srs-com:serviceId:GCalIII"
local jsonEvents = luup.variable_get(GS_SID, "gc_jsonEvents",52)

checking to see if there are any events for the day. if not, tell us that there are no events for today.

if ((jsonEvents == "[]") or (jsonEvents == nil)) then
  TodaysEvents="There are no events for today."
else
 TodaysEvents="Todays events are "
end


unwrapping all the different variables in the device variable.

package.loaded.json = nil
local json = require("json")
local eventList =json.decode(jsonEvents)
local numberEvents = table.getn(eventList)
local startevent, startDate, startTime, endevent, endTime, eventname, event

looping around the dumping the variables into an array

for i = 1,numberEvents do
  startevent = eventList[ i ].eventStart
  startDate = os.date("%Y-%m-%d", startevent)
  startTime = os.date("%H:%M:%S", startevent)
  endevent = eventList[ i ].eventEnd
  endTime = os.date("%H:%M:%S", endevent)
  eventname = eventList[ i ].eventName

if the event happens today, add it to the TodaysEvents variable. if not, don't add it.

  if (startDate == todaydate) then
   TodaysEvents = TodaysEvents .. eventname ..  " .       "
   luup.log(event)
  end


end
package.loaded.json = nil


and then of course sending it all to the sonos device.

luup.call_action(LS_SID, "Say", {Text = string.format("Good morning, Kirkwoods!  It is now %s. Here is your daily morning report. Today will be %s with a high of %s degrees. %s. Have a great day.", time, currentCondition, WUGTempHigh, TodaysEvents), GroupZones=SONOSZONES, SameVolumeForAll=SameVolume, Volume=50}, AV_DEV)

Becky, This look great, however Newbie question, how does one make this work if you would be so kind and provide a short tutorial would be greatly appreciated. Mike
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: MNB on June 22, 2015, 11:04:18 am
@dp0100, I have the SONOs and TTS installed and working well, question as I review this thread how is the various code snip-its used. I know if I create a scene I can insert Luup within but some of these items almost look like they are more than a simple scene or am I missing something? for example the "Tell Time" if it were a scene needs some how to trigger on the hour, quarterly which I do not see that possible any clues would be greatly appreciated, Mike
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: dp0100 on June 22, 2015, 02:16:07 pm
Hi Mike,

The example I referenced is just a scene -  I created a new scene called = Security System Check. Then configured the schedule section to run every night at 9:30pm. Then go to the LUUP page and pasted that code (of course making sure the id's match your specific configurations) BTW: I'm on UI5

So for your "Tell Time" example, I would do the exact same thing, in the schedule have it setup to run every hour or what ever your time constraint is. ( though not sure I would do it every hour) Hope this helps..David
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: MNB on June 23, 2015, 01:07:49 pm
David,
Thanxs for the comeback. I created a scene using "schedule" as the  trigger and set it 1 hour and dropped the luup code within the LUUP page. Was able to test the scene by depressing the scene play button which worked like a champ with one exception the 1 hour is set to when ever I created the scene "10:08" so then next trigger is set for 11:08 any suggestions as to how one could set the timer to actual clock time? Mike
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: dp0100 on June 24, 2015, 08:54:31 am
Sure, np..
I'm sure there is a much easier way via LUUP but I'm kinda of new to this so I'll use the trigger/schedule functionality.
Create a new scene that is scheduled to start every morning at a predetermined time (say 8am). Then update your existing scene to trigger off of this new one that launches every morning at 8am.
If you need to end it at another time, just create a new scene that triggers at say 9pm and terminates your scene that occurs every hour. Make sense?
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: MNB on June 24, 2015, 12:49:11 pm
David,
Makes sense, I will make the update in my scene to reflect. I'm also starting to use PLEG and will experiment with it to do the same. Mike
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: lemrock on July 27, 2015, 07:41:55 pm
There was a software update for Sonos today and now the "Say" function does not work anymore. I get an error on the Sonos that says : Unable to play "Say.***.mp3"- file is encoded incorrectly". My Sonos  has been playing the same mp3 files on a daily basis flawlessly for many many months without any issues. Is there a cure for what ails my Sonos?
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: lemrock on July 27, 2015, 08:32:01 pm
Sorry, but I made a mistake and asked this question in the wrong forum.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: f1ip on July 31, 2015, 02:40:06 am
Sonos with Tts don't work now.
Have anyone this problem or it's only my ?
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: lolodomo on July 31, 2015, 02:43:30 am
Sonos with Tts don't work now.
Have anyone this problem or it's only my ?
Yes, everyone using Google TTS.
Please take a look at the other topic at top of this section.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: lakewoodjazz on July 31, 2015, 11:04:19 am
Seems Sonos update 5.4 has limited all files to a minimum of 16k sample rates and Sonos support says the Sonos app audio text is probably not meeting that requirement now. Can lolodomo help? I have a ticket started with Vera support but they said the Sonos app is third party.......
I miss my talking house.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: lolodomo on August 03, 2015, 03:38:02 am
Seems Sonos update 5.4 has limited all files to a minimum of 16k sample rates and Sonos support says the Sonos app audio text is probably not meeting that requirement now. Can lolodomo help? I have a ticket started with Vera support but they said the Sonos app is third party.......
I miss my talking house.

The problem is with Google that changed its API. Please read the corresponding topic in this section. I provided a fix.

5.4 is installed on all my Sonos and TTS is working well for me (Google, Microsoft and Mary).
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: simonclark on November 05, 2015, 06:28:22 pm
I'd be happy to! Below are the lines that are specific to the calendar device. Make sure you have installed the Gcal3 device and the sonos device first. You have to do a little searching on the forum, but are excellent plugins and have really great documentation!! (kudos to the developers) You'll need to change my device numbers to reflect your own.

My code is a little sloppy, but it seems to work for us.
variable and device mumbo-jumbo:

url = require("socket.url")
local AV_DEV = 48
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local time = os.date('%I:%M')
local todaydate = os.date('%Y-%m-%d')
local SONOSZONES="ALL"
local SameVolume="true"
local TEMP_SID ="urn:upnp-org:serviceId:TemperatureSensor1"
local WUGTempHigh = luup.variable_get(TEMP_SID, "CurrentTemperature", 33)
local currentCondition = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1", "Forecast.1.Condition", 30)
local GS_SID = "urn:srs-com:serviceId:GCalIII"
local jsonEvents = luup.variable_get(GS_SID, "gc_jsonEvents",52)

checking to see if there are any events for the day. if not, tell us that there are no events for today.

if ((jsonEvents == "[]") or (jsonEvents == nil)) then
  TodaysEvents="There are no events for today."
else
 TodaysEvents="Todays events are "
end


unwrapping all the different variables in the device variable.

package.loaded.json = nil
local json = require("json")
local eventList =json.decode(jsonEvents)
local numberEvents = table.getn(eventList)
local startevent, startDate, startTime, endevent, endTime, eventname, event

looping around the dumping the variables into an array

for i = 1,numberEvents do
  startevent = eventList[ i ].eventStart
  startDate = os.date("%Y-%m-%d", startevent)
  startTime = os.date("%H:%M:%S", startevent)
  endevent = eventList[ i ].eventEnd
  endTime = os.date("%H:%M:%S", endevent)
  eventname = eventList[ i ].eventName

if the event happens today, add it to the TodaysEvents variable. if not, don't add it.

  if (startDate == todaydate) then
   TodaysEvents = TodaysEvents .. eventname ..  " .       "
   luup.log(event)
  end


end
package.loaded.json = nil


and then of course sending it all to the sonos device.

luup.call_action(LS_SID, "Say", {Text = string.format("Good morning, Kirkwoods!  It is now %s. Here is your daily morning report. Today will be %s with a high of %s degrees. %s. Have a great day.", time, currentCondition, WUGTempHigh, TodaysEvents), GroupZones=SONOSZONES, SameVolumeForAll=SameVolume, Volume=50}, AV_DEV)

I made one small change to make the list of events sound a little nicer.  Hope you dont mind Becky

Code: [Select]
for i = 1,numberEvents do
  startevent = eventList[ i ].eventStart
  startDate = os.date("%Y-%m-%d", startevent)
  startTime = os.date("%H:%M:%S", startevent)
  endevent = eventList[ i ].eventEnd
  endTime = os.date("%H:%M:%S", endevent)
  eventname = eventList[ i ].eventName
  if (i == 1) then
      TodaysEvents = TodaysEvents ..  eventname ..  " .       "
      else
      TodaysEvents = TodaysEvents .. " then " .. eventname ..  " .       "
  end
  luup.log(event)
end
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: becky on November 10, 2015, 01:04:10 pm
Not at all! Modify away! In fact, add/change anything you want! I know I have since I last posted that.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: MNB on November 10, 2015, 06:30:34 pm
@becky,
Based on your last post you indicate that you've also made changes, anything you're willing to share... Question I'm assuming
that statement in the LUA example "checking to see if there are any events for the day. if not, tell us that there are no events for today." is a comment that is precursor with a double dash? Mike

Quote
I know I have since I last posted that.
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: MNB on November 13, 2015, 08:11:12 pm
Bump
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: becky on November 20, 2015, 12:37:24 pm
There hasn't been anything major that I think would be useful to anyone else but my family. I wanted to tell my son what homework he had to work on, so I found an online public calendar that his teachers keep up to date and I pull that in, then tell him what assignments/tests are happening for the week when he gets home. If I was really good, I would disable the TV and all his electronics until he gets it done. I'm not that good. LOL

Everything else has been clean-up. I would like a way to tell me how long my commute is for the day (via google), however that is a blue sky thing right now. Sorry I don't have anything major to contribute!
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: Dnomyar220 on November 20, 2015, 01:20:45 pm
Edit: disregard below message... apparently it's google limiting use of their TTS engine, I found out from another thread. Everyone is recommending Microsoft Translator TTS now.  Leaving below post unedited in case anyone else is having this issue.

Has anyone else been noticing problems with TTS not working 100% of the time?  I have two incredibly simple commands (Welcome home", and "Garage door open") set up currently.  When I started using this, it probably worked 95% of the time.  It would miss one every once in awhile, or repeat the same command 3-4 times.  I'm guessing it's just a memory management thing with Veralite? 

Lately (past month), it seems to only hit like 60% of the commands.  Maybe it's telling me it's time to restart my veralite... I just wish there was a way to increase the RAM in that thing and speed up the whole process. 
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: MNB on November 20, 2015, 01:26:01 pm
@becky, thanxs for the comeback. Understand what your saying, however what you take as benign someone like me is interested in the ability (technique(s) to pull in a public calendar and use it within the Speak capability. Mike
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: michelhamelin on March 20, 2016, 01:48:01 pm
And if i want Sonos to check and Say only battery level what i have to change?


Sure here you go:

-- Door/Window sensor check and speech annotation by Pasqual Zottola
local vol = 60
local son = 23
local devcnt = 0
local devno = 0
local numopen = 0
local isare = "is"
local opensensors = " "
luup.log('Commencing sensor device search loop')
for deviceNo,d in pairs(luup.devices) do
   if d.category_num == 4 and d.subcategory_num == 1 then
           
      local tripped = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", deviceNo) or "Nil"
     
      if (tripped == "1") then
         opensensors = opensensors .. ". " .. d.description .. ","
         numopen = numopen + 1
      end
   luup.log(d.description .. ' status:' .. tripped .. ' Dev #' .. deviceNo .. ' id:' .. d.id ..  ' cat #:' .. d.category_num .. ' type:' .. d.device_type)     
   devcnt = devcnt + 1
    end
end
if numopen == 0 then   --If there are no sensors tripped, log and announce!
   luup.log('There were ' .. devcnt .. ' door and window sensors found and all are closed')
   luup.call_action("urn:micasaverde-com:serviceId:Sonos1", "Say", {Text=devcnt .. " sensors were checked, and all are closed. House is secure. Goodbye!", Language="en", Volume=vol}, son)
   
else   --If there are any sensors tripped, log and announce!
   if numopen > 1 then
      isare = "are"
   end
      luup.log('There were ' .. devcnt .. ' door and window sensors found and ' .. numopen .. " " .. isare .. ' open' .. opensensors)
      luup.call_action("urn:micasaverde-com:serviceId:Sonos1", "Say", {Text="Warning! House may not be secure," .. devcnt .. " sensors were checked and " .. numopen .. " " .. isare .. " open. Check," .. opensensors, Language="en", GroupDevices="32", Volume=vol}, son)
     
end
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: notchy on May 28, 2016, 01:08:13 pm
Another new one for anyone who is interested..

Sonos Period Of The Day Greetings

This one will check the time of day and then great you with either Good Morning, Good Afternoon or Good Evening

Code: [Select]
url = require("socket.url")
local t = os.date('*t')

local AV_DEV = 5
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local current_second = t.hour * 3600 + t.min * 60 -- number of sec since midnight
local morning = 0 * 3600 +  0 * 60             -- 00:00
local afternoon = 12 * 3600 +  0 * 60       -- 12:00
local evening = 18 * 3600 +  0 * 60             -- 18:00
local name = "Chris"

   if (current_second > morning) and (current_second < afternoon) then
        luup.call_action(LS_SID, "Say", {Text = string.format("Good Morning %s ", name)}, AV_DEV)
   else
     
        if (current_second > afternoon) and (current_second < evening) then
             luup.call_action(LS_SID, "Say", {Text = string.format("Good Afternoon %s ", name)}, AV_DEV)
        else

             luup.call_action(LS_SID, "Say", {Text = string.format("Good Evening %s ", name)}, AV_DEV)
        end
   end

 Hi everyone, I know this is an old  thread but I am new to Veraplus and I wanted to get this code working with my sonos.
I have the Microsoft TTS setup and working as I tested this but when I copy the above code and change out my Sonos ID , this does not execute when i run it.
Can somone tell me where they are applying this code to get it read aloud?

Thanks
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: kiethr on June 28, 2016, 09:27:12 pm
I am hoping someone that could help me out is still reading this thread.  I have been using Becky's code for sometime.  I recently upgraded from a vera 3 on UI5 to a vera plus on UI7.   When i added the scene to my new vera it doesn't work  I  put the code in the test area ofthe vera plus and it states CODE FAILED.  Could someone help with this. 
Code: [Select]
url = require("socket.url")
local AV_DEV = 42,17
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local time = os.date('%I:%M')
local todaydate = os.date('%Y-%m-%d')
local SONOSZONES="ALL"
local SameVolume="true"
local TEMP_SID ="urn:upnp-org:serviceId:TemperatureSensor1"
local WUGTempHigh = luup.variable_get(TEMP_SID, "CurrentTemperature", 20)
local currentCondition = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1", "Forecast.1.Condition", 19)
local GS_SID = "urn:srs-com:serviceId:GCalIII"
local jsonEvents = luup.variable_get(GS_SID, "gc_jsonEvents", 55)

if ((jsonEvents == "[]") or (jsonEvents == nil)) then
  TodaysEvents="There are no events for today."
else
 TodaysEvents="Todays events are "
end

package.loaded.json = nil
local json = require("json")
local eventList =json.decode(jsonEvents)  <--------I think the issue could be here
local numberEvents = table.getn(eventList)
local startevent, startDate, startTime, endevent, endTime, eventname, event

for i = 1,numberEvents do
  startevent = eventList[ i ].eventStart
  startDate = os.date("%Y-%m-%d", startevent)
  startTime = os.date("%H:%M:%S", startevent)
  endevent = eventList[ i ].eventEnd
  endTime = os.date("%H:%M:%S", endevent)
  eventname = eventList[ i ].eventName

  if (startDate == todaydate) then
   TodaysEvents = TodaysEvents .. eventname ..  " .       "
   luup.log(event)
  end

end
package.loaded.json = nil

luup.call_action(LS_SID, "Say", {Text = string.format("Hello, Rumbold family!  It is now %s. Here is your daily calendar. Today will be %s with a high of %s degrees. %s. Have a great day.", time, currentCondition, WUGTempHigh, TodaysEvents), GroupZones=SONOSZONES, SameVolumeForAll=SameVolume, Volume=40}, AV_DEV)
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: ctguess on June 28, 2016, 11:11:46 pm
Try looking at this forum topic - http://forum.micasaverde.com/index.php/topic,26692.480.html Page 33, post #480. It has the following code snippet

 
Code: [Select]
local json = require("dkjson") -- depending on your vera version you may need to use require("json")
  local eventList =json.decode(jsonEvents)
  package.loaded.json = nil

Maybe you need the dkjson "version"
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: kiethr on June 29, 2016, 07:22:53 am
Well i changed that line and the code did not fail.  However i'm not home so I will have to wait until later to see if it is working.

Thanks for the tip!!!
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: lloydshearer on January 25, 2017, 12:14:59 pm
Hi
i am using the great piece of code posted in this forum to do a security sensor check. the code is below.  Does anyone know how to delay the execution of this code.  I need the delay because i am triggering the scene from a amazon echo through HA-Bridge, and the echo is responding ok as the code starts to respond over the sonos system in the same room, i know its trivial but its a bit annoying. 
Thanks in advance
Lloyd


local vol = 100
local son =399
local devcnt = 0
local devno = 0
local numopen = 0
local isare = "is"
local opensensors = " "
luup.log('Commencing sensor device search loop')
for deviceNo,d in pairs(luup.devices) do
   if d.category_num == 4 and d.subcategory_num == 1 then
           
      local tripped = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", deviceNo) or "Nil"
     
      if (tripped == "1") then
         opensensors = opensensors .. ". " .. d.description .. ","
         numopen = numopen + 1
      end
   luup.log(d.description .. ' status:' .. tripped .. ' Dev #' .. deviceNo .. ' id:' .. d.id ..  ' cat #:' .. d.category_num .. ' type:' .. d.device_type)     
   devcnt = devcnt + 1
    end
end
if numopen == 0 then   --If there are no sensors tripped, log and announce!
   luup.log('There were ' .. devcnt .. ' door and window sensors found and all are closed')
   luup.call_action("urn:micasaverde-com:serviceId:Sonos1", "Say", {Text=devcnt .. " sensors were checked, and all are closed. House is secure. ", Language="en", Volume=vol}, son)
   
else   --If there are any sensors tripped, log and announce!
   if numopen > 1 then
      isare = "are"
   end
      luup.log('There were ' .. devcnt .. ' door and window sensors found and ' .. numopen .. " " .. isare .. ' open' .. opensensors)
      luup.call_action("urn:micasaverde-com:serviceId:Sonos1", "Say", {Text="Warning! House may not be secure," .. devcnt .. " sensors were checked and " .. numopen .. " " .. isare .. " open. Check," .. opensensors, Language="en", GroupDevices="Basement, Kitchen", Volume=vol}, son)
     
end
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: cybrmage on January 25, 2017, 02:08:17 pm
Does anyone know how to delay the execution of this code.

Add an appropriate delay before the luup.call_action commands...

ie:

luup.sleep(1000) -- delay 1 second
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: RichardTSchaefer on January 25, 2017, 04:12:49 pm
Just remember ... the total for any delay by a single function (loops included) should not be much more than 1 second without destabilizing Vera.
In this case this should work ... in general  luup.sleep is a very bad function.
 
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: lloydshearer on January 27, 2017, 12:29:20 pm
Thanks very much, worked perfectly
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: lloydshearer on February 01, 2017, 08:50:52 pm
Hi
i am using the great piece of code posted in this forum to do a security sensor check. the code is below.  Does anyone know how to delay the execution of this code.  I need the delay because i am triggering the scene from a amazon echo through HA-Bridge, and the echo is responding ok as the code starts to respond over the sonos system in the same room, i know its trivial but its a bit annoying. 
Thanks in advance
Lloyd


local vol = 100
local son =399
local devcnt = 0
local devno = 0
local numopen = 0
local isare = "is"
local opensensors = " "
luup.log('Commencing sensor device search loop')
for deviceNo,d in pairs(luup.devices) do
   if d.category_num == 4 and d.subcategory_num == 1 then
           
      local tripped = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", deviceNo) or "Nil"
     
      if (tripped == "1") then
         opensensors = opensensors .. ". " .. d.description .. ","
         numopen = numopen + 1
      end
   luup.log(d.description .. ' status:' .. tripped .. ' Dev #' .. deviceNo .. ' id:' .. d.id ..  ' cat #:' .. d.category_num .. ' type:' .. d.device_type)     
   devcnt = devcnt + 1
    end
end
if numopen == 0 then   --If there are no sensors tripped, log and announce!
   luup.log('There were ' .. devcnt .. ' door and window sensors found and all are closed')
   luup.call_action("urn:micasaverde-com:serviceId:Sonos1", "Say", {Text=devcnt .. " sensors were checked, and all are closed. House is secure. ", Language="en", Volume=vol}, son)
   
else   --If there are any sensors tripped, log and announce!
   if numopen > 1 then
      isare = "are"
   end
      luup.log('There were ' .. devcnt .. ' door and window sensors found and ' .. numopen .. " " .. isare .. ' open' .. opensensors)
      luup.call_action("urn:micasaverde-com:serviceId:Sonos1", "Say", {Text="Warning! House may not be secure," .. devcnt .. " sensors were checked and " .. numopen .. " " .. isare .. " open. Check," .. opensensors, Language="en", GroupDevices="Basement, Kitchen", Volume=vol}, son)
     
end


I have setup the sonos  api by jishi to use amazon poly for a tts engine, the voice implementation is very very good, does anyone know how i would this tts engine in the above code.  The execution line is http://192.168.10.112:5005/sayall/this is the spoken text

Thanks in advance
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: MNB on April 03, 2017, 01:02:20 pm
@kiethr, did you per chance have any success in getting your LUA snippit to work, and if so would you be so kind and share your solution? Mike


Well i changed that line and the code did not fail.  However i'm not home so I will have to wait until later to see if it is working.

Thanks for the tip!!!
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: MNB on April 03, 2017, 08:17:07 pm
@keithr, after taking your updated of @becky's code, I did a few modifications to finally getting the LUA snippit to work on my VERA - Edge. I'm hoping that @becky was able to get the Weather Alarm(s) to also work. Does anyone know of a way to get the calendar event to also have the start times announced?

Code: [Select]
-- Morning Announcement (Becky) modified by Michael Blackwell. To let the family know what's going on for the day before we get out of bed. It includes, current time, current weather condition, current temperature and any calendar events for the day from google calendar via GCal3 plugin plugin
local AV_DEV = 15 -- Sonos Device ID within Vera
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local LS_ZONES = "Kitchen,Living Room,Patio Room" -- Valid GroupZones = "All", "Kitchen", "Patio Room", "Living Room", "Master Bedroom", "Lily's Cabin" Note: if you are grouping more than one zone, ensure that there are no spaces between the deliminating comma.
local LS_VOLUME = 70
local time = os.date('%I:%M')
local todaydate = os.date('%Y-%m-%d')
local WEATHER_ID = 5 -- World Weather Device ID
local WEATHER_ID2 = 6 -- World Weather Child Device ID
local WEATHER_SID = "urn:upnp-micasaverde-com:serviceId:Weather1"
local TEMP_SID = "urn:upnp-org:serviceId:TemperatureSensor1"

local WeatherCurrCondition = luup.variable_get(WEATHER_SID, "Condition", WEATHER_ID)
local WeatherCurrTemp      = luup.variable_get(TEMP_SID, "CurrentTemperature", WEATHER_ID2)

local GS_SID = "urn:srs-com:serviceId:GCalIII"
local jsonEvents = luup.variable_get(GS_SID, "gc_jsonEvents", 243) --GCal3 Sensor Device ID

-- checking to see if there are any events for the day. if not, tell us that there are no events for today.
if ((jsonEvents == "[]") or (jsonEvents == nil)) then
  TodaysEvents="There are no Calendar events scheduled for today. "
else
 TodaysEvents="  The Calendar Events for Today are as follows;   "
end

-- unwrapping all the different variables in the device variable.
local json = require("dkjson") -- depending on your vera version like Edge or Plus, you may need to use require("json")
  local eventList =json.decode(jsonEvents)
  package.loaded.json = nil
local numberEvents = table.getn(eventList)
local startevent, startDate, startTime, endevent, endTime, eventname, event

-- looping around the dumping the variables into an array
for i = 1,numberEvents do
  startevent = eventList[ i ].eventStart
  startDate = os.date("%Y-%m-%d", startevent)
  startTime = os.date("%H:%M:%S", startevent)
  endevent = eventList[ i ].eventEnd
  endTime = os.date("%H:%M:%S", endevent)
  eventname = eventList[ i ].eventName

-- if the event happens today, add it to the TodaysEvents variable. if not, don't add it.
  if (i == 1) then
   TodaysEvents = TodaysEvents .. eventname ..  " .       "
   else
   TodaysEvents = TodaysEvents .. " then " .. eventname ..  " .       "
  end
  luup.log(event)
end
package.loaded.json = nil

-- Establishing proper greeting depending on the time of day
local time2 = os.date('It is  %H:%M.')
local hour=tonumber(os.date('%H'))
local greeting=""

if  hour < 12  then
  greeting = "Good morning"
  elseif hour < 17 then
  greeting = "Good afternoon"
  elseif hour < 21 then
  greeting = "Good evening"
  else
  greeting = "Good evening"
end

-- and then of course sending it all to the sonos device to make the announcement.
luup.call_action(LS_SID, "Say", {Text = string.format("%s    Blackwell family!  The time is.   %s  Here is your daily report. Today's weather will be   %s   with a high of    %s  degrees    %s     Have a great day.", greeting, time, WeatherCurrCondition, WeatherCurrTemp, TodaysEvents), GroupZones=LS_ZONES, SameVolumeForAll="true", Volume=LS_VOLUME}, AV_DEV)

Made correction in the Say statement had some flaws..
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: MNB on April 05, 2017, 11:21:48 am
I've noticed that this thread seems to be a little quite aka not much new content (e.g. new techniques, solutions and code) has been added of late, is this due to everything has been previously addressed or are people moving to something other devices? Mike
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: michelhamelin on October 06, 2017, 10:21:54 pm
Do You know how to Say also the Room where is the sensor?

Door & Window Sensor Check and Annunciation
Ok, so it took more than "a few hours" but here it is!!! This script checks for all connected door/window sensors, announces how many there are and if any are open (tripped,) it tells you which ones. I need to do more tinkering with the speech strings to make them smoother and maybe a bit slower. I plan to have two scenes, one for upstairs sonos and one for downstairs. The variables should be self explanatory. Feel free to reply with questions, comments, improvements, etc.

-- Door/Window sensor check and speech annotation by Pasqual Zottola
local vol = 50
local son = 27 --mast bdr =33, kitch=27
local devcnt = 0
local devno = 0
local numopen = 0
local isare = "is"
local opensensors = " "
luup.log('Commencing sensor device search loop')
for deviceNo,d in pairs(luup.devices) do
   if d.category_num == 4 then
           
      local tripped = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", deviceNo) or "Nil"
     
      if (tripped == "1") then
         opensensors = opensensors .. ". " .. d.description
         --[[ This line will change to recording info to an array so sonos speaks only once.
luup.call_action("urn:micasaverde-com:serviceId:Sonos1", "Say",
     {Text=d.description .. " is Open", Language="en", Volume=vol}, son)
         --]]     
         -- luup.log(d.description .. " status was " .. tripped)
         numopen = numopen + 1
      end
   luup.log(d.description .. ' status:' .. tripped .. ' Dev #' .. deviceNo .. ' id:' .. d.id ..  ' cat #:' .. d.category_num .. ' type:' .. d.device_type)     
   devcnt = devcnt + 1
    end
end
if numopen == 0 then   --If there are no sensors tripped, log and announce!
   luup.log('There were ' .. devcnt .. ' door and window sensors found and all are closed')
   luup.call_action("urn:micasaverde-com:serviceId:Sonos1", "Say", {Text="There were " .. devcnt .. " door and window sensors found, and all are closed", Language="en", Volume=vol}, son)
   
else   --If there are any sensors tripped, log and announce!
   if numopen > 1 then
      isare = "are"
   end
      luup.log('There were ' .. devcnt .. ' door and window sensors found and ' .. numopen .. " " .. isare .. ' open' .. opensensors)
      luup.call_action("urn:micasaverde-com:serviceId:Sonos1", "Say", {Text="There were " .. devcnt .. " sensors found and " .. numopen .. " " .. isare .. " open." .. opensensors, Language="en", Volume=vol}, son)
     
end
Title: Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
Post by: anthonyris on June 26, 2018, 11:23:58 pm
A simple lua script to have Vera announce over Sonos the time, temperature, weather conditions and today?s forecast using DarkSky weather app data. Bummer that WeatherUnderground now requires payment for API key.  :-*

DarkSky is a good choice (install via AltUI App Store), with a ton of weather-related variables to pull in. Code snippet attached (yes, it?s a bit sloppy, but functional, would love suggestions/critiques!).

Just replace IDs with your own devices, find a chime/bell sound file you like (optional!) and upload it to /www and then drop the script into a scheduled scene that runs every morning. Easy peasy.

BTW, don?t need second weather device ID, I was just testing if you could pull in data from multiple devices in one script without blowing anything up...

Enjoy,
.//A.

Code: [Select]
local AV_DEV = XX -- Sonos device ID
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local LS_DURATION = 5 ? length of chime sound
local LS_VOLUME = 35
local LS_PATH = "http://<localVeraIPaddress>/ZenTempleBell.mp3" -- Chime sound file in /www
local time = os.date('%M minutes past %I:')
local name = "Princess Cupcake" ? How you want to be greeted
local WeatherID1 = XX -- Weather app ID ? your DarkSky main device ID
local WeatherID2 = XX -- Weather app ID2 ? your DarkSky Temperature device ID, optional

local WEATHER_SID = "urn:upnp-org:serviceId:TemperatureSensor1"
local WEATHER_CID = "urn:upnp-micasaverde-com:serviceId:Weather1"

    local Today = luup.variable_get(WEATHER_CID, "TodayConditions", WeatherID1)
    local Current = luup.variable_get(WEATHER_CID, "CurrentConditions", WeatherID1)
    local HighTemp = luup.variable_get(WEATHER_CID, "TodayHighTemp", WeatherID1)
    local Precip = luup.variable_get(WEATHER_CID, "PrecipProbability", WeatherID1)
    local Temp = luup.variable_get(WEATHER_SID, "CurrentTemperature", WeatherID2)

luup.call_action (LS_SID, "Alert", {URI=LS_PATH , Duration=LS_DURATION , Volume=LS_VOLUME, GroupZones="ALL"}, AV_DEV)

luup.call_action(LS_SID, "Say", {Text = string.format("Good morning %s. You are amazing... The time is currently %s o'clock.   Right now, the weather is %s and the temperature is %s degrees. Today will be %s with a high of %s and a %s percent chance of precipitation... I hope you have a peaceful day.", name,time,Current,Temp,Today,HighTemp,Precip),GroupZones="ALL", SameVolumeForAll="true", Volume=LS_VOLUME}, AV_DEV)

luup.call_action (LS_SID, "Alert", {URI=LS_PATH , Duration=LS_DURATION , Volume=LS_VOLUME, GroupZones="ALL"}, AV_DEV)