We have moved at community.getvera.com

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

Offline Borat

  • Full Member
  • ***
  • Posts: 169
  • Karma: +4/-5
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #105 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!

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 #106 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.
« Last Edit: August 06, 2014, 08:18:25 pm by parkerc »

Offline Borat

  • Full Member
  • ***
  • Posts: 169
  • Karma: +4/-5
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #107 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

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 #108 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

Offline Borat

  • Full Member
  • ***
  • Posts: 169
  • Karma: +4/-5
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #109 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

Offline sharadmenawat

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

Offline RexBeckett

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

Offline sharadmenawat

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

Offline RexBeckett

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


Offline sharadmenawat

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

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 #115 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,

Offline sharadmenawat

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


Offline RexBeckett

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

Offline sharadmenawat

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

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: Text To Speech (TTS) With Sonos - Creating Dynamic Messages
« Reply #119 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.
« Last Edit: September 20, 2014, 06:37:04 pm by RexBeckett »