Getting Scene working with Sonos

I have the following code that use to work last year. With the bumps and hiccups along the way with Sonos not working. I have since installed the Sonos update from @rigpapa. Sonos does play but this command does not seem to work anymore.

I have this command execute when the front door is opened.

Are there new parameters to use as I have 3 sonos speakers.

This is my code:

luup.call_action(“urn:micasaverde-com:serviceId:Sonos1”, “Say”,
{Text=“The front door is open”, Language=“en”, GroupZones=“ALL”,
Volume=40, SameVolumeForAll=“true”},
9)

What TTS Engine are you using? If it’s RV, you can’t use “en” as the language. Try “en-US” or “en-GB”.

I am using RV.

I changed from “en” to “en-US” and this seems to be working.
I will do some more tests.

thank you @rigpapa

1 Like

@rigpapa -

I wonder if you could assist in why this weather code, does not work either. It has been a while since it stopped working.

Blockquote

local AV_DEV = 39
local LS_SID = “urn:micasaverde-com:serviceId:Sonos1”
local time = os.date(‘%I: %M’)
local TEMP_SID =“urn:upnp-org:serviceId:TemperatureSensor1”
local WUGTempHigh = luup.variable_get(TEMP_SID, “CurrentTemperature”, 15)
local currentCondition = luup.variable_get(“urn:upnp-micasaverde-com:serviceId:Weather1”, “Forecast.1.Condition”, 12)

luup.call_action(“urn:micasaverde-com:serviceId:Sonos1”, “PlayURI”, {URIToPlay=“SQ:InfoChime.wav”, Volume=50, Duration=20}, AV_DEV)
luup.call_action(LS_SID, “Say”, {Text = string.format(“Good morning, Family! It is now %s. Today will be %s with a high of %s degrees”, time,
currentCondition, WUGTempHigh) ,Volume=50}, AV_DEV)

Blockquote

“does not work” meaning what, exactly?

