Page 1 of 1

Double Check me.

Posted: Sunday 11 June 2017 22:31
by kchest
Hello,
I am new (but enthusiastic) to writing DzVents scripts and wanted to ensure that my first one is correct. My goal is to have the bedroom rolladen (blinds) lower to 40% if the room temperature is above 26degrees celsius and only between 1pm and 7pm. If the temperature ever drops to below 26 degrees then the rolladen should open (only if they are already in a 'closed' state). Here is my script:

Code: Select all


local Time = require('Time')
local t = Time()


return {
	active = true,           
	on = {
		devices = {
			'SZ Temperature'
		}
	},

	execute = function(domoticz, device, triggerInfo) 
		if (domoticz.devices["SZ Temperature"].temperature > 26 and (t.matchesRule('at 13:00-19:00'))) then
			domoticz.devices['SZ Rolladen'].level(40)
		elseif (domoticz.devices["SZ Temperature"].temperature < 26 and domoticz.devices['SZ Rolladen'].state == 'Closed') then
			domoticz.devices ['SZ Rolladen'].open()
		end
	end
}
So far I have not seen any errors in the Domoticz log, which gives me hope. But that doesn't necessarily mean it will function properly! ;)

Re: Double Check me.

Posted: Monday 12 June 2017 13:05
by dannybloe
Hey.. are you running the dzVents-integration branch??? You are using unreleased features :)

That being said.. it looks good! Isn't that 'matchesRule()' great?
However, the final release will be slightly different as you now have to change

Code: Select all

domoticz.devices["SZ Temperature"]
into

Code: Select all

domoticz.devices("SZ Temperature")
That change makes it all a lot faster to execute.

Re: Double Check me.

Posted: Monday 12 June 2017 13:12
by dannybloe
Owh, one thing. You don't have to create a Time() object as you can use domoticz.time:

Code: Select all

domoticz.time.matchesRule(...)

Re: Double Check me.

Posted: Tuesday 13 June 2017 7:54
by kchest
dannybloe wrote:Hey.. are you running the dzVents-integration branch??? You are using unreleased features :)

That being said.. it looks good! Isn't that 'matchesRule()' great?
However, the final release will be slightly different as you now have to change

Code: Select all

domoticz.devices["SZ Temperature"]
into

Code: Select all

domoticz.devices("SZ Temperature")
That change makes it all a lot faster to execute.

I'm running the stable version of domoticz, v3.5877. It doesn't have dzVents integration so I installed it (v1.1.2) from GitHub. I have done a little Python programming in the past and I find dzVents to be similar - easy to learn, straight forward, natural language. You did a great job with it. I'm looking forward to creating some useful scripts.

I was very happy to find that "matchesRule()" function. It was a lifesaver!