We have moved at community.getvera.com

Author Topic: Text To Speech (TTS) With Sonos - Creating Dynamic Messages  (Read 89507 times)

Offline sharadmenawat

  • Sr. Newbie
  • *
  • Posts: 21
  • Karma: +0/-0
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #120 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.

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

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #121 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 for examples of how to program delays.

Offline sharadmenawat

  • Sr. Newbie
  • *
  • Posts: 21
  • Karma: +0/-0
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #122 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.

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

Offline lolodomo

  • Moderator
  • Master Member
  • *****
  • Posts: 3484
  • Karma: +74/-10
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #123 on: September 25, 2014, 07:16:12 pm »
Use ALL as value for GroupZones parameter.

Offline sharadmenawat

  • Sr. Newbie
  • *
  • Posts: 21
  • Karma: +0/-0
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #124 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

Offline lolodomo

  • Moderator
  • Master Member
  • *****
  • Posts: 3484
  • Karma: +74/-10
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #125 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.

Offline SteveZ

  • Sr. Member
  • ****
  • Posts: 328
  • Karma: +4/-1
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #126 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)

Offline tb001

  • Sr. Member
  • ****
  • Posts: 394
  • Karma: +5/-2
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #127 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!

« Last Edit: November 02, 2014, 01:52:49 pm by tb001 »

Offline SteveZ

  • Sr. Member
  • ****
  • Posts: 328
  • Karma: +4/-1
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #128 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

Offline tb001

  • Sr. Member
  • ****
  • Posts: 394
  • Karma: +5/-2
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #129 on: November 02, 2014, 03:06:33 pm »
Thank you! I had switched the sonos dvc id, but missed the others. Rookie mistake...

Offline Pseudomizer

  • Sr. Member
  • ****
  • Posts: 376
  • Karma: +8/-1
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #130 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.
« Last Edit: November 25, 2014, 12:08:53 am by Pseudomizer »
Vera 3, RFWC5AW, 2 x LFM-20, FS20Z, 3 x YRD220ZW619KWKD, 2 x FI9826W, FI9828P, 2 x NEST Gen2, EVL-3CG, 11 x BR30, 3 x A19 Hue, Media Srv, 18 x ZW4004, 8 x ZW3003, 12 x ZW2002, IP2IR Cache, 2 x DSC24, ZWN-SC7, 4 x PIR-ZWAVE2, DSB05-ZWUS, RS100-HC, ECO-TILT-US, Ribu1C, 3 x GE12721, 2 x Echo, ZW078-A

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #131 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.

Offline charlesrg

  • Jr. Member
  • **
  • Posts: 57
  • Karma: +1/-1
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #132 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.

Offline Piwtorak

  • Hero Member
  • *****
  • Posts: 988
  • Karma: +4/-0
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #133 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 !!
Vera3 (1), Airport Extreme (2), Apple TV (3), Sqblaster (1), GE Switch (3), GE Dimmer (1), Leviton VRCSZ2 (2), GE 45601 (1), Intermatic HA03 (2), GE Zwave Outlet (1), Remote Control Curtain (1) and growing.

Offline parkerc

  • Beta Testers
  • Sr. Hero Member
  • *****
  • Posts: 2479
  • Karma: +35/-48
  • Life Moves Pretty Fast....
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #134 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