Double Check me.

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

Moderator: leecollings

Post Reply
kchest
Posts: 5
Joined: Friday 17 July 2015 14:28
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Location: Germany
Contact:

Double Check me.

Post 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! ;)
Domoticz v3.8153
Raspberry Pi 2B
Aeotec Gen5 Zwave Stick
Mysensors USB Gateway
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Double Check me.

Post 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.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Double Check me.

Post 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(...)
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
kchest
Posts: 5
Joined: Friday 17 July 2015 14:28
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Location: Germany
Contact:

Re: Double Check me.

Post 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!
Domoticz v3.8153
Raspberry Pi 2B
Aeotec Gen5 Zwave Stick
Mysensors USB Gateway
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest