My first scene with LUUP code works, but...

All,
I just installed the Sonos plugin today on my Vera3 and despite my fears, it was simple and worked! Emboldened by this victory, I decided to try my hand at creating my first scene using LUUP code. I created a scene that checks if my garage door sensor is tripped at 9PM, 10PM, and 11PM and if it is tripped, it uses TTS to announce it. I used the Schedules tab of my scene to run at 9, 10 & 11PM and then I added the following code to the LUUP tab:

local tripped = luup.variable_get(“urn:micasaverde-com:serviceId:SecuritySensor1”, “Tripped”, 21)
if (tripped == “1”) then
luup.call_action(“urn:micasaverde-com:serviceId:Sonos1”, “Say”,
{Text=“A Window or Door Is Open”, Language=“en”, Volume=80}, 27)
end

So the amazing thing is that this worked on the first try!!! Now I’m excited to abandon the limited UI tabs and make the whole scene work in LUUP. Is there an easy way to replace the settings in the Schedules tab with LUUP code that will check the sensor at defined times of the day? I also intend to add all of my door and window sensors to this scene so that if any of them are open around bed time, I will be alerted. Would I copy all of the lines then paste them in for each window/door and changing the dID? What other code can I add into this scene to make it better, more efficient, cooler???
Thanks in advance for the help!!!
Pasqual

Is there an easy way to replace the settings in the Schedules tab with LUUP code that will check the sensor at defined times of the day?

This would require you to set-up timers in Startup Lua to call your scene. There really isn’t any advantage over using the built-in schedules which are much easier to change.

Would I copy all of the lines then paste them in for each window/door and changing the dID?

That would work. You will discover that, if you send multiple alerts to the Sonos, they can step on each other.

What other code can I add into this scene to make it better, more efficient, cooler???

I’m sure there are many possibilities but it depends on your definition of cooler. You could repeat the alert every few minutes with incrementally increased volume until you go and close the door. When the volume reaches certain levels, you could add phrases like are you going to do anything about it? or go and close it, you lazy … to the alert. ;D

Thanks for the response Rex. I’m happy to use the built-in schedules. somewhere along the way, I got the impression that they were not reliable, but I should know better as I have plenty of scenes that use them with no issues.

I was wondering about the potential issue of each if statement running at the same time and then having multiple say commends sent to the Sonos at the same time. I know I’ve read about a delay command, so I’ll research that and insert it into the end of each if statement to let them run separately. I could also just check if any sensor is tripped and then increment a local variable (such as IsTripped,) by one, then if that variable is greater than zero at the end, I can just have an announcement that says “A Window or door somewhere is open.” It’s not as nice, but gets the job done. I wonder if I can use variables within the text of the Say command so I can be informed about how many windows or doors are open???

I like your idea of increasing the urgency of the alert over time if the issue isn’t resolved.

You could always mix it up with some of the dynamic messages that have been put together for the Sonos

http://forum.micasaverde.com/index.php/topic,12408.msg90882.html#msg90882

I know I've read about a delay command...

See Delayed Actions for help with this.

I wonder if I can use variables within the text of the Say command so I can be informed about how many windows or doors are open???

You can build the string to be said with embedded variables by using concatenation,

local mins = 10 local textTosay = "The door has been open for " .. mins .. "minutes."

When sent tout th? samedi Sonos, th? alerte are queues… Each or jour alerte will je player one acter one.