Page 1 of 1

Double events?

Posted: Tuesday 31 October 2017 8:33
by cyclops1982
Hi,

I'm currently running the below script, but am getting double notifications.
I have a small remote control, that triggers the scene. When that happens, i will get 2 notification e-mails. I'm not sure if this is just the remote control triggering the scene multiple times, or the script being wrong, or dzVents not working 100% correctly.

Code: Select all

return {
	active = true,
	on = {
		devices = {
			'Alarm:*',
			'$Alarm:*',
			'Sensor*',
			'$Sensor*'
		},
		variables = {
			'Alarm:*'
		},
		security = {
			domoticz.SECURITY_ARMEDAWAY,
			domoticz.SECURITY_ARMEDHOME,
			domoticz.SECURITY_DISARMED 
		},
		scenes = {
			'Scene:*'
		}
	},
	logging = {
		level = domoticz.LOG_DEBUG,
		marker = ' === SECURITY SCRIPT ==='
	},
	execute = function(domoticz, device, triggerInfo)
		-- If the security panel triggers the event, then we find it and set our device to it
		if triggerInfo.type == domoticz.EVENT_TYPE_SECURITY then
			device = domoticz.devices().find(function(dev)
				return dev.hardwareTypeValue == 67
			end)
		end
		local alarmVariable = domoticz.variables('Alarm:Timer')
		local securityPanel = domoticz.devices('Alarm: Security Panel')
		local alarmActive = domoticz.devices('Alarm: Active')

		-- Using scene's to arm/disarm so we can bind it to the buttons
		if device.name == 'Scene: Button 2 - Disarm / back home' and device.state == 'On' then
			if domoticz.security ~= 'Disarmed' then
				domoticz.log('Button 2 on remote pressed. Disarming!')
				securityPanel.disarm()
			end
		end
		if device.name == 'Scene: Button 1 - Arm / leave home' and device.state == 'On' then
			if domoticz.security == 'Disarmed' then
				domoticz.log('Button 1 on remote pressed. Armed Away!')
				securityPanel.armHome()
			end
		end
	
		-- Security panel is being disarmed.
		if device.name == 'Alarm: Security Panel' then
			domoticz.notify('Alarm panel changed', 'The Security Panel was ' .. device.state, PRIORITY_LOW)
			if  device.state == domoticz.SECURITY_DISARMED then
				alarmActive.setState('Off')
			end
		end


		-- Detect movement
		if domoticz.security ~= 'Disarmed' then	
			if string.find(device.name, '.?Sensor.*Burglar$') ~= nil and device.state == 'On' then
				-- TODO: play a sound
				alarmVariable.set(1).afterSec(15)
			end
			if string.find(device.name, '.?Sensor1: Burglar$') ~= nil and device.state == 'On' then
				domoticz.sendCommand('SendCamera:1', 'Somebody entered the house!')
			end
			if string.find(device.name, '.?Sensor2: Burglar$') ~= nil and device.state == 'On' then
				domoticz.notify('Somebody entered the house!', 'Somebody entered the back of the house while the alarm is armed!', PRIORITY_HIGH, SOUND_INCOMING)
			end
		end
		
		if device.name == 'Alarm:Timer' and device.value == 1 then
			alarmVariable.set(0);
			
			if domoticz.security ~= 'Disarmed' then
				alarmActive.setState('On')
			end
		end

		if device.name == 'Alarm: Active' then
			domoticz.log('===== ALARM ACTIVE STATE: ' .. device.state)
			if device.state == 'On' then
				domoticz.notify('Sounding the alarm!', 'We would be sounding the alarm now!',PRIORITY_HIGH, SOUND_INCOMING)
				domoticz.sendCommand('SendCamera:1', 'This is the image!')
				---domoticz.devices('$SmokeDetector1: Switch').setState('On')
			end
			if device.state == 'Off' and device.changed == true then
				domoticz.notify('Alarm turned off', 'The alarm sounded but is now turned off!',PRIORITY_LOW, SOUND_INCOMING)
				---domoticz.devices('$SmokeDetector1: Switch').setState('Off')
			end
		end

	end
}

Re: Double events?

Posted: Tuesday 31 October 2017 8:53
by emme
try adding a log line with triggerInfo.type... that will show you who has triggered the script

Re: Double events?

Posted: Tuesday 31 October 2017 9:33
by dannybloe
You can turn on debug logging in Domoticz settings to see what is going on here. There should be trigger reasons in the log as well in this mode telling you exactly what kind of event triggered dzVents. So please do some investigation and try to figure out what causes the double events. Perhaps by creating smaller scripts with less on-triggers.
That's the only way to see if there is a bug somewhere.

Re: Double events?

Posted: Tuesday 31 October 2017 16:16
by cyclops1982
Thanks. I'll have a look if the triggertype will work.
There's quite a lot of output, as there are triggers causing other things to trigger. Which makes it confusing.

I'll update when i know more :)

Re: Double events?

Posted: Saturday 02 December 2017 15:45
by rbisschops
Hi All,

Was this resolved already? I have a simple script that triggers on a dummy switch. When I trigger the switch (on or off) the script is executed multiple times (more then twice, it looks like it keeps going on for more then 15 times). The trigger event is every time the same sofor example Handling events for: "VirtualHeating", value: "Off" or Handling events for: "VirtualHeating", value: "On"

Even after commenting all the content of the execute part, this still happens.

Dzvents is version 2.2.0

Thx

Ralph

Re: Double events?

Posted: Saturday 02 December 2017 16:10
by dannybloe
Still, turn on debug logging and examine the logs. It should give you all info that dzVents gets from Domoticz regarding events. But if you comment out the entire execute then it is clearly not because of it. Maybe something else triggers the device multiple times.

Re: Double events?

Posted: Tuesday 05 December 2017 8:13
by rbisschops
@dannybloe: Strange thing. I replaced the complete contents of the dzVents folder. Now it works fine.

Edit: Althoug viewtopic.php?f=6&t=20237&p=156431&hilit=rpi3#p156431 explains this behaviour, so might be coincidence that it looked to be working again (version: 3.8.153 on my side). Might have been there before 3.8.699 and showing up as i'm running on a RPi3 (faster CPU). Did not see it on an RPi2 running the same version, same RPi config and even same database.