simple dzVents script

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

Moderator: leecollings

Post Reply
User avatar
dk78
Posts: 26
Joined: Monday 07 March 2016 15:50
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Veldhoven
Contact:

simple dzVents script

Post by dk78 »

I'm new with dzVents and I'm trying to create my first simple script with it. I think it's far more powerful then the basic lua. But i'm having some issues with some triggers and need some help.

I think it's a very simple script, but I'm not sure that I use the correct timer triggers. I want to turn on my hallway light when the front door is open. But only during nighttime. When the door is closed, the light must go off after 30 seconds. First I had this:

Code: Select all

return {
	active = true,
	on = {
		devices = {
			'front door'
		},
		timer = {
			'at nighttime'
		},
	},

	execute = function(domoticz, door)
		local light = domoticz.devices('Hallway')
		
		if (door.state == 'Open') then
			light.switchOn()
		else
			light.switchOff().afterSec(30)
		end

	end
}
But then the light will stay on during nighttime if i'm correct. Because of the timer in the on section.

So now I thought of this script, but I'm not sure how to use the boolean 'domoticz.time.atNightTime'. So should this do the trick?

Code: Select all

return {
	active = true,
	on = {
		devices = {
			'front door'
		},
	},

	execute = function(domoticz, door)

		local light = domoticz.devices('Hallway')
		
		if (domoticz.time.isNightTime and door.state == 'Open') then
			light.switchOn()
		else
			light.switchOff().afterSec(30)
		end

	end
}
I tried to found some examples, but I haven't found any.

I'm not sure if I'm doing this correct. Should I let the door trigger this script or the timer?
Last edited by dk78 on Friday 28 July 2017 14:37, edited 1 time in total.
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: simple dzVents script

Post by dannybloe »

Ok, your first attempt wasn't correct indeed. What you did was creating two independent triggers: a device trigger and a timer trigger. They have no connection with each other. If the door is opened, the script is triggered but also every minute at nighttime.

So clearly that is not what you wanted.

Your seconds attempt creates only one trigger and causes your script to be executed if the door is opened or when it is closed (change of state). I think you should change it a bit though:

Code: Select all

execute = function(domoticz, door)
	if (not domoticz.time.isNightTime) then return 
	
	local light = domoticz.devices('Hallway')
      
	if (door.state == 'Open') then
		light.switchOn()
	else
		light.switchOff().afterSec(30)
	end
end
But, in your case it can even be simpler by setting a time rule on the device trigger:

Code: Select all

return {
	active = true,
	on = {
		devices = { 
			['front door'] = { 'at nighttime' }
		}
	},
	execute = function(domoticz, door)
		local light = domoticz.devices('Hallway')
      
		if (door.state == 'Open') then
			light.switchOn()
		else
			light.switchOff().afterSec(30)
		end
	end
}
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
User avatar
dk78
Posts: 26
Joined: Monday 07 March 2016 15:50
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Veldhoven
Contact:

Re: simple dzVents script

Post by dk78 »

Thanks! Your last script is the script what I thought to do with my first.

I'm going to rewrite my scripts to dzVents. See many powerfull things without any dummy switches that I use at the moment.
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: simple dzVents script

Post by dannybloe »

Good luck!
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
User avatar
dk78
Posts: 26
Joined: Monday 07 March 2016 15:50
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Veldhoven
Contact:

Re: simple dzVents script

Post by dk78 »

How does it work if you want to execute the script with 2 device triggers? I thought I copy the syntax, but this won't work:

Code: Select all

   on = {
      devices = {
         ['Status'] = { 'at nighttime' }
         ['Luxsensor'] = { 'at nighttime' }
      }
   },
Tried also to put both devices between the [] but that isn't the solution either.
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: simple dzVents script

Post by dannybloe »

there is a comma missing between the two devices items.

Code: Select all

   on = {
      devices = {
         ['Status'] = { 'at nighttime' }, -- comma
         ['Luxsensor'] = { 'at nighttime' }
      }
   },
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
User avatar
dk78
Posts: 26
Joined: Monday 07 March 2016 15:50
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Veldhoven
Contact:

Re: simple dzVents script

Post by dk78 »

Ah, that makes sense. I was looking at {} and [] ' ' but missed the comma. Thanks again!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest