Re: Did I leave the door open?
Posted: Sunday 03 March 2019 19:37
What does your log show?
2019-03-04 17:10:00.579 Status: dzVents: Info: POR: ------ Start internal script: Deuren open test2:, trigger: every 5 minutes
2019-03-04 17:10:00.602 Status: dzVents: Info: POR: Device Garage staat 0 minuten open.
2019-03-04 17:10:00.604 Status: dzVents: Info: POR: ------ Finished Deuren open test2
2019-03-04 17:15:00.576 Status: dzVents: Info: POR: ------ Start internal script: Deuren open test2:, trigger: every 5 minutes
2019-03-04 17:15:00.599 Status: dzVents: Info: POR: Device Garage staat 5 minuten open.
2019-03-04 17:15:00.599 Status: dzVents: Error (2.4.6): POR: An error occured when calling event handler Deuren open test2
2019-03-04 17:15:00.599 Status: dzVents: Error (2.4.6): POR: .../scripts/dzVents/generated_scripts/Deuren open test2.lua:35: attempt to index global 'Domoticz' (a nil value)
2019-03-04 17:15:00.599 Status: dzVents: Info: POR: ------ Finished Deuren open test2
try to change Domoticz to domoticz (case matters)remko2000 wrote: Monday 04 March 2019 17:17 My log show:
2019-03-04 17:10:00.579 Status: dzVents: Info: POR: ------ Start internal script: Deuren open test2:, trigger: every 5 minutes
2019-03-04 17:10:00.602 Status: dzVents: Info: POR: Device Garage staat 0 minuten open.
2019-03-04 17:10:00.604 Status: dzVents: Info: POR: ------ Finished Deuren open test2
2019-03-04 17:15:00.576 Status: dzVents: Info: POR: ------ Start internal script: Deuren open test2:, trigger: every 5 minutes
2019-03-04 17:15:00.599 Status: dzVents: Info: POR: Device Garage staat 5 minuten open.
2019-03-04 17:15:00.599 Status: dzVents: Error (2.4.6): POR: An error occured when calling event handler Deuren open test2
2019-03-04 17:15:00.599 Status: dzVents: Error (2.4.6): POR: .../scripts/dzVents/generated_scripts/Deuren open test2.lua:35: attempt to index global 'Domoticz' (a nil value)
2019-03-04 17:15:00.599 Status: dzVents: Info: POR: ------ Finished Deuren open test2
Code: Select all
local devicesToCheck = {
-- table with doors to check and the minutes before the first warning is given
{ ['name'] = 'Voordeur', ['threshold'] = 10 },
{ ['name'] = 'Garage', ['threshold'] = 2 },
{ ['name'] = 'Achterdeur', ['threshold'] = 10 },
}
-- number of times you are warned about an open door
local alertCount = 3
return {
active = true,
on = {
timer = {'every 5 minutes'},
},
logging = {
level = domoticz.LOG_INFO,
marker = "POR"
},
-- count per door of the number of alerts per door
data = {
['Voordeur'] = {initial=0},
['Garage'] = {initial=0},
['Achterdeur'] = {initial=0},
},
execute = function(domoticz)
for i, deviceToCheck in pairs(devicesToCheck) do
local name = deviceToCheck['name']
local threshold = deviceToCheck['threshold']
local state = domoticz.devices(name).state
local minutes = domoticz.devices(name).lastUpdate.minutesAgo
if ( state == 'Open') then
domoticz.log('Device ' .. name .. ' staat ' .. minutes .. ' minuten open.')
if (minutes > threshold) and (domoticz.data[name] < alertCount) then
domoticz.data[name] = domoticz.data[name] + 1
domoticz.notify('Herinnering-open',
name .. ' staat al langer dan ' .. minutes .. ' minuten open.',
domoticz.PRIORITY_HIGH)
domoticz.log('dit is waarschuwing ' .. tostring(domoticz.data[name]))
end
elseif (domoticz.data[name] > 0) then
domoticz.notify('Herinnering-dicht',
name .. ' is weer gesloten.',
domoticz.PRIORITY_HIGH)
domoticz.log('Device ' .. name .. ' is ' .. minutes .. ' dicht.')
domoticz.data[name] = 0
end
end
end
}Yes sorry, I didn't receive notification of your message.
Code: Select all
local devicesToCheck = {
-- table with doors to check and the minutes before the first warning is given
{ ['name'] = 'Porte Entrée',
['threshold'] = 1,
['actionOpen'] = function(domoticz)
domoticz.log('Porte entrée ouverte')
end ,
['actionClose'] = function(domoticz)
domoticz.log('Porte entrée fermée')
end },
{ ['name'] = 'Porte Terrasse',
['threshold'] = 1,
['actionOpen'] = function(domoticz)
domoticz.devices('Thermostat Away Mode').switchOn()
end ,
['actionClose'] = function(domoticz)
domoticz.devices('Thermostat Away Mode').switchOff()
end },
}
-- number of times you are warned about an open door
local maxAlertCount = 5
return {
active = true,
on = {
timer = {'every 1 minutes'},
},
logging = {
-- level = domoticz.LOG_INFO,
marker = "PORTES"
},
-- count per door of the number of alerts per door
data = {
['Porte Entrée'] = {initial=0},
['Porte Terrasse'] = {initial=0},
},
execute = function(domoticz)
for i, deviceToCheck in pairs(devicesToCheck) do
local name = deviceToCheck['name']
local threshold = deviceToCheck['threshold']
local state = domoticz.devices(name).state
local minutes = domoticz.devices(name).lastUpdate.minutesAgo
if ( state == 'Unlocked') then
domoticz.log('La ' .. name .. ' est ouverte depuis ' .. minutes .. ' minutes.')
if (minutes > threshold) and (domoticz.data[name] < maxAlertCount) then
domoticz.data[name] = domoticz.data[name] + 1
domoticz.notify('Porte ouverte', 'La ' .. name .. ' est ouverte depuis ' .. minutes .. ' minutes.', domoticz.PRIORITY_HIGH, domoticz.SOUND_NONE, nil, domoticz.NSS_TELEGRAM)
deviceToCheck['actionOpen'](domoticz)
end
elseif (domoticz.data[name] > 0) then
domoticz.data[name] = 0
domoticz.notify('Porte ouverte', 'La ' .. name .. ' est refermée.', domoticz.PRIORITY_HIGH, domoticz.SOUND_NONE, nil, domoticz.NSS_TELEGRAM)
deviceToCheck['actionClose'](domoticz)
end
end
end
}One thing I'd like to change in the future would be to act upon a change on the sensor instead of testing every x minutes.
Code: Select all
local devicesToCheck = {
-- table with doors to check and the minutes before the first warning is given
{ ['name'] = 'Voordeur', ['threshold'] = 5 },
{ ['name'] = 'Zolderdeur', ['threshold'] = 10 },
}
-- number of times you are warned about an open door
local alertCount = 3
return {
active = true,
on = {
timer = {'every 5 minutes'},
},
logging = {
-- level = domoticz.LOG_INFO,
marker = "POR"
},
-- count per door of the number of alerts per door
data = {
['Voordeur'] = {initial=0},
['Zolderdeur'] = {initial=0},
},
execute = function(domoticz)
for i, deviceToCheck in pairs(devicesToCheck) do
local name = deviceToCheck['name']
local threshold = deviceToCheck['threshold']
local state = domoticz.devices(name).state
local minutes = domoticz.devices(name).lastUpdate.minutesAgo
if ( state == 'Open') then
domoticz.log('Device ' .. name .. ' staat ' .. minutes .. ' minuten open.')
if (minutes > threshold) then
domoticz.data[name] = domoticz.data[name] + 1
domoticz.notify('Herinnering-open',
name .. ' staat al langer dan ' .. minutes .. ' minuten open.',
domoticz.PRIORITY_HIGH)
domoticz.log('dit is waarschuwing ' .. tostring(domoticz.data[name]))
end
elseif (domoticz.data[name] > 0) then
domoticz.notify('Herinnering-dicht',
name .. ' is weer gesloten.',
domoticz.PRIORITY_HIGH)
domoticz.log('Device ' .. name .. ' is ' .. minutes .. ' dicht.')
domoticz.data[name] = 0
end
end
end
}Can you try this ?
Code: Select all
return
{
active = true,
on =
{
timer = {'every 5 minutes'},
},
logging =
{
level = domoticz.LOG_INFO,
marker = "POR"
},
data =
{
VoordeurAlerts = { initial = 0 },
ZolderdeurAlerts = { initial = 0 },
},
execute = function(dz)
-- table with names of doors to check as key, minutes before the first warning is given and max number of Alerts as values
local devicesToCheck =
{
Voordeur = { threshold = 5 , maxAlerts = 3},
Zolderdeur = { threshold = 10, maxAlerts = 2 },
}
for name, settings in pairs(devicesToCheck) do
local device = dz.devices(name)
local alertCount = dz.data[name .. 'Alerts']
if device.state == 'Open' then
dz.log('Device ' .. name .. ' staat ' .. device.lastUpdate.secondsAgo .. ' seconden open.')
local minutesOpen = device.lastUpdate.minutesAgo
if minutesOpen > settings.threshold and alertCount < settings.maxAlerts then
alertCount = alertCount + 1
dz.notify('Herinnering-open',name .. ' staat al langer dan ' .. minutesOpen .. ' minuten open.',dz.PRIORITY_HIGH)
dz.log('dit is waarschuwing ' .. alertCount)
end
elseif alertCount > 0 then
dz.notify('Herinnering-dicht',name .. ' is weer gesloten.',dz.PRIORITY_HIGH)
dz.log('Device ' .. name .. ' is ' .. device.lastUpdate.secondsAgo .. ' seconden dicht.')
alertCount = 0
end
dz.data[name .. 'Alerts'] = alertCount
end
end
}
Waaren,waaren wrote: Tuesday 03 December 2019 21:00 Can you try this ?
Code: Select all
return { active = true, on = { timer = {'every 5 minutes'}, }, logging = { level = domoticz.LOG_INFO, marker = "POR" }, data = { VoordeurAlerts = { initial = 0 }, ZolderdeurAlerts = { initial = 0 }, }, execute = function(dz) -- table with names of doors to check as key, minutes before the first warning is given and max number of Alerts as values local devicesToCheck = { Voordeur = { threshold = 5 , maxAlerts = 3}, Zolderdeur = { threshold = 10, maxAlerts = 2 }, } for name, settings in pairs(devicesToCheck) do local device = dz.devices(name) local alertCount = dz.data[name .. 'Alerts'] if device.state == 'Open' then dz.log('Device ' .. name .. ' staat ' .. device.lastUpdate.secondsAgo .. ' seconden open.') local minutesOpen = device.lastUpdate.minutesAgo if minutesOpen > settings.threshold and alertCount < settings.maxAlerts then alertCount = alertCount + 1 dz.notify('Herinnering-open',name .. ' staat al langer dan ' .. minutesOpen .. ' minuten open.',dz.PRIORITY_HIGH) dz.log('dit is waarschuwing ' .. alertCount) end elseif alertCount > 0 then dz.notify('Herinnering-dicht',name .. ' is weer gesloten.',dz.PRIORITY_HIGH) dz.log('Device ' .. name .. ' is ' .. device.lastUpdate.secondsAgo .. ' seconden dicht.') alertCount = 0 end dz.data[name .. 'Alerts'] = alertCount end end }
Code: Select all
return
{
active = true,
on =
{
timer = {'every 2 minutes'},
},
logging =
{
level = domoticz.LOG_INFO,
marker = "POR"
},
data =
{
Deur_woonkamerAlerts = { initial = 0 },
},
execute = function(dz)
-- table with names of doors to check as key, minutes before the first warning is given and max number of Alerts as values
local devicesToCheck =
{
Deur_woonkamer = { threshold = 5 , maxAlerts = 3},
}
for name, settings in pairs(devicesToCheck) do
local device = dz.devices(name)
local alertCount = dz.data[name .. 'Alerts']
if device.state == 'Open' then
dz.log('Device ' .. name .. ' staat ' .. device.lastUpdate.secondsAgo .. ' seconden open.')
local minutesOpen = device.lastUpdate.minutesAgo
if minutesOpen > settings.threshold and alertCount < settings.maxAlerts then
alertCount = alertCount + 1
dz.notify('Herinnering-open',name .. ' staat al langer dan ' .. minutesOpen .. ' minuten open.',dz.PRIORITY_HIGH)
dz.log('dit is waarschuwing ' .. alertCount)
end
elseif alertCount > 0 then
dz.notify('Herinnering-dicht',name .. ' is weer gesloten.',dz.PRIORITY_HIGH)
dz.log('Device ' .. name .. ' is ' .. device.lastUpdate.secondsAgo .. ' seconden dicht.')
alertCount = 0
end
dz.data[name .. 'Alerts'] = alertCount
end
end
}
change to
Code: Select all
if alertCount == '3' then
Thank for helping! I have a error pts/dzVents/generated_scripts/deuropen_verwaming_uit.lua:54: unexpected symbol near '}'waaren wrote: Saturday 18 January 2020 22:50change toAssignment is the basic means of changing the value of a variable or a table field:Code: Select all
if alertCount == '3' then
a = "hello" .. "world"
Lua provides the following relational operators:
< > <= >= == ~=
All these operators always result in true or false.
Code: Select all
return
{
active = true,
on =
{
timer = {'every 2 minutes'},
},
logging =
{
level = domoticz.LOG_INFO,
marker = "POR"
},
-- table with names of doors Alerts
data =
{
Deur_woonkamerAlerts = { initial = 0 },
},
execute = function(dz)
-- table with names of doors to check as key, minutes before the first warning is given and max number of Alerts as values
local devicesToCheck =
{
Deur_woonkamer = { threshold = 5 , maxAlerts = 3},
}
for name, settings in pairs(devicesToCheck) do
local device = dz.devices(name)
local alertCount = dz.data[name .. 'Alerts']
if device.state == 'Open' then
dz.log('Device ' .. name .. ' staat ' .. device.lastUpdate.secondsAgo .. ' seconden open.')
local minutesOpen = device.lastUpdate.minutesAgo
if minutesOpen > settings.threshold and alertCount < settings.maxAlerts then
alertCount = alertCount + 1
dz.notify('Herinnering-open',name .. ' staat al langer dan ' .. minutesOpen .. ' minuten open.',dz.PRIORITY_HIGH)
dz.log('dit is waarschuwing ' .. alertCount)
if alertCount == '3' then
domoticz.devices('ToonApiLib - Scene').switchSelector(30)
dz.notify('Verwarming gaat lager in tempratuur',dz.PRIORITY_HIGH)
end
elseif alertCount > 0 then
dz.notify('Herinnering-dicht',name .. ' is weer gesloten.',dz.PRIORITY_HIGH)
dz.log('Device ' .. name .. ' is ' .. device.lastUpdate.secondsAgo .. ' seconden dicht.')
alertCount = 0
end
dz.data[name .. 'Alerts'] = alertCount
end
end
}
Made some corrections in the code and commented the lines with problems. Not tested so could be that you stil encounter somethingmarktn wrote: Tuesday 21 January 2020 20:02 Thank for helping! I have a error pts/dzVents/generated_scripts/deuropen_verwaming_uit.lua:54: unexpected symbol near '}'
Code: Select all
return
{
active = true,
on =
{
timer = {'every 2 minutes'},
},
logging =
{
level = domoticz.LOG_INFO,
marker = "POR"
},
-- Persistent data table with names of doors Alerts
data =
{
Deur_woonkamerAlerts = { initial = 0 },
},
execute = function(dz)
-- table with names of doors to check as key, minutes before the first warning is given and max number of Alerts as values
local devicesToCheck =
{
Deur_woonkamer = { threshold = 5 , maxAlerts = 3},
}
for name, settings in pairs(devicesToCheck) do
local device = dz.devices(name)
local alertCount = dz.data[name .. 'Alerts']
if device.state == 'Open' then
dz.log('Device ' .. name .. ' staat ' .. device.lastUpdate.secondsAgo .. ' seconden open.',dz.LOG_INFO)
local minutesOpen = device.lastUpdate.minutesAgo
if minutesOpen > settings.threshold and alertCount < settings.maxAlerts then
alertCount = alertCount + 1
dz.notify('Herinnering-open',name .. ' staat al langer dan ' .. minutesOpen .. ' minuten open.',dz.PRIORITY_HIGH)
dz.log('dit is waarschuwing ' .. alertCount,dz.LOG_INFO)
end -- << every if block must be closed with an end statement >>
-- if alertCount == '3' then -- << alertCount is a number not a string >>
if alertCount == 3 then
-- domoticz.devices('ToonApiLib - Scene').switchSelector(30) -- << object domoticz does not exist. You should use dz here >>
dz.devices('ToonApiLib - Scene').switchSelector(30)
-- dz.notify('Verwarming gaat lager in tempratuur',dz.PRIORITY_HIGH) -- << wrong syntax: must start with subject, message >>
dz.notify('Verwarming','Verwarming gaat lager in temperatuur',dz.PRIORITY_HIGH)
end
elseif alertCount > 0 then
dz.notify('Herinnering-dicht',name .. ' is weer gesloten.',dz.PRIORITY_HIGH)
dz.log('Device ' .. name .. ' is ' .. device.lastUpdate.secondsAgo .. ' seconden dicht.',dz.LOG_INFO)
alertCount = 0
end
dz.data[name .. 'Alerts'] = alertCount
end
end
}
waaren wrote: Tuesday 21 January 2020 23:58Made some corrections in the code and commented the lines with problems. Not tested so could be that you stil encounter somethingmarktn wrote: Tuesday 21 January 2020 20:02 Thank for helping! I have a error pts/dzVents/generated_scripts/deuropen_verwaming_uit.lua:54: unexpected symbol near '}'
Code: Select all
return { active = true, on = { timer = {'every 2 minutes'}, }, logging = { level = domoticz.LOG_INFO, marker = "POR" }, -- Persistent data table with names of doors Alerts data = { Deur_woonkamerAlerts = { initial = 0 }, }, execute = function(dz) -- table with names of doors to check as key, minutes before the first warning is given and max number of Alerts as values local devicesToCheck = { Deur_woonkamer = { threshold = 5 , maxAlerts = 3}, } for name, settings in pairs(devicesToCheck) do local device = dz.devices(name) local alertCount = dz.data[name .. 'Alerts'] if device.state == 'Open' then dz.log('Device ' .. name .. ' staat ' .. device.lastUpdate.secondsAgo .. ' seconden open.',dz.LOG_INFO) local minutesOpen = device.lastUpdate.minutesAgo if minutesOpen > settings.threshold and alertCount < settings.maxAlerts then alertCount = alertCount + 1 dz.notify('Herinnering-open',name .. ' staat al langer dan ' .. minutesOpen .. ' minuten open.',dz.PRIORITY_HIGH) dz.log('dit is waarschuwing ' .. alertCount,dz.LOG_INFO) end -- << every if block must be closed with an end statement >> -- if alertCount == '3' then -- << alertCount is a number not a string >> if alertCount == 3 then -- domoticz.devices('ToonApiLib - Scene').switchSelector(30) -- << object domoticz does not exist. You should use dz here >> dz.devices('ToonApiLib - Scene').switchSelector(30) -- dz.notify('Verwarming gaat lager in tempratuur',dz.PRIORITY_HIGH) -- << wrong syntax: must start with subject, message >> dz.notify('Verwarming','Verwarming gaat lager in temperatuur',dz.PRIORITY_HIGH) end elseif alertCount > 0 then dz.notify('Herinnering-dicht',name .. ' is weer gesloten.',dz.PRIORITY_HIGH) dz.log('Device ' .. name .. ' is ' .. device.lastUpdate.secondsAgo .. ' seconden dicht.',dz.LOG_INFO) alertCount = 0 end dz.data[name .. 'Alerts'] = alertCount end end }
Code: Select all
local devicesToCheck = {
-- table with doors to check and the minutes before the first warning is given
{ ['name'] = 'Long Name of Device',
['threshold'] = 1,
['alias'] = 'Short Name'},
}
-- number of times you are warned about an open door
local alertCount = 3
return {
active = true,
on = {
timer = {'every 5 minutes'},
},
-- logging = {
-- level = domoticz.LOG_INFO,
-- marker = "POR"
-- },
-- count per door of the number of alerts per door
data = {
['Long Name of Device'] = {initial=0},
},
execute = function(domoticz)
for i, deviceToCheck in pairs(devicesToCheck) do
local name = deviceToCheck['name']
local threshold = deviceToCheck['threshold']
local alias = deviceToCheck['alias']
local state = domoticz.devices(name).state
local minutes = domoticz.devices(name).lastUpdate.minutesAgo
if ( state == 'Open') then
domoticz.log(alias .. ' staat ' .. minutes .. ' minuten open.')
if (minutes > threshold) and (domoticz.data[name] < alertCount) then
domoticz.data[name] = domoticz.data[name] + 1
local alert = alias .. ' staat al langer dan ' .. minutes .. ' minuten open.'
domoticz.log('dit is waarschuwing #' .. tostring(domoticz.data[name]))
end
elseif (domoticz.data[name] > 0) then
domoticz.notify('Security', 'Device ' .. alias .. ' is weer gesloten.', domoticz.PRIORITY_NORMAL, domoticz.SOUND_DEFAULT,'', domoticz.NSS_HTTP)
domoticz.log('Device ' .. alias .. ' is ' .. minutes .. ' dicht.')
domoticz.data[name] = 0
end
end
end
}
Code: Select all
local devicesToCheck = {
-- table with doors to check and the minutes before the first warning is given
{ ['name'] = 'ven-playroom', ['threshold'] = 3 },
{ ['name'] = 'ven-adrian', ['threshold'] = 10 },
{ ['name'] = 'ven-dormitorio', ['threshold'] = 3 },
}
-- number of times you are warned about an open door
local alertCount = 3
return {
active = true,
on = {
timer = {'every 5 minutes'},
},
logging = {
-- level = domoticz.LOG_INFO,
marker = "VEN"
},
-- count per door of the number of alerts per door
data = {
['ven-playroom'] = {initial=0},
['ven-adrian'] = {initial=0},
['ven-dormitorio'] = {initial=0},
},
execute = function(domoticz)
for i, deviceToCheck in pairs(devicesToCheck) do
local name = deviceToCheck['name']
local threshold = deviceToCheck['threshold']
local state = domoticz.devices(name).state
local minutes = domoticz.devices(name).lastUpdate.minutesAgo
if ( state == 'Open') then
domoticz.log('La ventana ' .. name .. ' lleva ' .. minutes .. ' minutos abierta.')
if (minutes > threshold) and (domoticz.data[name] < alertCount)
then
domoticz.data[name] = domoticz.data[name] + 1
domoticz.notify('La ventana ' .. name .. ' ha estado ' .. minutes .. ' minutos abierta.', domoticz.PRIORITY_HIGH)
domoticz.log('AVISO #' .. tostring(domoticz.data[name]))
end
elseif (domoticz.data[name] > 0) then
domoticz.notify('La ventana ' .. name .. ' está cerrada de nuevo.', domoticz.PRIORITY_HIGH)
domoticz.log('La ventana ' .. name .. ' está ' .. minutes .. ' cerrada.')
domoticz.data[name] = 0
end
end
end
}The syntax used here for domoticz.notify is wrongruny wrote: Tuesday 17 November 2020 11:49 I'm using the original script but the notification send by Telegram is always "1", this is my code:
change the notification in your script tonotify(subject, message [,priority][,sound][,extra][,subsystem][,delay] ): Function. Send a notification (like Prowl). Priority can be like domoticz.PRIORITY_LOW, PRIORITY_MODERATE, PRIORITY_NORMAL, PRIORITY_HIGH, PRIORITY_EMERGENCY. extra is notification subsystem specific. For NSS_FIREBASEyou can specify the target mobile (‘midx_1’, midx_2, etc..). For sound see the SOUND constants below. subsystem can be a table containing one or more notification subsystems. See domoticz.NSS_subsystem types. Delay is delay in seconds
Code: Select all
domoticz.notify('Door notification','La ventana ' .. name .. ' ha estado ' .. minutes .. ' minutos abierta.', domoticz.PRIORITY_HIGH)