Text To Speech (TTS) With Sonos - Creating Dynamic Messages

[quote=“RexBeckett, post:120, topic:173177”]

Yes this made the Sonos speak up :wink: 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.[/quote]

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

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

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.

[quote=“sharadmenawat, post:121, topic:173177”][quote=“RexBeckett, post:120, topic:173177”]

Yes this made the Sonos speak up :wink: 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.[/quote]

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

Sharad[/quote]

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

Sharad

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

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[/quote]

Normally impossible with Sonos system. In my case, groups are always in sync … but I only own 2 Sonos in my home.

[quote=“haavard, post:67, topic:173177”]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]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)

[/code]

Thanks for your help![/quote]

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

[code]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)[/code]

[quote=“SteveZ, post:127, topic:173177”][quote=“haavard, post:67, topic:173177”]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]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)

[/code]

Thanks for your help![/quote]

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

[code]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)[/code][/quote]

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!

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

Thank you! I had switched the sonos dvc id, but missed the others. Rookie mistake…

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:

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.

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.

If you guys are interested, here is my scene some may want as example:

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.

Very good Charlesrg…

if I need change the “morning” for “afternoon” when necessary…do you have some code for this ?
thanks !!

[quote=“Piwtorak, post:134, topic:173177”]if I need change the “morning” for “afternoon” when necessary…do you have some code for this ?
thanks !![/quote]

Hi @piwtorak

Have a look at this earlier post, maybe this will help… → http://forum.micasaverde.com/index.php/topic,12408.msg92210.html#msg92210

[quote=“Piwtorak, post:134, topic:173177”]Very good Charlesrg…

if I need change the “morning” for “afternoon” when necessary…do you have some code for this ?
thanks !![/quote]

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

[code]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[/code]

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…

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]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[/code]

Please Look if your plugin (source of information) is the same I have installed…

thanks

I’m using wundeground weather plugin for weather info and I’m on UI7.