Did I leave the door open?

Post Reply
User avatar
felix63
Posts: 164
Joined: Monday 07 December 2015 10:30
Target OS: Raspberry Pi
Domoticz version: 3.8275
Location: Gouda
Contact:

Did I leave the door open?

Post by felix63 » Friday 08 June 2018 15:15

A DzVents script to check to see if doors have been left open for too long. Both the number of doors and the threshold for reporting on a door are easily changed my adjusting the values in the table at the beginning of the script. The table 'devicesToCheck' needs to contain the exact names of your door switches. To prevent you going nuts the warnings will stop once the amounts of warning per door exceeds the variable alerCount.

Code: Select all


local devicesToCheck = {
--  table with doors to check and the minutes before the first warning is given
	{ ['name'] = 'Voordeur', ['threshold'] = 3 },
	{ ['name'] = 'Garagedeur', ['threshold'] = 10 },
	{ ['name'] = 'Achterdeur', ['threshold'] = 3 },
	{ ['name'] = 'Provisiekast deur', ['threshold'] = 10 },
	{ ['name'] = 'Bergingdeur', ['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},
        ['Garagedeur'] = {initial=0},
        ['Achterdeur'] = {initial=0},
        ['Provisiekast deur'] = {initial=0},
        ['Bergingdeur'] = {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('Device ' .. 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('Device ' .. name .. ' is weer gesloten.', domoticz.PRIORITY_HIGH)
                domoticz.log('Device ' .. name .. ' is  ' .. minutes .. ' dicht.')
			    domoticz.data[name] = 0
			end
		end
	end
}

User avatar
felix63
Posts: 164
Joined: Monday 07 December 2015 10:30
Target OS: Raspberry Pi
Domoticz version: 3.8275
Location: Gouda
Contact:

Re: Did I leave the door open?

Post by felix63 » Sunday 08 July 2018 12:59

Updated the script above to give a notification if the door is closed again....

hoeby
Posts: 50
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi
Domoticz version: V4.9700
Location: Echt, Netherlands
Contact:

Re: Did I leave the door open?

Post by hoeby » Thursday 02 August 2018 20:13

I used your nice script.
But on the first try it didn't work.
I am using telegram for notification. When the IF = TRUE, i only got a "1" in the telegram message.
Therefor i changed your script to this

Code: Select all

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)
What changed?:
I added 'Herinnering-open', and 'Herinnering-dicht', to the notify message.
Personal thing, i removed the devices tekst in de notify script, this had nothing to do with the problem i noticed.
Don't know if this adding gives problems to other notification options. But on telegram this works, now i nicely get "name .. ' staat al langer dan ' .. minutes .. ' minuten open. or name .. ' is weer gesloten.

vwtune
Posts: 7
Joined: Wednesday 24 January 2018 10:13
Target OS: Raspberry Pi
Domoticz version:
Location: Nederland
Contact:

Re: Did I leave the door open?

Post by vwtune » Friday 24 August 2018 15:15

Thanks for your script.

only the alertcount don't work. if i change the number in 4, 5 or whatever, it still gives me more messages that the door is open, till i close the door, then the alerts stopts. What is wrong with the script?

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest