Page 16 of 17
Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!
Posted: Wednesday 19 October 2016 14:50
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?
Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!
Posted: Wednesday 19 October 2016 15:05
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.
Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!
Posted: Wednesday 19 October 2016 16:36
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.
Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!
Posted: Wednesday 19 October 2016 20:06
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
Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!
Posted: Sunday 23 October 2016 20:39
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 (42.11 KiB) Viewed 3616 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
Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!
Posted: Sunday 23 October 2016 21:19
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.
Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!
Posted: Monday 24 October 2016 7:45
by Glatzi
Thx, that solved the error!
Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!
Posted: Monday 24 October 2016 10:05
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?
Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!
Posted: Thursday 27 October 2016 19:19
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 (10.43 KiB) Viewed 3543 times
Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!
Posted: Monday 31 October 2016 9:11
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
Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!
Posted: Wednesday 02 November 2016 8:26
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
Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!
Posted: Wednesday 02 November 2016 17:04
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?
Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!
Posted: Friday 04 November 2016 7:26
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
- 04-11-_2016_07-17-43.png (55.35 KiB) Viewed 3432 times
Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!
Posted: Friday 04 November 2016 17:31
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.
Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!
Posted: Monday 21 November 2016 22:27
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
Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!
Posted: Monday 21 November 2016 22:49
by Doler
Something like
Code: Select all
Domoticz.devices['Subwoofer'].setState(Domoticz.devices['Versterker'].state)
Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!
Posted: Sunday 04 December 2016 18:09
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
Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!
Posted: Sunday 04 December 2016 18:17
by felix63
Wouldn't it be possible to set/change the debug level using a (selector)switch?
Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!
Posted: Saturday 10 December 2016 14:22
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
Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!
Posted: Saturday 10 December 2016 14:27
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)