Introducing dzVents - Domoticz Lua file based event scripting made e-z!

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

Moderator: leecollings

dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by dannybloe »

Wroopy wrote:
dannybloe wrote:
dannybloe wrote:
Every time the script is executed it reads the persistent data and stores it when the script is finished. So each time the switch changes.
I just tested it here and it works with this script:

Code: Select all

return {
	active = true,
	on = {
		'mySensor'
	},
	data = {
		history = {history = true, maxItems = 10}
	},
	execute = function(domoticz, sensor)
		local reading = sensor.temperature
		domoticz.data.history.add(reading)
		local avg = domoticz.data.history.avg()
		local size = domoticz.data.history.size
		print(sensor.name .. ": last=" .. reading .. ", avg=" .. avg .. ", size= " .. size)
	end
}
and the data file is like this:

Code: Select all

-- Persistent Data
local multiRefObjects = {

} -- multiRefObjects
local obj1 = {
	["history"] = {
		[1] = {
			["time"] = "2016-10-19 09:45:59";
			["data"] = 16.799999237061;
		};
		[2] = {
			["time"] = "2016-10-19 09:45:58";
			["data"] = 16.799999237061;
		};
		[3] = {
			["time"] = "2016-10-19 09:45:30";
			["data"] = 16.799999237061;
		};
		[4] = {
			["time"] = "2016-10-19 09:45:29";
			["data"] = 16.799999237061;
		};
		[5] = {
			["time"] = "2016-10-19 09:44:59";
			["data"] = 16.799999237061;
		};
		[6] = {
			["time"] = "2016-10-19 09:44:58";
			["data"] = 16.799999237061;
		};
		[7] = {
			["time"] = "2016-10-19 09:44:29";
			["data"] = 16.799999237061;
		};
		[8] = {
			["time"] = "2016-10-19 09:44:28";
			["data"] = 16.799999237061;
		};
		[9] = {
			["time"] = "2016-10-19 09:43:59";
			["data"] = 16.799999237061;
		};
		[10] = {
			["time"] = "2016-10-19 09:43:58";
			["data"] = 16.89999961853;
		};
	};
}
return obj1

Are you sure that the script is called multiple times?
Yes I'm sure it is calles several times. I can see it both in Domoticz log and the timestamp of the item is changed in the storage-file.

I've tested to increase the logging, i.e. change ['Log level'] = 3 in dzVents_settings.lua too see if I would get som extra useful information. Got some very confusing result

1. The size of the history variable where increasing. So finally I got 10 items as expected.
2. Changed back to ['Log level'] = 2 and now I get only one hisory item.
3. Switch to level 3 again and it worked as expected.
4. Changed back to 2 and got only one history item.

Does that give any hint on what the problem could be?
Wow, that is certainly weird. I'd have to debug that. Can you PM me your entire script code?
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: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by dannybloe »

dannybloe wrote:
Wroopy wrote:
dannybloe wrote:
Wow, that is certainly weird. I'd have to debug that. Can you PM me your entire script code?
I cannot reproduce this. In my test the loglevel has no influence. :roll:
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Wroopy
Posts: 9
Joined: Tuesday 18 October 2016 22:06
Target OS: Linux
Domoticz version: v3.5745
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by Wroopy »

dannybloe wrote:
Wroopy wrote:
dannybloe wrote:
I just tested it here and it works with this script:

Code: Select all

return {
	active = true,
	on = {
		'mySensor'
	},
	data = {
		history = {history = true, maxItems = 10}
	},
	execute = function(domoticz, sensor)
		local reading = sensor.temperature
		domoticz.data.history.add(reading)
		local avg = domoticz.data.history.avg()
		local size = domoticz.data.history.size
		print(sensor.name .. ": last=" .. reading .. ", avg=" .. avg .. ", size= " .. size)
	end
}
Wow, that is certainly weird. I'd have to debug that. Can you PM me your entire script code?
To make sure I don't have ant race conditions, I've removed all other scripts and have only the script that you've tested with.

Still the same problem.

Tested with different loglevels and it is only when having log level 2 it doesn't work. :?
Glatzi
Posts: 13
Joined: Monday 19 September 2016 8:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by Glatzi »

dannybloe wrote:Yea you can set it to true if you start the stuff in th evening for the first time. That's an easy one ;)
Hi dannybloe,

