Double events?

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
cyclops1982
Posts: 13
Joined: Monday 20 March 2017 13:28
Target OS: -
Domoticz version:
Contact:

Double events?

Post 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
}
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Double events?

Post by emme »

try adding a log line with triggerInfo.type... that will show you who has triggered the script
The most dangerous phrase in any language is:
"We always done this way"
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Double events?

Post 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.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
cyclops1982
Posts: 13
Joined: Monday 20 March 2017 13:28
Target OS: -
Domoticz version:
Contact:

Re: Double events?

Post 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 :)
User avatar
rbisschops
Posts: 63
Joined: Monday 12 May 2014 11:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.2563
Location: Schiedam, Netherlands
Contact:

Re: Double events?

Post 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
RPi 3B (master): RFXtrx433, Harmony Hub, Z-Wave devices, CoCo units, Hue, Xiaomi Aquara
RPi 2B (slave): P1 connection, MySensors with custom built watermeter sensors on Aquadis+
RPi’s with: Mosquitto MQTT, Home Bridge, Home Assistant (for evaluation only)
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Double events?

Post 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.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
User avatar
rbisschops
Posts: 63
Joined: Monday 12 May 2014 11:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.2563
Location: Schiedam, Netherlands
Contact:

Re: Double events?

Post 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.
RPi 3B (master): RFXtrx433, Harmony Hub, Z-Wave devices, CoCo units, Hue, Xiaomi Aquara
RPi 2B (slave): P1 connection, MySensors with custom built watermeter sensors on Aquadis+
RPi’s with: Mosquitto MQTT, Home Bridge, Home Assistant (for evaluation only)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest