Did I leave the door open? [SOLVED]
Moderator: leecollings
- felix63
- Posts: 244
- Joined: Monday 07 December 2015 9:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.1
- Location: Gouda
- Contact:
Re: Did I leave the door open?
What does your log show?
-
- Posts: 167
- Joined: Thursday 28 December 2017 14:38
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Broek op Langedijk
- Contact:
Re: Did I leave the door open?
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
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Did I leave the door open?
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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 167
- Joined: Thursday 28 December 2017 14:38
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Broek op Langedijk
- Contact:
Re: Did I leave the door open?
Case matters indeed. I change the capital and it looks likt it works fine now! Thanx for the help. This is my code now:
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
}
Re: Did I leave the door open?
Yes sorry, I didn't receive notification of your message.
I did the following :
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
}
- felix63
- Posts: 244
- Joined: Monday 07 December 2015 9:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.1
- Location: Gouda
- Contact:
Re: Did I leave the door open?
Great! Thanks.. great addition to the script.
Re: Did I leave the door open?
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.
But I have so many things to do in Domoticz that I'm not that willing to touch something that is already functionning :-p
-
- Posts: 48
- Joined: Thursday 01 June 2017 8:44
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Latest
- Location: Netherlands
- Contact:
Re: Did I leave the door open?
Hi there,
Hope there is still support on this item.
I am using the script from post 1 combined with the telegram notification fix.
The script is almost working fine except for the fact that the warning notifications don''s stop after 3 times.
I hope someone can tell me where I have made an error?
Greetings,
Harald
Hope there is still support on this item.
I am using the script from post 1 combined with the telegram notification fix.
The script is almost working fine except for the fact that the warning notifications don''s stop after 3 times.
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
}
Greetings,
Harald
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Did I leave the door open?
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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 48
- Joined: Thursday 01 June 2017 8:44
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Latest
- Location: Netherlands
- Contact:
Re: Did I leave the door open? [SOLVED]
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 }
Thanks for the advice, working flawlessly now.
Great.
Greetings, Harald
Re: Did I leave the door open?
Nice script and it works fine!
i tried to change something, but i need a little help. DZevents is new for me...
I have addes this:
if alertCount = '3' then
domoticz.devices('ToonApiLib - Scene').switchSelector(30)
dz.notify('Verwarming gaat lager in tempratuur',dz.PRIORITY_HIGH)
This is the error:
2020-01-18 19:34:42.268 Error: dzVents: Error: (2.4.29) error loading module 'deuropen_verwaming_uit' from file '/home/pi/domoticz/scripts/dzVents/generated_scripts/deuropen_verwaming_uit.lua':
2020-01-18 19:34:42.268 ...pts/dzVents/generated_scripts/deuropen_verwaming_uit.lua:41: 'then' expected near '='
i tried to change something, but i need a little help. DZevents is new for me...
I have addes this:
if alertCount = '3' then
domoticz.devices('ToonApiLib - Scene').switchSelector(30)
dz.notify('Verwarming gaat lager in tempratuur',dz.PRIORITY_HIGH)
This is the error:
2020-01-18 19:34:42.268 Error: dzVents: Error: (2.4.29) error loading module 'deuropen_verwaming_uit' from file '/home/pi/domoticz/scripts/dzVents/generated_scripts/deuropen_verwaming_uit.lua':
2020-01-18 19:34:42.268 ...pts/dzVents/generated_scripts/deuropen_verwaming_uit.lua:41: 'then' expected near '='
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
}
Domoticz latest stable, Intel NUC, Proxmox, Zigate, RFLink, Kaku switches, Ikea lights, Xiaomi sensors, Honeywell smoke detectors, Yeelight, Shelly, Slave Domoticz PI 3B+, Node-Red, Espeasy.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Did I leave the door open?
change to
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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Re: Did I leave the door open?
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.
What i want is, that after 3 warning the heating is going lower. And a notifacation what happend.
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
}
Domoticz latest stable, Intel NUC, Proxmox, Zigate, RFLink, Kaku switches, Ikea lights, Xiaomi sensors, Honeywell smoke detectors, Yeelight, Shelly, Slave Domoticz PI 3B+, Node-Red, Espeasy.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Did I leave the door open?
Made some corrections in the code and commented the lines with problems. Not tested so could be that you stil encounter something
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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Re: Did I leave the door open?
Thanks, it works!!
Mark
Mark
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 something
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 }
Domoticz latest stable, Intel NUC, Proxmox, Zigate, RFLink, Kaku switches, Ikea lights, Xiaomi sensors, Honeywell smoke detectors, Yeelight, Shelly, Slave Domoticz PI 3B+, Node-Red, Espeasy.
-
- Posts: 5
- Joined: Sunday 29 September 2019 20:10
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Did I leave the door open?
Thanks for this great script, works perfectly.
The only thing I don't know is how to set some sort of alias for the device so my notification looks cleaner?
I like to name my devices very specific in the device section, so I know where I use the device for.
The only downside is that the names are long and not very clean for notifications.
I can of course change the notification manually, but that is not the most convenient way to do it!
Can someone help me with this?
The only thing I don't know is how to set some sort of alias for the device so my notification looks cleaner?
I like to name my devices very specific in the device section, so I know where I use the device for.
The only downside is that the names are long and not very clean for notifications.
I can of course change the notification manually, but that is not the most convenient way to do it!
Can someone help me with this?
- felix63
- Posts: 244
- Joined: Monday 07 December 2015 9:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.1
- Location: Gouda
- Contact:
Re: Did I leave the door open?
Hi,
You could try this version of the script. Too lazy to test but should work,
You could try this version of the script. Too lazy to test but should work,
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
}
-
- Posts: 11
- Joined: Monday 28 January 2019 15:21
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Did I leave the door open?
Hi
I'm using the original script but the notification send by Telegram is always "1", this is my code:
I'm using the original script but the notification send by Telegram is always "1", this is my code:
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
}
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Did I leave the door open?
The syntax used here for domoticz.notify is wrong
From the wiki
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)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 11
- Joined: Monday 28 January 2019 15:21
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Did I leave the door open?
Thanks mate!!!
Who is online
Users browsing this forum: No registered users and 1 guest