I'm currently running the below script, but am getting double notifications.
I have a small remote control, that triggers the scene. When that happens, i will get 2 notification e-mails. I'm not sure if this is just the remote control triggering the scene multiple times, or the script being wrong, or dzVents not working 100% correctly.
Code: Select all
return {
active = true,
on = {
devices = {
'Alarm:*',
'$Alarm:*',
'Sensor*',
'$Sensor*'
},
variables = {
'Alarm:*'
},
security = {
domoticz.SECURITY_ARMEDAWAY,
domoticz.SECURITY_ARMEDHOME,
domoticz.SECURITY_DISARMED
},
scenes = {
'Scene:*'
}
},
logging = {
level = domoticz.LOG_DEBUG,
marker = ' === SECURITY SCRIPT ==='
},
execute = function(domoticz, device, triggerInfo)
-- If the security panel triggers the event, then we find it and set our device to it
if triggerInfo.type == domoticz.EVENT_TYPE_SECURITY then
device = domoticz.devices().find(function(dev)
return dev.hardwareTypeValue == 67
end)
end
local alarmVariable = domoticz.variables('Alarm:Timer')
local securityPanel = domoticz.devices('Alarm: Security Panel')
local alarmActive = domoticz.devices('Alarm: Active')
-- Using scene's to arm/disarm so we can bind it to the buttons
if device.name == 'Scene: Button 2 - Disarm / back home' and device.state == 'On' then
if domoticz.security ~= 'Disarmed' then
domoticz.log('Button 2 on remote pressed. Disarming!')
securityPanel.disarm()
end
end
if device.name == 'Scene: Button 1 - Arm / leave home' and device.state == 'On' then
if domoticz.security == 'Disarmed' then
domoticz.log('Button 1 on remote pressed. Armed Away!')
securityPanel.armHome()
end
end
-- Security panel is being disarmed.
if device.name == 'Alarm: Security Panel' then
domoticz.notify('Alarm panel changed', 'The Security Panel was ' .. device.state, PRIORITY_LOW)
if device.state == domoticz.SECURITY_DISARMED then
alarmActive.setState('Off')
end
end
-- Detect movement
if domoticz.security ~= 'Disarmed' then
if string.find(device.name, '.?Sensor.*Burglar$') ~= nil and device.state == 'On' then
-- TODO: play a sound
alarmVariable.set(1).afterSec(15)
end
if string.find(device.name, '.?Sensor1: Burglar$') ~= nil and device.state == 'On' then
domoticz.sendCommand('SendCamera:1', 'Somebody entered the house!')
end
if string.find(device.name, '.?Sensor2: Burglar$') ~= nil and device.state == 'On' then
domoticz.notify('Somebody entered the house!', 'Somebody entered the back of the house while the alarm is armed!', PRIORITY_HIGH, SOUND_INCOMING)
end
end
if device.name == 'Alarm:Timer' and device.value == 1 then
alarmVariable.set(0);
if domoticz.security ~= 'Disarmed' then
alarmActive.setState('On')
end
end
if device.name == 'Alarm: Active' then
domoticz.log('===== ALARM ACTIVE STATE: ' .. device.state)
if device.state == 'On' then
domoticz.notify('Sounding the alarm!', 'We would be sounding the alarm now!',PRIORITY_HIGH, SOUND_INCOMING)
domoticz.sendCommand('SendCamera:1', 'This is the image!')
---domoticz.devices('$SmokeDetector1: Switch').setState('On')
end
if device.state == 'Off' and device.changed == true then
domoticz.notify('Alarm turned off', 'The alarm sounded but is now turned off!',PRIORITY_LOW, SOUND_INCOMING)
---domoticz.devices('$SmokeDetector1: Switch').setState('Off')
end
end
end
}