heggink and I are worked on a new script but because his work is more next level (with doorlocks and auto arming) I started to make something as simple as possible (as start point) I want to post it here and get some feedback.
also a big thanks to dannybloe for his work and comments.
requirements:
2 user variables:
- AlarmSirenTime, integer (example: 3)
AlarmOnDelay, integer (example: 60)
3 virtual switches:
- vsAlarm_dooropen
vsAlarm_SoundSiren
vsAlarm_Detected
test door switch (testdeur) to test script without walking to the door everytime.
these switches have I placed in a roomplan: Alarm. handy to test. when script is finished I will place $ in front of the name.
2 dzVents scripts:
global_data
Code: Select all
local SECURITY_PANEL = 'Security Panel'
local ALARM_DETECTED = 'vsAlarm_Detected'
local ALARM_DOOR_OPEN = 'vsAlarm_dooropen'
local SIREN = 'vsAlarm_SoundSiren'
local delay = 60
return {
helpers = {
PlaySound = function(msg)
os.execute("sudo killall mplayer")
os.execute("sh /home/pi/domoticz/scripts/bash/Play_sound.sh '" .. msg .. "' ")
end,
alarmOn = function(dz, notify, delay)
dz.log('In alarmOn: ' .. dz.security, dz.LOG_DEBUG)
if (dz.security == dz.SECURITY_DISARMED) then
if (dz.devices(ALARM_DOOR_OPEN).state == 'Off') then
dz.log('Arming domoticz', dz.LOG_INFO)
--domoticz.devices('AlarmActive').switchOn() -- we will use this later as override
dz.devices(SECURITY_PANEL).armAway().afterSec(delay)
if (notify) then -- DB: use param notify
dz.notify('SECURITY', 'Arming Alarm', dz.PRIORITY_HIGH)
end
--dz.devices('Home Temp').updateSetPoint(15)
--dz.devices('Thermostat Downstairs Away').switchOn()
dz.helpers.playSound('Alarm Geactiveerd')
else
dz.log('Failed Arming domoticz, door/window still open', dz.LOG_ERROR)
if (notify) then
dz.notify('SECURITY', 'FAILED Arming Alarm, door/window open', dz.PRIORITY_HIGH) -- DB: const
end
dz.helpers.playSound('Alarm niet geactiveerd, er staat nog iets open') -- DB: camelCase
end
end
end,
alarmOff = function(dz)
dz.log('In alarmOff: ' .. dz.security, dz.LOG_DEBUG)
if (dz.security == dz.SECURITY_ARMED_AWAY) then
-- Reset al states
dz.devices(SIREN).switchOff()
dz.devices(ALARM_DOOR_OPEN).switchOff()
dz.devices(ALARM_DETECTED).switchOff()
--dz.devices('$AlarmActive').switchOff()
dz.devices('Sirene').switchOff() -- real siren!!
dz.devices(SECURITY_PANEL).disarm()
dz.log('Disarming domoticz', dz.LOG_INFO) -- DB: info?
if (notify) then
dz.notify('SECURITY', 'Disarming Alarm', dz.PRIORITY_HIGH)
end
dz.helpers.playSound('Alarm Uitgeschakeld')
end
end
}
}
AlarmScript
Code: Select all
local CUSTOM_KEYPAD = 'Keypad Access Control'
local ALARM_DETECTED = 'vsAlarm_Detected'
local ALARM_DOOR_OPEN = 'vsAlarm_dooropen'
local SIREN = 'vsAlarm_SoundSiren'
local DELAY = 60 --seconds
local TEST_DOOR = 'deurtest'
local NOTIFY_ALARM = true
return {
active = true,
on = {
devices = {
CUSTOM_KEYPAD,
'deur*', 'Schuifpui',
ALARM_DETECTED, ALARM_DOOR_OPEN, SIREN
}
},
logging = {
level = domoticz.LOG_DEBUG,
marker = "Alarm script: " -- prefix added to every log message
},
-- actual event code
execute = function(dz, dv)
local devices = dz.devices
local delay = dz.variables(DELAY).value
--CUSTOM_KEYPAD
if (dv.name == CUSTOM_KEYPAD) then
dz.log('Status bericht: ' .. dv.name .. dv.state, dz.LOG_DEBUG) -- DB: moeten er geen spaties oid tussen name en state? add loglevel, debug of info?
if (dv.state == 'On') then
if (dz.security == dz.SECURITY_DISARMED) then -- DB: gebruik dz constants
dz.log('CUSTOM_KEYPAD switches alarm ON')
dz.helpers.alarmOn(dz, NOTIFY_ALARM, delay) --DB: geef NOTIFY_ALARM ook mee, denk dat je hier je delay wil meegeven
end
else
if (dz.security == dz.SECURITY_ARMED_AWAY) then -- DB: constatns
dz.log('CUSTOM_KEYPAD switches alarm OFF', dz.LOG_INFO) --DB: loglevel?
dz.helpers.alarmOff(dz, NOTIFY_ALARM, delay) -- DB: NOTIFY_ALARM meegeven
end
end
return
end
-- Notify that alarm is triggered and siren will go off
if (dv.name == ALARM_DETECTED
and dv.state == 'On'
and dz.security == dz.SECURITY_ARMEDAWAY) then
dz.log('Alarm detected during Armed Away status, report it!')
dz.notify('SECURITY', 'ALARM: Sensor ging af', dz.PRIORITY_EMERGENCY)
if (NOTIFY_ALARM) then
local notifySub = '[ALARM] ' .. dv.name .. ' - device triggered'
local notifyMsg = '[ALARM] ' .. dv.name .. ' - ' .. dv.state .. ' - device triggered'
--DB: wel een lange subject.. zou je die niet korter houden en meer in het bericht stoppen?
dz.notify(notifySub, notifyMsg, dz.PRIORITY_EMERGENCY)
dz.log(notifyMsg, dz.LOG_DEBUG) --DB: dit is debug info lijkt me? dus debug level gebruiken?
end
devices(ALARM_DETECTED).switchOff().afterSec(20)
devices(SIREN).switchOn().afterSec(90)
dz.helpers.PlaySound('Beweging gedetecteerd, alarm gaat over 90 seconden af.', NOTIFY_ALARM)
dz.notify('SECURITY', 'Switching Siren on in 90 seconds', dz.PRIORITY_EMERGENCY)
return
end
-- Siren make somenoise!
if (dv.name == SIREN
and dv.state == 'On'
and dz.security == dz.SECURITY_ARMEDAWAY) then
-- devices('Siren').switchOn().forMin(duration)
dz.helpers.PlaySound('Herrie, wordt vervangen door werkelijke sirene!!!', NOTIFY_ALARM)
dz.notify('ALARM!!!', 'Siren switched on due to Alarm going off', dz.PRIORITY_EMERGENCY)
return
end
-- This point in script it will always be a door..
if (dv.name == TEST_DOOR) then
-- Motion detected
if (dv.bState) then
--local message -- DB: deze gebruik je alleen in de forEach dus dan kan je die daar ook declaren
-- first filter on name starting with Door/window
devices().filter(function(device)
local name = device.name
return (string.sub(name, 1, 4) == 'deur')
end).forEach(function(sensor)
local message = 'DSWStatus: ' .. 'Device ' .. sensor.name .. ' has status (' .. sensor.state .. '), '
dz.log(message, dz.LOG_DEBUG)
if (sensor.bState) then
dz.log(message, dz.LOG_DEBUG)
-- if something is open but alarm is not armed vsAlarm_dooropen will switched because the alarm can't be activated
devices(ALARM_DOOR_OPEN).switchOn()
if (dz.security == dz.SECURITY_ARMEDAWAY) then
devices(ALARM_DETECTED).switchOn()
end
end
end)
end
end
end
}
sh script for voice speech on
/home/pi/domoticz/scripts/bash
Code: Select all
#!/bin/sh
killall mplayer
izsynth -e google -v nl "$1"
please shoot! reply/pm with ideas, faults typos whatever you like.