just came back from vacation & quickly implemented your script. It works fine!
Thanks for your input!!!

What I'm still generally searching for is some kind of logic to distinguish if a switch was triggered by a PIR or manually trough the light button which triggers a Fibaro relay.
An example is that someone manually triggers a light switch in our hall. There also is a PIR. So although the switch is triggered manually the PIR detects the motion & the state in the dzVents table changes. So how can I differentiate this case for a proper handling?

Any input is really appreciated :-)
RPi3+UZB1,FIBARO FGMS001(9x),FIBARO FGD212,FIBARO FGRM222(6x),FIBARO FGSD002(1x),FIBARO FGWPE (3x),Neo CoolCam Power plug(5x),NodOn CRC-3-1 Remote(2x),Qubino ZMNHADx(1x),Qubino ZMNHDD1(2x),Z-Wave Weather Sensor(1x),Z-Wave ZME_WALLC-S,FIBARO System FGK10x
Glatzi
Posts: 13
Joined: Monday 19 September 2016 8:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by Glatzi »

Hi dannybloe,

can you please take a look at the latest beta of Domoticz? Something is going wrong with the scenes & dzEvents there. I'm getting the following error with all of my scenes:

Code: Select all

LUA: Cannot find the device. Skipping: KuecheLichtSchrank 1
2016-10-23_20-38-34.gif
2016-10-23_20-38-34.gif (42.11 KiB) Viewed 3619 times
I've deleted all scenes & recreated just the one above but the error remains. No more errors even in debug level 3.
I've also stopped Domoticz & deleted the devices.lua file so it can be build up from scratch but no luck at all :-(

Best rergards

Stephan
RPi3+UZB1,FIBARO FGMS001(9x),FIBARO FGD212,FIBARO FGRM222(6x),FIBARO FGSD002(1x),FIBARO FGWPE (3x),Neo CoolCam Power plug(5x),NodOn CRC-3-1 Remote(2x),Qubino ZMNHADx(1x),Qubino ZMNHDD1(2x),Z-Wave Weather Sensor(1x),Z-Wave ZME_WALLC-S,FIBARO System FGK10x
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by dannybloe »

Glatzi wrote:Hi dannybloe,

can you please take a look at the latest beta of Domoticz? Something is going wrong with the scenes & dzEvents there. I'm getting the following error with all of my scenes:

Code: Select all

LUA: Cannot find the device. Skipping: KuecheLichtSchrank 1
2016-10-23_20-38-34.gif

I've deleted all scenes & recreated just the one above but the error remains. No more errors even in debug level 3.
I've also stopped Domoticz & deleted the devices.lua file so it can be build up from scratch but no luck at all :-(

Best rergards

Stephan
Upgrade to the latest dzvents release.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Glatzi
Posts: 13
Joined: Monday 19 September 2016 8:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by Glatzi »

Thx, that solved the error!
RPi3+UZB1,FIBARO FGMS001(9x),FIBARO FGD212,FIBARO FGRM222(6x),FIBARO FGSD002(1x),FIBARO FGWPE (3x),Neo CoolCam Power plug(5x),NodOn CRC-3-1 Remote(2x),Qubino ZMNHADx(1x),Qubino ZMNHDD1(2x),Z-Wave Weather Sensor(1x),Z-Wave ZME_WALLC-S,FIBARO System FGK10x
Glatzi
Posts: 13
Joined: Monday 19 September 2016 8:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by Glatzi »

I've got a question regarding the switchOn().for_min(x) method.

If I'm using this with a power switch in conjunction with a PIR like this:

Code: Select all

if ( PIRKeller.state == 'On' and Keller_Switch.state == 'Off' ) then

	Keller_Switch.switchOn().for_min(2)
               
 elseif ( PIRKeller.state == 'On' and Keller_Switch.state == 'On' ) then
 
        Keller_Switch.switchOn().for_min(2)
end
What happens with the for_min(x) timer when the elsif section is executed:

