Page 14 of 17

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

Posted: Sunday 07 August 2016 12:42
by Abbell
@dannybloe Thank you!
That is a very straight forward and comprehensible script.
I can't wait to start testing it.

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

Posted: Monday 08 August 2016 18:50
by raptorjr
I haven't even started to use blockly or let alone Lua for scripting. But this makes me want to start doing script. Looks very nice and intuitive.
But I wonder what is the time plan for getting this as a part of Domoticz? Is there a pull request or something where I can watch the progress? Could even blockly get support for this in some way?

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

Posted: Monday 08 August 2016 22:56
by ddahya
dannybloe wrote:
ddahya wrote:
Its working on my PoC machine but not my Prod box.
If you look at the device attributes from my prod machine it's missing,

2016-08-06 10:40:20.641 LUA: > utility: 23
2016-08-06 10:40:20.642 LUA: > state: 23.00
2016-08-06 10:40:20.643 LUA: > _sValues: 23.00

these are in the PoC box.
That's really strange. Can you try to give the device the same name in production as it has on your poc machine? There must be some discrepancy between the two machines. I suspect the naming may be the culprit as Domoticz doesn't use ids but names in the Lua tables it provides to the scripts. I have to do some juggling to match all those tables to the same devices but it's all done by name.
Finally got it working, I had a scene with the same name as my thermostat "Dining". once i renamed the scene with a different name the dzVents script worked. Thanks for all your help.

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

Posted: Tuesday 09 August 2016 8:15
by dannybloe
raptorjr wrote:I haven't even started to use blockly or let alone Lua for scripting. But this makes me want to start doing script. Looks very nice and intuitive.
But I wonder what is the time plan for getting this as a part of Domoticz? Is there a pull request or something where I can watch the progress? Could even blockly get support for this in some way?
There is nothing there yet. As far as I know, Gizmocus is planning to or working on it right now to have a better and more reliable information stream to the event system so dzVents can be integrated more easily. But I'm not sure how that goes as he's on vacation right now.

So there are two options: a) it's integrated as-is. That means you will have to rely on getting extra data through http (json calls) which is a bit fragile on not truly live or b) integrate it and have a better stream of data coming into the event system (and therefore dzVents as it is just another event script, though a bit more clever) so you have access to all the data in Domoticz directly and live.

a) doesn't require any C++ knowledge and b) does. I don't have C++ knowledge so I'd have to rely on someone else here or we just have to go with option a). Option a) is different from what we have now in that now you have to put dzVents in your system manually. Advantage is that I can update dzVents outside the update cycle of Domoticz.
But I'd rather have option b).

So, until that's there I'd suggest to just start using it coz it doesn't seem likely that dzVents is going away anytime soon ;-)

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

Posted: Friday 12 August 2016 22:35
by Abbell
@dannybloe
I do have a question now that I have been running the script...
EventSystem: Lua script Washing machine did not return a commandArray

Do I need to encapsulate the script using Commandarray() ?

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

Posted: Saturday 13 August 2016 14:10
by dannybloe
Abbell wrote:@dannybloe
I do have a question now that I have been running the script...
EventSystem: Lua script Washing machine did not return a commandArray

Do I need to encapsulate the script using Commandarray() ?
That should not be necessary as the scripts always return a commandArray. Maybe you can set the loglevel to 1.5 and see what it prints. It should show you the commandArray in the log for each script. (you may have to try it with the dev branch though).

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

Posted: Sunday 28 August 2016 16:33
by raptorjr
How can I find out which device triggered the script? If I have several switches in the on-section.

I see this in the tutorial "A 'devices' table holding a list of device names or ids: 'devices' = { 'deviceNameA', 'deviceNameB'}. This can be useful if you have a variable holding the devices that you use for defining the triggers and use in your code."

But don't understand if that is something that I need to use?

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

Posted: Saturday 10 September 2016 13:26
by raptorjr
Another question. I have a water volume device, it shows total litres and something that seems to be current m3 value. Litres seems to be impossible to use or reset, and is now only a nonsense value( 5350 litres and I just added that device???)

But m3 seems to actually be the value I need, the current volume, and is possible to reset. But I don't know how I can access that m3 value from dzVents?

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

Posted: Thursday 15 September 2016 8:10
by dannybloe
raptorjr wrote:Another question. I have a water volume device, it shows total litres and something that seems to be current m3 value. Litres seems to be impossible to use or reset, and is now only a nonsense value( 5350 litres and I just added that device???)