By the way, to format a code block, use three back-ticks ``` on a line by itself both before and after the end of the block.

local AV_DEV = 39
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local time = os.date('%I: %M')
local TEMP_SID ="urn:upnp-org:serviceId:TemperatureSensor1"
local WUGTempHigh = luup.variable_get(TEMP_SID, "CurrentTemperature", 15)
local currentCondition = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1", "Forecast.1.Condition", 12)

luup.call_action("urn:micasaverde-com:serviceId:Sonos1", "PlayURI", {URIToPlay="SQ:InfoChime.wav", Volume=50, Duration=20}, AV_DEV)
luup.call_action(LS_SID, "Say", {Text = string.format("Good morning, Family! It is now %s. Today will be %s with a high of %s degrees", time, currentCondition, WUGTempHigh) ,Volume=50}, AV_DEV)

sorry about the format.
The temperature is not announced on Sonos. What happens it the radio station that I was previously listening too an hour ago is now being played.

The SQ designation on the URL plays a queue, not a file. If the named queue can’t be found, who knows what it will do. Do you happen to have a queue (not just a file, but a queue) named exactly “InfoChime.wav”? If so, can you play it from the app?

On the Say action, you don’t have a language spec, so make sure you’re default language is also set correctly. You were passing language on the previous question, so it would work once corrected, but if the default is similarly incorrect, that would make it not speak here.

@rigpapa - So I eventually was able to get the Sonos working to announce the weather temp for the High and Low. I had to clean up the code.

I have an issue where I am trying to have it mention Tomorrow’s High and I was using a 3rd variable. I get no announcement and wondering if I am missing something.

when I remove the 3rd variable reference, sonos announces the high and low.

My Sonos Device ID is # 39 and the Darksky Weather Device ID # is 410

url = require("socket.url")

local AV_DEV = 39
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local TEMP_SID ="urn:upnp-micasaverde-com:serviceId:Weather1"
local OwTempTodayHigh= luup.variable_get(TEMP_SID, "TodayHighTemp", 410)
local OwTempTodayLow= luup.variable_get(TEMP_SID, "TodayLowTemp", 410)
local currentCondition= luup.variable_get(TEMP_SID, "TodayConditions", 410)
local OwTempTomorrowHigh= luup.variable_get(TEMP_SID, "TomorrowHighTemp", 410)
local OwTempTomorrowLow= luup.variable_get(TEMP_SID, "TomorrowLowTemp", 410)
local tomorrowCondition = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1", 
"TomorrowConditions", 410)

luup.call_action(LS_SID, "Say", {Text = string.format("Good morning, Family! Todays high will be %s degrees and the low will be %s degrees and Tomorrow's High will be %s degrees ", OwTempTodayHigh,OwTempTodayLow,OwTempTomorrowHigh) ,Volume=35}, AV_DEV)

The code you’ve posted has three variables, so I’m not sure if you’re saying what you posted is working or not working.

But the gist is, for your string.format() call to work and not throw an error that stops the Say action from even being attempted, the number of %s placeholders has to be equal to the number of arguments that follow the format string. All the values (variables) also have to not be nil.

When writing Lua code, you really need to be looking at the LuaUPnP log file to see if you are generating any errors, or if you are getting through to the action. Are you familiar with that file/know how to get to it?

That is the million $ question. How can I view logs to give me an idea of what is going on?

http://your-vera-local-ip/cgi-bin/cmh/log.sh?Device=LuaUPnP

The log display may not display the last thing that happened–the log has a buffer that has to be flushed, so to get it flushed, you may have to repeat your action a couple of times. Look for errors at the bottom of the output.

Ok So I reviewed the logs and I do see this message “luup_log:39: Sonos: warning: RV TTS: failed!”
I have gone into sonos and used the TTS text and that works. This only fails when I request 2 variables to be announced when I add a 3rd option, it seems to fail.

Any ideas on how to get RV TTS to work consistently?

local AV_DEV = 39
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local TEMP_SID ="urn:upnp-micasaverde-com:serviceId:Weather1"
local OwTempTodayHigh= luup.variable_get(TEMP_SID, "TodayHighTemp", 410) or "no high temp"
local OwTempTodayLow= luup.variable_get(TEMP_SID, "TodayLowTemp", 410) or "no low temp"
local OwWindSpeedToday= luup.variable_get(TEMP_SID, "TodayWindSpeed", 410) or "no wind speed"  




luup.call_action(LS_SID, "Say", {Text = string.format("Good morning! Todays high will be %s degrees and the low will be %s degrees and the WindSpeed is %s  ", OwTempTodayHigh,OwTempTodayLow,OwWindSpeedToday) ,Volume=35}, AV_DEV)
 <0x7010c520>
27	12/19/19 8:55:13.876	JobHandler_LuaUPnP::HandleActionRequest testing zigbee urn:micasaverde-com:serviceId:HomeAutomationGateway1, urn:micasaverde-com:serviceId:ZigbeeNetwork1, 0x1bbf778 <0x7010c520>
28	12/19/19 8:55:13.876	JobHandler_LuaUPnP::HandleActionRequest testing Bluetooth urn:micasaverde-com:serviceId:HomeAutomationGateway1, urn:micasaverde-com:serviceId:BluetoothNetwork1, 0x1bc4008 <0x7010c520>
20	12/19/19 8:55:13.876	LuaInterface::StartEngine 0x22f2f10 device 0 <0x7010c520>
10	12/19/19 8:55:13.877	sbrk JobHandler_LuaUPnP::HandleActionRequest Problem with getnameinfo <0x7010c520>
08	12/19/19 8:55:13.878	JobHandler_LuaUPnP::HandleActionRequest device: 39 service: urn:micasaverde-com:serviceId:Sonos1 action: Say <0x7010c520>
08	12/19/19 8:55:13.878	JobHandler_LuaUPnP::HandleActionRequest argument Volume=35 <0x7010c520>
08	12/19/19 8:55:13.878	JobHandler_LuaUPnP::HandleActionRequest argument Text=Good morning! Todays high will be -7.3 degrees and the low will be -12.5 degrees and the WindSpeed is 8.1   <0x7010c520>
35	12/19/19 8:55:13.878	JobHandler_LuaUPnP::ConfirmGlobalActionRules start <0x7010c520>
31	12/19/19 8:55:14.100	AlarmManager::Run 0x1df9200 notified of a change entry 0x18c77e8 id 318 deleted 0 <0x75216520>
31	12/19/19 8:55:14.101	AlarmManager::Run callback for alarm 0x1df9200 entry 0x18c77e8 type 7 id 318 param=0x27f28f8 entry->when: 1576763714 time: 1576763714 tnum: 0 slow 1 tardy 0 <0x75216520>
35	12/19/19 8:55:14.101	LuaInterface::CallFunction_Timer func:PeriodicTS device:106 <0x75216520>
10	12/19/19 8:55:14.102	AlarmManager::AddRelativeAlarm current time 1576763714 delay 1 type 7 <0x75216520>
10	12/19/19 8:55:14.102	AlarmManager::AddAbsoluteAlarm alarm 0x1df9200 entry 0x300efa8 id 319 type 7 param=0x1502ff0 entry->when: 1576763715 time: 1576763714 bCancelFirst 0=0 <0x75216520>
31	12/19/19 8:55:14.103	AlarmManager::Run finish callback for alarm 0x1df9200 entry 0x18c77e8 type 7 id 318 param=0x27f28f8 entry->when: 1576763714 time: 1576763714 tnum: 0 slow 1 duration 0 <0x75216520>
02	12/19/19 8:55:14.971	luup_log:39: Sonos: warning: RV TTS: failed! <0x7010c520>
35	12/19/19 8:55:14.994	ImplAction::HandleActionRequest SSonos1_Sonos1_Say_run returned 0 <0x7010c520>
35	12/19/19 8:55:14.994	JobHandler_LuaUPnP::GlobalPostProcessingRules start <0x7010c520>
35	12/19/19 8:55:14.995	JobHandler_LuaUPnP::GlobalPostProcessingRules start <0x7010c520>
10	12/19/19 8:55:14.996	luvd_get_info_data_request creating file buffer /data_request pMem 0x33e2000/54403072 diff: 37634048 <0x7010c520>
10	12/19/19 8:55:14.996	luvd_get_info_data_request done /data_request ret 0 size 140 pMem 0x33e2000/54403072 diff: 37634048 took 0 info (nil) <0x7010c520>
10	12/19/19 8:55:14.997	mg_callback /data_request stop id: 120 <0x7010c520>

Try shortening your text. I’ll bet you’re hitting a string length limit at ResponsiveVoice.

@rigpapa - You are a genius :grinning:
You were bang on, that was the issue.

So can i call the luup call action multiple times in my logic to add 4 or 5 things I want it to say ? ( luup.call_action(LS_SID, “Say”, )

I figured out I can break out my Luua call action for “Say” to get my info announced on Sonos.

Thank you so much @rigpapa

You might get it to work with a single string. Your format string has some whitespace at the end, and as it happens, the string is about the exact length of the limit for RV, so the engine is cutting it into two, with the second part containing only whitespace, which causes an error.

Try using the long string, but remove all whitespace from the end of it. Make it tight to the inside of the quotes.