dzvents newbie

Easy to use, 100% Lua-based event scripting framework.
Post Reply
hmjgriffon
Posts: 11
Joined: Friday 20 January 2017 22:39
Target OS: Raspberry Pi
Domoticz version:
Contact:

dzvents newbie

Post by hmjgriffon » Friday 13 July 2018 21:03

I tried looking through posts but there are a lot. I have some scripts written in lua, just recently found out about dzvents, well, I'm not a programmer and my system is very limited because the old lua was too hard for me to figure out. I started looking at dzvents, I've read through the documentation, watched the quick start video, and I've got a script together. This simply sets off a siren, notifies the mobile app and triggers various cameras in blue iris, I am not at home to test this yet but I wanted to see if anyone could look it over and see if I have made any obvious mistakes, much appreciated. I only have one camera in there because if this works I can easily add the rest.

Code: Select all

return {
	active = true,
	on = {
		devices = {
			'Front Door',
			'Back Door'
		},
	},
	execute = function(domoticz, door)
		if (door.state == 'Open') and domoticz.security('Armed Home') or domoticz.security('Armed Away') then
			domoticz.devices('Siren').switchOn()
			domoticz.log('The '..door..' was opened!')
			domoticz.notify('The '..door..' was opened!', domoticz.PRIORITY_EMERGENCY, domoticz.SOUND_SIREN)
			local BiLogin = 'user=USERNAME&pw=PASSWORD'
			domoticz.openURL('http://10.0.0.124/admin?camera=Kitchen&trigger&'..BiLogin..'')
		end

	end
}

User avatar
waaren
Posts: 1220
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents newbie

Post by waaren » Friday 13 July 2018 22:38

@hmjgriffon,

from a quick look I only see two obvious mistakes. In domoticz.log en domoticz.notify you use door, but door is there a device object. I think you want door.name .
I am not sure that the logic you use in the if is going to deliver what you want. Maybe an extra pair of () will help. But just a small test will show how the and and or behave in this line.
You end the domoticz.openURL with a concatenation of an empty string. Probably it will not mess things up but why do you use this ?

BTW: I learned (and still learn) a lot from solving my own coding mistakes.
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

hmjgriffon
Posts: 11
Joined: Friday 20 January 2017 22:39
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: dzvents newbie

Post by hmjgriffon » Saturday 14 July 2018 0:51

waaren wrote:
Friday 13 July 2018 22:38
@hmjgriffon,

from a quick look I only see two obvious mistakes. In domoticz.log en domoticz.notify you use door, but door is there a device object. I think you want door.name .
I am not sure that the logic you use in the if is going to deliver what you want. Maybe an extra pair of () will help. But just a small test will show how the and and or behave in this line.
You end the domoticz.openURL with a concatenation of an empty string. Probably it will not mess things up but why do you use this ?

BTW: I learned (and still learn) a lot from solving my own coding mistakes.
I figured it out once I got home, found more examples and experimented, thanks! Now to re-write my next script, LOL! For anyone that cares, here it is now, tested and working.

Code: Select all

return {
    active = true,
    on = {
		devices = {
			'*Door',
		},
	},
	execute = function(domoticz, device)
		if (device.state == 'Open') and (domoticz.security ~= domoticz.SECURITY_DISARMED) then
			domoticz.devices('Siren').switchOn()
			domoticz.log('The '..device.name..' was opened!')
			domoticz.notify('The '..device.name..' was opened!', domoticz.PRIORITY_EMERGENCY, domoticz.SOUND_SIREN)
			local BiLogin = 'user=USERNAME&pw=PASSWORD'
			domoticz.openURL('http://10.0.0.124/admin?camera=Kitchen&trigger&'..BiLogin..'')
		end

	end
}

Post Reply

Who is online

Users browsing this forum: ronaldbro and 1 guest