i use my HC2 to send an email when some door sensors are armed.
therefore i use:
-- Alarm an--
local message_on = (os.date("Haustüre um %H:%M Uhr zugesperrt. Die Fenster und die Haustüre sind scharf! (%d.%m.%Y)"))
local subject_on = "Haustüre zugesperrt"
fibaro:call(2, 'sendEmail', subject_on, message_on)
my script is triggered with an contact in my door when i lock it.
the contact works fine, so i can see in debug!
but often the email is not be sent!
maybe my script has an bug ?
here the whole script:
--[[
%% properties
128 value
%% globals
--]]
------------------------------
--###---- Variablen ----###--
------------------------------
local windowID = {30,113,99} -- IDs der Sensoren die ge-/entschärft werden sollen
local countID = 200 -- zähler für maximale Kontaktanzahl
local riegel = 128 -- ID Riegelkontakt
-- farbige Debug Meldungen
Debug = function ( color, message )
fibaro:debug(string.format('<%s style="color:%s;">%s', "span", color, message, "span"))
end
-- Alarm an--
local message_on = (os.date("Haustüre um %H:%M Uhr zugesperrt. Die Fenster und die Haustüre sind scharf! (%d.%m.%Y)"))
local subject_on = "Haustüre zugesperrt"
-- Alarm aus--
local message_off = (os.date("Haustüre um %H:%M Uhr aufgesperrt. Der Alarm wurde deaktiviert. (%d.%m.%Y)"))
local subject_off = "Haustüre aufgesperrt"
------------------------------
--###---- Funktionen ----###--
------------------------------
-- An --
function Notify_on()
--->> Hier muss der Code rein wenn der Alarm aktiviert wurde <<---
fibaro:call(2, 'sendEmail', subject_on, message_on)
end
-- Aus --
function Notify_off()
--->> Hier muss der Code rein wenn der Alarm deaktiviert wurde <<---
fibaro:call(2, 'sendEmail', subject_off, message_off)
end
--- Arm-Check ---
function armedcheckSensorID(array)
for j=1, countID do
if windowID[j] ~= nil then
if (tonumber(fibaro:getValue(windowID[j], 'armed')) == 0) then
return false
end
end
end
return true
end
---Disarm Check ---
function disarmedcheckSensorID(array)
for j=1, countID do
if windowID[j] ~= nil then
if (tonumber(fibaro:getValue(windowID[j], 'armed')) == 1) then
return false
end
end
end
return true
end
------------------------------
--###---- Skript ----###--
------------------------------
--- Schärfen ---
if ( (tonumber(fibaro:getValue(riegel, "value")) == 0 ) ) then
--fibaro:debug('Türe Abgeschlossen')
Debug('green','Türe Abgeschlossen')
for j=1, countID do
if windowID[j] ~= nil then
if (tonumber(fibaro:getValue(windowID[j], 'value')) == 0) then
fibaro:call(windowID[j], 'setArmed', '1')
else
local sensorname = fibaro:getName(windowID[j])
local sensorroom = fibaro:getRoomNameByDeviceID(windowID[j])
local subject_unsafe = 'ACHTUNG: ' ..sensorroom.. ' offen!'
local message_unsafe = 'Im Raum: ' .. sensorroom ..' ist der '.. sensorname ..' nicht geschlossen!'
Debug('red',message_unsafe)
fibaro:call(2, 'sendEmail', subject_unsafe, message_unsafe)
fibaro:call(141, 'sendPush', message_unsafe) -- Galaxy S7
-- fibaro:call(159, 'sendPush', message_unsafe) -Nexus 4
end
end
end
if (armedcheckSensorID(windowID)) then
Debug('green','Alle Sensoren scharf.')
Notify_on()
end
else
end
--- Entschäfen ---
if ( (tonumber(fibaro:getValue(riegel, "value")) == 1 ) ) then
Debug('green','Türe Aufgeschlossen.')
fibaro:call(2, 'sendEmail', 'Wohnung wurde aufgesperrt')
for j=1, countID do
if windowID[j] ~= nil then
if (tonumber(fibaro:getValue(windowID[j], 'value')) == 0) then
fibaro:call(windowID[j], 'setArmed', '0')
else
local sensorname = fibaro:getName(windowID[j])
local sensorroom = fibaro:getRoomNameByDeviceID(windowID[j])
local subject_unsafe = 'ACHTUNG: ' ..sensorroom.. ' offen!'
local message_unsafe = 'Im Raum: ' .. sensorroom ..' ist der '.. sensorname ..' nicht geschlossen!'
Debug('red',message_unsafe)
--fibaro:call(2, 'sendEmail', subject_unsafe, message_unsafe)
--fibaro:call(2, 'sendPush', message_unsafe)
end
end
end
if (disarmedcheckSensorID(windowID)) then
Debug('green','Alle Sensoren entschärft.')
Notify_off();
end
else
end