I’m trying to create a scene where Sonos says something when triggered by a motion sensor or fire alarm. I’ve successfully tested TTS manually via TTS menu:
But if I create a scene with TTS I only get the error “Scene run failed”:
Anyway I’m using ResponsiveVoice instead of Google and direct TTS is working fine. Is it possible in general to use TTS in a scene or do I have to use a LUA script? Anything else I could try to make it work in a scene?
I use lua to send TTS to sonos here is an example for my morning weather announcement:
url = require("socket.url")
local AV_DEV = 219
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
local time = os.date('%I: %M')
local TEMP_SID ="urn:upnp-micasaverde-com:serviceId:Weather1"
local OwTempTodayHigh= luup.variable_get(TEMP_SID, "TodayHighTemp", 548)
local OwTempTodayLow= luup.variable_get(TEMP_SID, "TodayLowTemp", 548)
local currentCondition= luup.variable_get(TEMP_SID, "TodayConditions", 548)
local OwTempTomorrowHigh= luup.variable_get(TEMP_SID, "TomorrowHighTemp", 548)
local OwTempTomorrowLow= luup.variable_get(TEMP_SID, "TomorrowLowTemp", 548)
local tomorrowCondition = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1",
"TomorrowConditions", 548)
luup.call_action(LS_SID, "Say", {Text = string.format("God morgon! Idag blir det %s med en högsta
temperatur på %s grader och en lägsta temperatur på %s grader. I morgon blir det %s med en
högsta temperatur på %s grader och en lägsta temperatur på %s", currentCondition,
OwTempTodayHigh, OwTempTodayLow, tomorrowCondition, OwTempTomorrowHigh,
OwTempTomorrowLow) ,Volume=35}, AV_DEV)
I believe the value for Engine in your scene action should be “RV” not “ResponsiveVoice”. The latter is what shows on the menu in the plugin (the human-readable text for the option), but the key value that the UI sends to the action is actually different.
There are a number of ways to do it, but you could add the following Lua to a scene that is triggered by the smoke detector tripping:
-- Insert this as your scene Lua, triggered by the smoke detector tripping
-- (whether armed or disarmed--you always want to know).
-- Be sure to set the device numbers correctly below. Modify the TTS text
-- and language as needed.
local SonosDeviceNum = 123
local SensorDeviceNum = 456
local warningInterval = 15 -- seconds between warnings
function warnSmoke()
-- Since this function is called in a time-delay loop, we have to make sure
-- we check the sensor state each time or it will never stop talking.
local status = luup.variable_get( "urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", SensorDeviceNum ) or "0"
if status == "0" then
luup.log("The smoke has cleared; stopping warnings.")
return
end
-- Give TTS warning on Sonos.
luup.call_action( "urn:micasaverde-com:serviceId:Sonos1", "Say",
{ Text="Achtung! Feuer in der Badewanne! Wieso?", Language="de", Engine="RV", Volume=50 },
SonosDeviceNum )
-- Delay and call this function again.
luup.call_delay( "warnSmoke", warningInterval, "" )
end
-- Since we are triggered by the detector, start off with the first warning.
luup.log("Smoke detector TTS warning loop starting.")
warnSmoke()
return true
This code also writes start and stop messages to the Vera log, so you can see it running there.
Cool. Just be aware that if you run the scene directly (with the “play” button on the scene list), it likely will not speak. That’s because it checks the sensor status before speaking, so it knows when to stop speaking, so if you just run the scene and the sensor is not tripped, nothing will happen.