Domoticz alarm scripts Hardware.Info Magazine #5/2017

In het nieuwe Hardware.Info Magazine vind je een workshop over het zelf maken van een alarmsysteem met behulp van de Domoticz Home Automation software. In het artikel vermelden we twee stukken code die je middels de in Domoticz geïntegreerde LUA-programmeertaal moet overnemen. Voor wie liever copy-paste dan tikt, hieronder de twee in het magazine getoonde stukken code:

Script "Alarm paneel"

commandArray = {}
 if (devicechanged['Alarm RFID Paneel'] == 'On') then
    commandArray['Domoticz Security Panel'] = 'Arm Away'
    print('### SecPanel: status changed to ' .. globalvariables['Security'])
 end
 if (devicechanged['Alarm RFID Paneel'] == 'Off') then
    commandArray['Domoticz Security Panel'] = 'Disarm'
    commandArray['Alarm situatie'] = 'Off'
    print('### SecPanel: status changed to ' .. globalvariables['Security'])
 end
return commandArray

Script "Detecteer jamming"

commandArray = {}
json = (loadfile "/volume1/@appstore/domoticz/var/scripts/lua/JSON.lua")()
local url = string.format("http://192.168.1.100:8084/json.htm?type=openzwavenodes&idx=8")
url = string.format("%s %q", "curl", url)
local zwavenodes=assert(io.popen(url))
local nodes = zwavenodes:read('*all')
zwavenodes:close()
local jsonZwave = json:decode(nodes)
jammingdetected = false
for i, zwavedevice in ipairs(jsonZwave['result']) do
 if (jsonZwave['result'][i]['PollEnabled'] == 'true') then
    s = jsonZwave['result'][i]['LastUpdate']
    year = string.sub(s, 1, 4)
    month = string.sub(s, 6, 7)
    day = string.sub(s, 9, 10)
    hour = string.sub(s, 12, 13)
    minutes = string.sub(s, 15, 16)
    seconds = string.sub(s, 18, 19)
    t1 = os.time()
    t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
    difference = (os.difftime (t1, t2))
    if (difference > 60) then
        print('Mogelijke jamming! Z-wave product niet bereikbaar: ' .. jsonZwave['result'][i]['Description'])
        jammingdetected = true
    end
 end
end
if (jammingdetected == true and otherdevices['Jamming gedetecteerd'] == 'Off') then
        commandArray['Jamming gedetecteerd']='On'
elseif (jammingdetected == false and otherdevices['Jamming gedetecteerd'] == 'On') then
        commandArray['Jamming gedetecteerd']='Off'
end    
return commandArray

« Vorig bericht Volgend bericht »
0