Is the first timer just canceled & the second will be executed with 2 minutes or is the
time added to the first timer?
RPi3+UZB1,FIBARO FGMS001(9x),FIBARO FGD212,FIBARO FGRM222(6x),FIBARO FGSD002(1x),FIBARO FGWPE (3x),Neo CoolCam Power plug(5x),NodOn CRC-3-1 Remote(2x),Qubino ZMNHADx(1x),Qubino ZMNHDD1(2x),Z-Wave Weather Sensor(1x),Z-Wave ZME_WALLC-S,FIBARO System FGK10x
Glatzi
Posts: 13
Joined: Monday 19 September 2016 8:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by Glatzi »

Hi dannybloe,

what is the reason for the __data. Dot files in the scripts/storage folder?
2016-10-27_19-15-05.gif
2016-10-27_19-15-05.gif (10.43 KiB) Viewed 3546 times
RPi3+UZB1,FIBARO FGMS001(9x),FIBARO FGD212,FIBARO FGRM222(6x),FIBARO FGSD002(1x),FIBARO FGWPE (3x),Neo CoolCam Power plug(5x),NodOn CRC-3-1 Remote(2x),Qubino ZMNHADx(1x),Qubino ZMNHDD1(2x),Z-Wave Weather Sensor(1x),Z-Wave ZME_WALLC-S,FIBARO System FGK10x
Wroopy
Posts: 9
Joined: Tuesday 18 October 2016 22:06
Target OS: Linux
Domoticz version: v3.5745
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by Wroopy »

Glatzi wrote:Hi dannybloe,

what is the reason for the __data. Dot files in the scripts/storage folder?

2016-10-27_19-15-05.gif
I got the same dot-file in the data directory. For me, the reason is that I'm using vi as editor and when you open a file in vi a backup file is created with a leading dot in the filename.

The backupfile is detected and evaluated as a ordinary script by dzVents/lua.

@dannybloe; A possible improvement to dzVents woul be to ignore script-files with a leading dot?

/Andreas
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by dannybloe »

Wroopy wrote:
Glatzi wrote:Hi dannybloe,

what is the reason for the __data. Dot files in the scripts/storage folder?

2016-10-27_19-15-05.gif
I got the same dot-file in the data directory. For me, the reason is that I'm using vi as editor and when you open a file in vi a backup file is created with a leading dot in the filename.

The backupfile is detected and evaluated as a ordinary script by dzVents/lua.

@dannybloe; A possible improvement to dzVents woul be to ignore script-files with a leading dot?

/Andreas
Aha.. that explains... we should certainly ignore those .dotted scripts completely. Right now they are executed as normal scripts!!
I'm very busy at home right now (renovation) which will take at least one or two weeks so I don't have time to fix that I think. I will try but no promises. On the other hand... pull requests are always welcome ;-)
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Markvr
Posts: 1
Joined: Thursday 04 December 2014 18:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by Markvr »

Hi Danny,

I'm trying to read the CounterDelivToday from a P1 Smart Meter device. But I only get a nil value returned. The CounterToday value is working well!

Can you help me?
Glatzi
Posts: 13
Joined: Monday 19 September 2016 8:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by Glatzi »

Wroopy wrote:
Glatzi wrote:Hi dannybloe,

what is the reason for the __data. Dot files in the scripts/storage folder?

2016-10-27_19-15-05.gif
I got the same dot-file in the data directory. For me, the reason is that I'm using vi as editor and when you open a file in vi a backup file is created with a leading dot in the filename.

The backupfile is detected and evaluated as a ordinary script by dzVents/lua.

@dannybloe; A possible improvement to dzVents woul be to ignore script-files with a leading dot?

/Andreas
Hi Andreas,

when you edit files with vim the file is marked with a dot as a prefix & a suffix .swp

Anyway, this is no big deal.
Goold luck with your renovation project @dannybloe :-) This year we had do it in our whole house instead of taking a vacation :D
04-11-_2016_07-17-43.png
04-11-_2016_07-17-43.png (55.35 KiB) Viewed 3435 times
RPi3+UZB1,FIBARO FGMS001(9x),FIBARO FGD212,FIBARO FGRM222(6x),FIBARO FGSD002(1x),FIBARO FGWPE (3x),Neo CoolCam Power plug(5x),NodOn CRC-3-1 Remote(2x),Qubino ZMNHADx(1x),Qubino ZMNHDD1(2x),Z-Wave Weather Sensor(1x),Z-Wave ZME_WALLC-S,FIBARO System FGK10x
Wroopy
Posts: 9
Joined: Tuesday 18 October 2016 22:06
Target OS: Linux
Domoticz version: v3.5745
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by Wroopy »

