Alarm with repeatAfterSec

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
terrorsource
Posts: 67
Joined: Wednesday 10 May 2017 17:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Alarm with repeatAfterSec

Post by terrorsource »

Hi,

I'm trying to build an alarm script in DzVents and want to turn on the Siren for 10sec, then 5sec off then 10sec on etc etc so lang a dummy switch "Alarm_BG" is turned on.

I was thinking that repeatAfterSec could help me with that.

This is what i have so far, not very much but it's just a start.

Code: Select all

return {
	on = {
		devices = {
			'Alarm_BG'
		}
	},
	
    execute = function(domoticz,trigger) 
        if domoticz.devices("Alarm_BG").state == "Off" and domoticz.devices("Sirene").state == "On" then
           domoticz.devices("Sirene").switchOff()
       
        elseif domoticz.devices("Alarm_BG").state == "On" then
            domoticz.devices("Sirene").switchOn().forSec(10).repeatAfterSec(16, 30)
		end
   end
}
JuanUil
Posts: 500
Joined: Friday 22 May 2015 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11083
Location: Asten NB Nederland
Contact:

Re: Alarm with repeatAfterSec

Post by JuanUil »

Hi,

I have a LUA script to do that.

Code: Select all

-- ~/domoticz/scripts/lua/script_device_AlarmBoven.lua

-- Functie om de sirene een paar keer te laten gaan (instelbaar)
function soundSirene(sirene, times)
    times = times or 5
    local pause = 0
    for i = 1, times do
        commandArray[#commandArray + 1]={[sirene]='On AFTER '..pause }
        pause = pause + 60
        commandArray[#commandArray + 1]={[sirene]='Off AFTER '..pause }
        pause = pause + 60
	end
end

 --   soundSirene("Sirene") -- Make the sirene sound default number of times
 --   soundSirene("Sirene", 3) -- Make the sirene sound 3 times

commandArray = {}


if (otherdevices['Alarm Boven']=='On' and (devicechanged['Logeerkamer']=='Open' or devicechanged['Behandelkamer']=='Open')) then
	commandArray['SendEmail']='Alarm#Er is een raam boven open gegaan#xxxxxxxxxxxxxxx'
	commandArray['SendEmail']='Alarm#Er is een raam boven open gegaan#xxxxxxxxxxxxxxx'
    soundSirene("Sirene", 5) -- Make the sirene sound 5 times
end

return commandArray
Your mind is like a parachute,
It only works when it is opened!

RPI4 several Fibaro, KaKu, Neocoolcam switches, Z-Wave, Zigbee2Mqtt, Ikea bulbs and remote, Zigbee temp nodes
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest