We have moved at community.getvera.com

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

Offline Brientim

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

« Last Edit: March 15, 2015, 01:36:38 am by Brientim »

Offline Brientim

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

Offline tomgru

  • Hero Member
  • *****
  • Posts: 1403
  • Karma: +18/-6
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #182 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

Offline Brientim

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

Offline Brientim

  • Sr. Hero Member
  • ******
  • Posts: 2497
  • Karma: +78/-7
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #184 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"

Offline tomgru

  • Hero Member
  • *****
  • Posts: 1403
  • Karma: +18/-6
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #185 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.

Offline Brientim

  • Sr. Hero Member
  • ******
  • Posts: 2497
  • Karma: +78/-7
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #186 on: March 15, 2015, 11:48:26 pm »
The original weather would have been at the last volume the Sonos was at.

Offline tomgru

  • Hero Member
  • *****
  • Posts: 1403
  • Karma: +18/-6
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #187 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!

Offline dp0100

  • Sr. Newbie
  • *
  • Posts: 30
  • Karma: +2/-2
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #188 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
« Last Edit: April 24, 2015, 01:41:44 pm by dp0100 »

Offline JS007

  • Sr. Member
  • ****
  • Posts: 319
  • Karma: +1/-3
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #189 on: May 05, 2015, 04:57:19 pm »
wow, nice plugin, just got the sonos 1 and tts works nice

Offline dp0100

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

Offline MNB

  • Hero Member
  • *****
  • Posts: 689
  • Karma: +4/-9
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #191 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
Edge-1.7.2607, VRI06-1LX Dimr (6), VS05-1LX Sw (4), GE ZW3002 Dimr (1), HA01C Outlet (12), HA02C Sw (6), HA04C Sw (4), GE Sw (2), HA05 Sw (3), MiniMote Contr (5), HSM200/100 Sensor (2), ZW100A Sensor (8), Nest thermostat (1) & Protect Fire/CO (6) Kwikset Locks (3), F18918W (1) & IP3M-9 (6) Cam's

Offline MNB

  • Hero Member
  • *****
  • Posts: 689
  • Karma: +4/-9
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #192 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
Edge-1.7.2607, VRI06-1LX Dimr (6), VS05-1LX Sw (4), GE ZW3002 Dimr (1), HA01C Outlet (12), HA02C Sw (6), HA04C Sw (4), GE Sw (2), HA05 Sw (3), MiniMote Contr (5), HSM200/100 Sensor (2), ZW100A Sensor (8), Nest thermostat (1) & Protect Fire/CO (6) Kwikset Locks (3), F18918W (1) & IP3M-9 (6) Cam's

Offline dp0100

  • Sr. Newbie
  • *
  • Posts: 30
  • Karma: +2/-2
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #193 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
« Last Edit: June 22, 2015, 02:38:24 pm by dp0100 »

Offline MNB

  • Hero Member
  • *****
  • Posts: 689
  • Karma: +4/-9
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #194 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
Edge-1.7.2607, VRI06-1LX Dimr (6), VS05-1LX Sw (4), GE ZW3002 Dimr (1), HA01C Outlet (12), HA02C Sw (6), HA04C Sw (4), GE Sw (2), HA05 Sw (3), MiniMote Contr (5), HSM200/100 Sensor (2), ZW100A Sensor (8), Nest thermostat (1) & Protect Fire/CO (6) Kwikset Locks (3), F18918W (1) & IP3M-9 (6) Cam's