But m3 seems to actually be the value I need, the current volume, and is possible to reset. But I don't know how I can access that m3 value from dzVents?
I think that has to do with the way Domoticz works with counter devices. dzVents is only using what Domoticz is sending to the script engine.
Anyway, I'm not entirely sure what you question is. Are you just looking for the current value?

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

Posted: Wednesday 21 September 2016 23:13
by raptorjr
My question is how do I read the water volume value? The value that on this picture is 0.000m3.
The value 0 Liter is accumulated, and not what I need.

Image

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

Posted: Sunday 25 September 2016 15:47
by dannybloe
raptorjr wrote:My question is how do I read the water volume value? The value that on this picture is 0.000m3.
The value 0 Liter is accumulated, and not what I need.

Image
See the documentation for devices: Device attributes. myDevice.counterToday or counterTotal should do it. (but you have to have http fetching enabled.

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

Posted: Tuesday 11 October 2016 19:12
by Glatzi
dzvEnts is an awesome framework :-) Thx a lot @dannybloe !!!!

Is it possible to use a function in the timer section too?

I've got the problem that I use several scripts for my blinds which should only be executed when it is sunrise or sunset. I'm checking the domoticz.time.isDayTime or domoticz.time.isNightTime attribute

Code: Select all

return {
        active = true,
        on = {
                ['timer'] = 'at sunset',
                ['timer'] = 'at sunrise'

...

if ( domoticz.time.isNightTime and myLevelBlinds > 20) then
                                domoticz.devices['Blinds'].dimTo(10)
But I've got the problem that not all of them get executed everytime. Sometimes my blinds will open or close, sometimes not because the event is missed by Domoticz. So I want to run the script again e.g. 3 minutes after sunrise/sunset. I've written a lua script which is able to calculate that time but how can I include this with dzevents timer?

I've already tried to put the value in a globalData Variable & use this with the timer event, but no luck. Alternatively something like '3 minutes after sunset' would be great :-)

Any help is appreciated...

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

Posted: Wednesday 12 October 2016 7:36
by dannybloe
Glatzi wrote:dzvEnts is an awesome framework :-) Thx a lot @dannybloe !!!!

Is it possible to use a function in the timer section too?

I've got the problem that I use several scripts for my blinds which should only be executed when it is sunrise or sunset. I'm checking the domoticz.time.isDayTime or domoticz.time.isNightTime attribute

Code: Select all

return {
        active = true,
        on = {
                ['timer'] = 'at sunset',
                ['timer'] = 'at sunrise'

...

if ( domoticz.time.isNightTime and myLevelBlinds > 20) then
                                domoticz.devices['Blinds'].dimTo(10)
But I've got the problem that not all of them get executed everytime. Sometimes my blinds will open or close, sometimes not because the event is missed by Domoticz. So I want to run the script again e.g. 3 minutes after sunrise/sunset. I've written a lua script which is able to calculate that time but how can I include this with dzevents timer?

I've already tried to put the value in a globalData Variable & use this with the timer event, but no luck. Alternatively something like '3 minutes after sunset' would be great :-)

Any help is appreciated...
So why don't you just set a timer for let's say every couple of minutes and in the script check if it is sunrise or sunset and check the state of your blinds and act accordingly? That shouldn't be too hard I think.

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

Posted: Wednesday 12 October 2016 12:33
by Eduard
Is is possible to create persistent data variables dynamically? Like with an existing array of variables that holds the names of the persistent data variables to be created...

Code: Select all

local arrDataVars = {'Counter1', 'Counter2', 'Counter3'}
and then in the data = { } part something magic.
Maybe use something like loadstring("arrDataVars[1] = { initial = 0 }") ??

instead of

Code: Select all

data = {
  Counter1 = { initial = 0 },
  Counter2 = { initial = 0 },
  Counter3 = { initial = 0 }
}
Any help would be great :D

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

Posted: Wednesday 12 October 2016 13:01
by dannybloe
Eduard wrote:Is is possible to create persistent data variables dynamically? Like with an existing array of variables that holds the names of the persistent data variables to be created...

Code: Select all

local arrDataVars = {'Counter1', 'Counter2', 'Counter3'}
and then in the data = { } part something magic.
Maybe use something like loadstring("arrDataVars[1] = { initial = 0 }") ??

instead of

Code: Select all

data = {
  Counter1 = { initial = 0 },
  Counter2 = { initial = 0 },
  Counter3 = { initial = 0 }
}
Any help would be great :D
It is even simpler than that. Simply create a table variable:

Code: Select all

data = {
    myVar = { initial = {} }
}
Then you can do this:

Code: Select all

domoticz.data.myVar['counter1'] = 1;
domoticz.data.myVar['counter2'] = 2;
That should work.

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

Posted: Wednesday 12 October 2016 13:12
by Eduard
dannybloe wrote:It is even simpler than that. Simply create a table variable:

Code: Select all

data = {
    myVar = { initial = {} }
}
Then you can do this:

Code: Select all

domoticz.data.myVar['counter1'] = 1;
domoticz.data.myVar['counter2'] = 2;
That should work.
Aah cool. I will try that. Thanks!!

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

Posted: Wednesday 12 October 2016 13:29
by BakSeeDaa
Hi there!

I will try to migrate my current LUA scripts to dzVents.

In several of my old LUA scripts I call require to load a module with some handy functions that I use frequently. I use those functions frequently, for example when I want to have a message spoken out loud in the kitchen (using AutoRemote and Tasker):

Code: Select all

local b = require("scripts/lua/mymodule")
b.speak("Hello world")
I'm now trying to figure out the nicest and most elegant way to use my custom functions in dzVents scripts. I guess I could just use require to load a module as in the code above... I wish there was a some kind of hook mechanism or a way to "extend" the domoticz object in my dzVents script so that I could just issue a command like

Code: Select all

domoticz.speak('Hello world', domoticz.PRIORITY_NORMAL)
Any ideas about that? Thanks!

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

Posted: Wednesday 12 October 2016 13:32
by dannybloe
BakSeeDaa wrote:Hi there!

I will try to migrate my current LUA scripts to dzVents.

In several of my old LUA scripts I call require to load a module with some handy functions that I use frequently. I use those functions frequently, for example when I want to have a message spoken out loud in the kitchen (using AutoRemote and Tasker):

Code: Select all

local b = require("scripts/lua/mymodule")
b.speak("Hello world")
I'm now trying to figure out the nicest and most elegant way to use my custom functions in dzVents scripts. I guess I could just use require to load a module as in the code above... I wish there was a some kind of hook mechanism or a way to "extend" the domoticz object in my dzVents script so that I could just issue a command like

Code: Select all

domoticz.speak('Hello world', domoticz.PRIORITY_NORMAL)
Any ideas about that? Thanks!
That's an interesting idea. Shouldn't be so hard to do that. Until then I'd just do the require way.

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

Posted: Wednesday 12 October 2016 14:59
by BakSeeDaa
dannybloe wrote:That's an interesting idea. Shouldn't be so hard to do that. Until then I'd just do the require way.
Thanks @dannybloe

I have the following function in my module:

Code: Select all

function b.OpenURL(url)
	-- The commandArray also supports nested tables to send the same command type multiple times.
	-- To do this, give the command a numeric index
	commandArray[#commandArray + 1]={['OpenURL']=url }
end
It allows me to call multiple URLs.

While my old LUA scripts was working with that code, I now have a problem with that I have no valid commandArray object reference. Also, my module doesn't seem to be able to access the domoticz object so I have currently no way to add something to the command array or access domoticz user variables... Maybe there is a way to solve that?

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

Posted: Wednesday 12 October 2016 15:03
by dannybloe
BakSeeDaa wrote:
dannybloe wrote:That's an interesting idea. Shouldn't be so hard to do that. Until then I'd just do the require way.
Thanks @dannybloe

I have the following function in my module:

Code: Select all

function b.OpenURL(url)
	-- The commandArray also supports nested tables to send the same command type multiple times.
	-- To do this, give the command a numeric index
	commandArray[#commandArray + 1]={['OpenURL']=url }
end
It allows me to call multiple URLs.

While my old LUA scripts was working with that code, I now have a problem with that I have no valid commandArray object reference. Also, my module doesn't seem to be able to access the domoticz object so I have currently no way to add something to the command array or access domoticz user variables... Maybe there is a way to solve that?
domoticz.commandArray is exactly the commandArray that is sent back to domoticz. You can see in Domoticz.lua how the array is filled.
Can't you pass domoticz.commandArray to your function and have you function use the parameter instead of the global commandAarray? dzVentz overwrites the global commandArray at the end of the script run.