dannybloe wrote: Aha.. that explains... we should certainly ignore those .dotted scripts completely. Right now they are executed as normal scripts!!
I'm very busy at home right now (renovation) which will take at least one or two weeks so I don't have time to fix that I think. I will try but no promises. On the other hand... pull requests are always welcome ;-)
Made a pull request (my first time, but hope it was done correct).

The current logic is to include all files that contains .lua
Changed to logic to make sure that the file ends with .lua and does not begin with a dot.
User avatar
felix63
Posts: 244
Joined: Monday 07 December 2015 9:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: Gouda
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by felix63 »

Hi Danny,

Nice piece of software. My compliments. I have ported a few scripts. Easier then I thought. Two small questions. I have one script controlling two devices. If one is changed the other one follows. This requires more lines then I expected because apparently I can't copy the state of one device to the other. Is that true or am I missing something?

Code: Select all

return {
	active = true,                  
	on = { 'Subwoofer',
			'Versterker' },

	execute = function(domoticz, mySwitch) 
		if domoticz.devices['Versterker'].changed and domoticz.devices['Subwoofer'].state ~= domoticz.devices['Versterker'].state then
			if domoticz.devices['Versterker'].state == 'On' then
				domoticz.devices['Subwoofer'].switchOn()
			else
				domoticz.devices['Subwoofer'].switchOff()
			end
		elseif  domoticz.devices['Subwoofer'].changed and domoticz.devices['Versterker'].state ~= domoticz.devices['Subwoofer'].state then
			if domoticz.devices['Subwoofer'].state == 'On' then
				domoticz.devices['Versterker'].switchOn()
			else
				domoticz.devices['Versterker'].switchOff()
			end
		end
	end
}
Secondly can I use a (selector-type) switch in domoticz to dynamically set the log-level? If yes then how?

Cheers,
Lex
Doler
Posts: 142
Joined: Friday 31 July 2015 21:02
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Sint-Oedenrode, Netherlands
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by Doler »

Something like

Code: Select all

Domoticz.devices['Subwoofer'].setState(Domoticz.devices['Versterker'].state)
Mark: Domoticz Beta on Raspberry Pi 4 running Debian Bookworm - Z-Stick 7 - RFXCom - P1 - MySensors - SolarEdge - Dahua - Philips Hue - Docker - Zigbee2mqtt (plugin) - Zwave-js-ui - dzVents - Nodered
User avatar
felix63
Posts: 244
Joined: Monday 07 December 2015 9:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: Gouda
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by felix63 »

Doler wrote:Something like

Code: Select all

Domoticz.devices['Subwoofer'].setState(Domoticz.devices['Versterker'].state)
That works better, thanks!



Verzonden vanaf mijn iPad met Tapatalk
User avatar
felix63
Posts: 244
Joined: Monday 07 December 2015 9:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: Gouda
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by felix63 »

Wouldn't it be possible to set/change the debug level using a (selector)switch?
gus
Posts: 16
Joined: Tuesday 04 November 2014 10:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by gus »

Hi!

Trying to switch on groups with dzvents but don't get it to work...

Shouldn't this work:
domoticz.switchGroups('Innelampor Basement', 'On')


Please advice


/Rickard
Last edited by gus on Saturday 10 December 2016 14:30, edited 2 times in total.
Doler
Posts: 142
Joined: Friday 31 July 2015 21:02
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Sint-Oedenrode, Netherlands
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by Doler »

gus wrote:Hi!

Trying to switch on groups with dzvents but don't get it to work...

Shouldn't this work:
domoticz.groups['Innelampor Basement'].switchOn()


Please advice


/Rickard
You should use

Code: Select all

 domoticz.switchGroup('Innelampor Basement', 'On') 
(see Domoticz methods)
Mark: Domoticz Beta on Raspberry Pi 4 running Debian Bookworm - Z-Stick 7 - RFXCom - P1 - MySensors - SolarEdge - Dahua - Philips Hue - Docker - Zigbee2mqtt (plugin) - Zwave-js-ui - dzVents - Nodered
Locked

Who is online

Users browsing this forum: No registered users and 1 guest