triggerInfo.trigger for device change?

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

Moderator: leecollings

Post Reply
anasazi
Posts: 43
Joined: Saturday 06 August 2016 9:53
Target OS: Windows
Domoticz version:
Location: Sweden
Contact:

triggerInfo.trigger for device change?

Post by anasazi »

Hi,

According to the dzVents wiki, triggerInfo.trigger only works for timer rules and for security state.
Is it possible to use this when devices changes also?

Check the example script below, is this possible?

Code: Select all

return {

	active = true,

	on = {
		security = {
			domoticz.SECURITY_ARMEDAWAY,
			domoticz.SECURITY_DISARMED,
		},
		devices = {
			'$Alarm - Detekterat',
		},

	},

	execute = function(domoticz, device, triggerInfo)

		if (triggerInfo.trigger == domoticz.SECURITY_ARMEDAWAY) then
			domoticz.devices('$Alarm - Delay Active').switchOn().forMin(1)
            		domoticz.devices('Siren').switchOn().forSec(1)
				
		elseif (triggerInfo.trigger == domoticz.SECURITY_DISARMED) then
			domoticz.devices('$Alarm - Siren Trigger').switchOff()
			domoticz.devices('$Alarm - Detekterat').switchOff()
			domoticz.devices('Siren').switchOff()
			domoticz.devices('$Alarm - Delay Active').switchOff()
			
		elseif (triggerInfo.trigger == '$Alarm - Detekterat') then
			if (device.state == 'On') then
				domoticz.devices('$Alarm - Siren Trigger').switchOn().afterSec(30)
				domoticz.devices('Siren').switchOn().forSec(1)
			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: triggerInfo.trigger for device change?

Post by emme »

Use device.name
The most dangerous phrase in any language is:
"We always done this way"
SweetPants

Re: triggerInfo.trigger for device change?

Post by SweetPants »

anasazi wrote: Wednesday 17 January 2018 13:19 Hi,

According to the dzVents wiki, triggerInfo.trigger only works for timer rules and for security state.
Is it possible to use this when devices changes also?

Check the example script below, is this possible?

Code: Select all

return {

	active = true,

	on = {
		security = {
			domoticz.SECURITY_ARMEDAWAY,
			domoticz.SECURITY_DISARMED,
		},
		devices = {
			'$Alarm - Detekterat',
		},

	},

	execute = function(domoticz, device, triggerInfo)

		if (triggerInfo.trigger == domoticz.SECURITY_ARMEDAWAY) then
			domoticz.devices('$Alarm - Delay Active').switchOn().forMin(1)
            		domoticz.devices('Siren').switchOn().forSec(1)
				
		elseif (triggerInfo.trigger == domoticz.SECURITY_DISARMED) then
			domoticz.devices('$Alarm - Siren Trigger').switchOff()
			domoticz.devices('$Alarm - Detekterat').switchOff()
			domoticz.devices('Siren').switchOff()
			domoticz.devices('$Alarm - Delay Active').switchOff()
			
		elseif (triggerInfo.trigger == '$Alarm - Detekterat') then
			if (device.state == 'On') then
				domoticz.devices('$Alarm - Siren Trigger').switchOn().afterSec(30)
				domoticz.devices('Siren').switchOn().forSec(1)
			end
        end
	end
}
I'm using if (triggerinfo.type == domoticz.EVENT_TYPE_DEVICE) then with dzVentz 2.3.0
anasazi
Posts: 43
Joined: Saturday 06 August 2016 9:53
Target OS: Windows
Domoticz version:
Location: Sweden
Contact:

Re: triggerInfo.trigger for device change?

Post by anasazi »

emme wrote: Wednesday 17 January 2018 13:57Use device.name
Hi,

I have tried with device.name in combination with infoTrigger.info and it's woking, thanks!
Then I tried to add more devices and I added a wild-card device but this won't work when using device.name, see the example script below what I mean...

is this supposed to work or am I writing the script wrong?

Code: Select all

return {

	active = true,

	on = {
		security = {
			domoticz.SECURITY_ARMEDAWAY,
			domoticz.SECURITY_DISARMED,
		},
		devices = {
			'*dörren',
		},

	},

	execute = function(domoticz, device, triggerInfo)

		if (triggerInfo.trigger == domoticz.SECURITY_ARMEDAWAY) then
			domoticz.devices('$Alarm - Delay Active').switchOn().forMin(1)
            		domoticz.devices('Siren').switchOn().forSec(1)
			
		elseif (triggerInfo.trigger == domoticz.SECURITY_DISARMED) then
			domoticz.devices('$Alarm - Siren Trigger').switchOff()
			domoticz.devices('$Alarm - Detekterat').switchOff()
		    	domoticz.devices('Siren').switchOff()
		    	domoticz.devices('$Alarm - Delay Active').switchOff()
			
		elseif (device.name == '*dörren') then
			if (device.state == 'On') then
				domoticz.devices('$Alarm - Siren Trigger').switchOn().afterSec(30)
				domoticz.devices('Siren').switchOn().forSec(1)
			end
        end
	end
}
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: triggerInfo.trigger for device change?

Post by dannybloe »

Looks good to me, give it a try.. hire some burglars perhaps to help...
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: triggerInfo.trigger for device change?

Post by waaren »

Can you change

Code: Select all

elseif (device.name == '*dörren') then
into

Code: Select all

elseif string.find(device.name,'dörren') ~= nil then
and report back what the result is ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
anasazi
Posts: 43
Joined: Saturday 06 August 2016 9:53
Target OS: Windows
Domoticz version:
Location: Sweden
Contact:

Re: triggerInfo.trigger for device change?

Post by anasazi »

Hi,

I will try with your recommendations this weekend.
Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest