send an email when the doorbell rings and is not opened within 1 minute.

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
DDuck
Posts: 4
Joined: Wednesday 04 April 2018 15:47
Target OS: Windows
Domoticz version:
Contact:

send an email when the doorbell rings and is not opened within 1 minute.

Post by DDuck »

Hi,
I am new to Domoticz.
I have a thin client at home with Windows7 running domoticz.
it is connected with an RF link and Xiaomi gateway, switch, smart switches and door sensors are present.

I have been trying to get a script working that will send me a mail if the front door does not open within 1 minute after someone has pressed the bell
the hard part is to not send a mail if the door opens on time.
[

Code: Select all

return {
	on = {
		devices = {'Bel', 'Door1'
		}
	},
	execute = function(dz, device)
	  if (device.state == 'On') then
		dz.log('Device ' .. device.name .. ' was changed- so sombody ring it', dz.LOG_INFO)
	    dz.mail('subject', 'message tekst','[email protected]').AfterMin(2)
	  end
	  if (dz.devices('Door1').state == 'Open') then
		dz.log('Device ' .. device.name .. ' was changed- so sombody opend the door', dz.LOG_INFO)
        dz.mail.cancelQueuedCommands()
      end
	end
}
i get this error:
2018-04-04 16:14:15.936 User: Admin initiated a switch command (77/Bel/On)
2018-04-04 16:14:15.962 (Dummy) Light/Switch (Bel)
2018-04-04 16:14:16.670 dzVents: Info: Handling events for: "Bel", value: "On"
2018-04-04 16:14:16.671 dzVents: Info: ------ Start internal script: test-deurbel: Device: "Bel (Dummy)", Index: 77
2018-04-04 16:14:16.671 dzVents: Info: Device Bel was changed- so sombody ring it
2018-04-04 16:14:16.671 dzVents: Error (2.4.2): An error occured when calling event handler test-deurbel
2018-04-04 16:14:16.671 dzVents: Error (2.4.2): ...oticz\scripts\dzVents\generated_scripts/test-deurbel.lua:9: attempt to call field 'mail' (a nil value)
2018-04-04 16:14:16.672 dzVents: Info: ------ Finished test-deurbel

if i thak line 9 out it is line 11 on error. Please Help me understand
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: send an email when the doorbell rings and is not opened within 1 minute.

Post by Egregius »

Isn't this a dzvents script? Shouldn't this be posted in the dzvents board?
Anyway, in pass2php fairly simple to handle :lol:

Code: Select all

<?php
sleep(60);
if(past('doorsensor')<60)mail('Doorbell pressed');
?>
DDuck
Posts: 4
Joined: Wednesday 04 April 2018 15:47
Target OS: Windows
Domoticz version:
Contact:

Re: send an email when the doorbell rings and is not opened within 1 minute.

Post by DDuck »

Egregius wrote: Wednesday 04 April 2018 18:06 Isn't this a dzvents script? Shouldn't this be posted in the dzvents board?
Anyway, in pass2php fairly simple to handle :lol:

Code: Select all

<?php
sleep(60);
if(past('doorsensor')<60)mail('Doorbell pressed');
?>
Is the system taking any other commands while waiting/running this script??
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: send an email when the doorbell rings and is not opened within 1 minute.

Post by waaren »

DDuck wrote: Wednesday 04 April 2018 16:17 Hi,
I am new to Domoticz.
I have a thin client at home with Windows7 running domoticz.
it is connected with an RF link and Xiaomi gateway, switch, smart switches and door sensors are present.

I have been trying to get a script working that will send me a mail if the front door does not open within 1 minute after someone has pressed the bell
the hard part is to not send a mail if the door opens on time.

2018-04-04 16:14:16.671 dzVents: Error (2.4.2): ...oticz\scripts\dzVents\generated_scripts/test-deurbel.lua:9: attempt to call field 'mail' (a nil value)

if I thake line 9 out it is line 11 on error. Please Help me understand
dz.mail is not dzVents syntax and afterSec / afterMin is not implemented for .email so we need something to help us. My way is to use a uservar for this (see code example)

Code: Select all

--[[ 
		Conditional Delayed Email test (dzVents > 2.4.0 )
]]--


return {
	on = { devices = { 'Bel' },
	variables = { 'emailTrigger_for_Door1' } -- Need to be defined once via setup -> more options -> uservariables (as integer)
	},

	execute = function(dz, trigger)
	  	if trigger.isVariable then
			if dz.devices('Door1').lastUpdate.secondsAgo < dz.devices('Bel').lastUpdate.secondsAgo then
				-- Door1 opened after Bel rang so no further action necessary
				dz.log("Door1 opened after Bel rang so no further action necessary", dz.LOG_INFO)
			else
				dz.log("Door1 not opened in time sending Email", dz.LOG_INFO)
				dz.email('Hey', 'Why has no one opened the door ??', 'your Email address')
				dz.variables('emailTrigger_for_Door1').set(0).silent()
			end
		else
            -- domoticz Email afterSec not implemented so we need a uservariable to help us
			dz.variables('emailTrigger_for_Door1').set(1).afterSec(60)
		end
	end
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
DDuck
Posts: 4
Joined: Wednesday 04 April 2018 15:47
Target OS: Windows
Domoticz version:
Contact:

Re: send an email when the doorbell rings and is not opened within 1 minute.

Post by DDuck »

Hi Waaren,

thanks for your help, the uservar's are a very interesting way of getting to the point.
I'm going to look into them next day's. for now the script is working. many thanks for that.
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: send an email when the doorbell rings and is not opened within 1 minute.

Post by Egregius »

DDuck wrote: Wednesday 04 April 2018 20:00
Egregius wrote: Wednesday 04 April 2018 18:06 Isn't this a dzvents script? Shouldn't this be posted in the dzvents board?
Anyway, in pass2php fairly simple to handle :lol:

Code: Select all

<?php
sleep(60);
if(past('doorsensor')<60)mail('Doorbell pressed');
?>
Is the system taking any other commands while waiting/running this script??
Of course, why wouldn't it?
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest