Simple Alarm - Additional Features - Issues sounding indoor siren on arm/disarm

Hi everyone,

I’m new to all this so be gentle :wink:

I purchased an Edge about 3 weeks ago now, and my initial task was to keep the wife happy and create an alarm system. So i thought i’d try the Simple Alarm plugin. Whilst it works on the whole, there were some features i felt it would benefit from to make it more like a standard alarm and increase the WAF!

Such as:

[ul][li]Sound the indoor siren, On and Off with 1 second intervals for both state, whilst the countdown timer is running for both arming the alarm and entry detection through the front door[/li]
[li]Add code to run the “intrusion” function when the front door is opened, allowing ‘n’ seconds to disarm the alarm, before sounds all sirens and running the “panic” function[/li]
[li]Similar to above, however instead, if any other sensor (i.e. not the front door) is tripped, run the “panic” function immediately[/li][/ul]

As I have an Everspring indoor siren, the “beep, beep” option does not seem possible via a single signal to the device, i.e. it’s only capable of ON or OFF commands. Therefore i hunted through the LUA code for the plugin and tried to reverse engineer it and understand where i needed to edit to acheive the features above.

The below shows a snippet of code for part of the countdown timer function which runs when you arm the alarm, or when it detects the front door sensor being tripped…

[code]function updateRemaining()
local dueTimestamp = readVariableOrInit(Device,SERVICE_ID, “DueTimestamp”, “”)
local remaining = tonumber(dueTimestamp) - os.time()
if (remaining < 0) then remaining = 0 end
setIfChanged(SERVICE_ID, “Remaining”, remaining, Device)
–Sounds indoor siren whilst away or incoming delay is in progress
luup.call_delay( ‘TurnOnSirenIndoor’, 2 )
luup.call_delay( ‘TurnOffSirenIndoor’, 1 )
return remaining > 0
end

function TurnOnSirenIndoor()
luup.call_action(SID_SwitchPower1, “SetTarget”, {newTargetValue = “1”}, 28)
end

function TurnOffSirenIndoor()
luup.call_action(SID_SwitchPower1, “SetTarget”, {newTargetValue = “0”}, 28)
end[/code]

To summarise, the above works out the stop time for the counter minus the current time, giving you the “countdown” and then whilst it is greater than 0 it calls the Siren ON function with a delay of 2 seconds and then the OFF function with a 1 second delay. I chose these delay times, as it gives the nicest “Beep Beep” effect. This then loops until the countdown timer is finished and at which point either arms the alarm, or runs the panic function.

To clarify - i wrote the two SirenIndoor functions and added them to loop above them, however the timer was part of the plugin already.

My issue is that i’m finding it all really really slow and delayed. For example my wife disarmed the alarm this afternoon, and the indoor siren remained ON for “alledgedly” 2 minutes before turning OFF again. Annoyingly my Edge seems to also have lost any logs/alerts from prior to the disarm trigger taking place too - which makes it even harder to diagnose.

Is there a better way of doing this? Or is Z Wave and/or Vera Edge, simply incapable of sending ON/OFF signals and acting on them as fast as I desire?

I would really appreciate some advice with this, as the wife just wanted a standard alarm, however i like the idea that this system in theory gives me a lot more options for future automation and such, and until i get it working - i’m going to continue getting ear ache! The full lua file is attached if it helps understand what is going on.

Many thanks in advance.

I would NOT rely on LUA/Z-Wave to get messages out at 1 second resolution.
Especially if other things are happening at the same time (doors opening, motion sensors tripping from activity … )

Sorry for the slow reply - I’ve just got back from holiday :slight_smile:

Thank you for you post, i guess this is what i needed to know, even if it’s not exactly the answer I was hoping for. At least now I can code around the fact that it won’t be able to handle the speed at which i was hoping it could fire signals.

I will change my script so it only sounds the indoor siren for about 5 seconds upon arming the alarm and then again upon intrusion detected via the front door. At least this will remind you the alarm is on and you have time to disarm before it goes off.

One more question around the call_delay option…if i have a script which is similar to below…
luup.call_delay( ‘TurnOnSirens’, 0 )
luup.call_delay( ‘TurnOFFSirens’, 5 )
“Some other code”

Are both the call delay “requests” sent to the controller at the same time (pretty much), so it will run the ON, and exactly 5 seconds later run the OFF and then run the “some other code” immediately after the requests are sent, i.e. before the OFF function is actually run?

Or…does it run the ON function, once completed, run the OFF function and then only once completed (i.e. about 5 seconds later) it runs the “some other code”?

Does that make sense?

I’m trying to confirm whether code after the delayed functions runs before or after the delayed function(s) has completed.

[quote=“dasmith83, post:3, topic:187959”]…if i have a script which is similar to below…
luup.call_delay( ‘TurnOnSirens’, 0 )
luup.call_delay( ‘TurnOFFSirens’, 5 )
“Some other code”

Are both the call delay “requests” sent to the controller at the same time (pretty much), so it will run the ON, and exactly 5 seconds later run the OFF and then run the “some other code” immediately after the requests are sent, i.e. before the OFF function is actually run?[/quote]

Yes, this is the roughly way it should work (although I doubt the word ‘exactly’). Certainly ‘some other code’ will run before the 5 second delay.

Ok. Thanks very much. This makes sense why I was struggling so much previously too.

I’ve so much to learn!

We all have!

Yes, the whole point of callbacks is to run asynchronously from the main thread.