I am trying to script announcements through my sonos system when alarm is armed. Let’s say the exit delay is 45 seconds. I would like an announcement to be made when alarm is armed, then after 20 seconds, and then count last 5 seconds. What’s the best way to do this? I tried to use sleep function which takes parameter in milliseconds, but it doesn’t seem to work. I have this in my luup code which doesn’t work:
[tt]local AV_DEV = 5
local LS_SID = “urn:micasaverde-com:serviceId:Sonos1”
– When alarm is armed, announce that 45 seconds remaining to exit
luup.call_action(LS_SID, “Say”, {Text = string.format(“Security system has been activated… You have 45 seconds to exit… Have a nice day!”), Volume=25, GroupZones=“Office”}, AV_DEV)
– After 20 seconds, remind that 25 seconds are remaining
luup.sleep(20000)
luup.call_action(LS_SID, “Say”, {Text = string.format(“You have 25 seconds remaining to exit.”), Volume=25, GroupZones=“Office”}, AV_DEV)
– After 20 seconds, remind that 5 seconds are remaining
luup.sleep(20000)
luup.call_action(LS_SID, “Say”, {Text = string.format(“You now have 5 seconds remaining to exit.”), Volume=25, GroupZones=“Office”}, AV_DEV)
– Count last 5 seconds
luup.call_action(LS_SID, “Say”, {Text = string.format(“Five… Four… Three… Two… One… Alarm is now active.”), Volume=25, GroupZones=“Office”}, AV_DEV)[/tt]
Any help on how to make this work?
Thanks.
OK, so I just read that luup.sleep may not be the best way to do it since another event may be missed while luup “sleeps” and recommendation was to use the delay instead. So I tried that, doesn’t work either… please help! This is new code which doesn’t work unfortunately:
[tt]local AV_DEV = 5
local LS_SID = “urn:micasaverde-com:serviceId:Sonos1”
– When alarm is armed, announce that 45 seconds remaining to exit
luup.call_action(LS_SID, “Say”, {Text = string.format(“Security system has been activated… You have 45 seconds to exit… Have a nice day!”), Volume=25, GroupZones=“Office”}, AV_DEV)
– After 20 seconds remind that 25 seconds remaining
luup.call_delay(“First_Call”,20)
function First_Call()
luup.call_action(LS_SID, “Say”, {Text = string.format(“You have 25 seconds remaining to exit.”), Volume=25, GroupZones=“Office”}, AV_DEV)
end
– After 20 seconds reming that 5 seconds remaining
luup.call_delay(“Second_Call”,20)
function Second_Call()
luup.call_action(LS_SID, “Say”, {Text = string.format(“You now have 5 seconds remaining to exit.”), Volume=25, GroupZones=“Office”}, AV_DEV))
end
– Now count last 5 seconds
luup.call_action(LS_SID, “Say”, {Text = string.format(“Five… Four… Three… Two… One… Alarm is now active.”), Volume=25, GroupZones=“Office”}, AV_DEV)[/tt]
If the total amount of time spent in sleep is more than a few seconds, if it’s in a loop you need to add all the time for each loop, Vera will restart!
While sleeping using luup.sleep , NOTHING ELSE in Vera is running.
You need to break things up into little fragments of code that run quickly, and then schedule the next fragment of code using luup.call_delay.
In this case you need to create a function and schedule it:
AV_DEV = 5
LS_SID = "urn:micasaverde-com:serviceId:Sonos1"
-- When alarm is armed, announce that 45 seconds remaining to exit
luup.call_action(LS_SID, "Say", {Text = string.format("Security system has been activated... You have 45 seconds to exit... Have a nice day!"), Volume=25, GroupZones="Office"}, AV_DEV)
luup.call_delay("WakeupLater1", 20, 0)
function WakeupLater1()
luup.call_action(LS_SID, "Say", {Text = string.format("You have 25 seconds remaining to exit."), Volume=25, GroupZones="Office"}, AV_DEV)
luup.call_delay("WakeupLater2", 20, 0)
end
function WakeupLater2()
luup.call_action(LS_SID, "Say", {Text = string.format("You now have 5 seconds remaining to exit."), Volume=25, GroupZones="Office"}, AV_DEV)
luup.call_action(LS_SID, "Say", {Text = string.format("Five... Four... Three... Two... One... Alarm is now active."), Volume=25, GroupZones="Office"}, AV_DEV)
end
NOTE: It was important to remove the LOCAL from the variable definitions.
THANK YOU!! It works. Just need to figure out how to insert pause in Google TTS so it sounds a bit more natural. One question though - you said it was important to remove “local” from my variables declarations. I thought that making them local restricts the scope of the variables to the current scene. I am guessing I needed to remove the local to make them available to the functions in the scene as well? Now that they are not local, are the variables removed (i.e. memory is released) after the scene is done?
Thanks