Page 1 of 1
Keep data betwwen script calls
Posted: Thursday 21 July 2022 9:29
by lost
Hello,
Is there an easy way, in Domoticz embedded Lua, to keep a data buffer between a device or time script calls? There is the user variable way, but size limit is 200 bytes so that's a bit short.
I would like to aggregate some mail notifications bursts by buffering them until a size limit or time slice value is reached but did not found an easy way to do so?
Re: Keep data betwwen script calls
Posted: Wednesday 27 July 2022 11:08
by lost
Well, finally shortened messages to fit in a user variable used as a buffer... Would indeed be nice to add an API to have Domoticz alloc some user buffer to allow scripts to keep some persistent data between calls. Looks dzVent implement this feature using a file (that should be in a tmpfs to avoid SD wear), but this is IMO hacking to cope with a missing feature.
Re: Keep data betwwen script calls
Posted: Wednesday 27 July 2022 11:17
by boum
Well, both in classic lua and dzvents, you can use
lua I/O interface to write a file to /tmp or wherever your ramfs is.
Re: Keep data betwwen script calls
Posted: Wednesday 27 July 2022 12:44
by mgugu
lost wrote: ↑Thursday 21 July 2022 9:29
Hello,
Is there an easy way, in Domoticz embedded Lua, to keep a data buffer between a device or time script calls? There is the user variable way, but size limit is 200 bytes so that's a bit short.
I would like to aggregate some mail notifications bursts by buffering them until a size limit or time slice value is reached but did not found an easy way to do so?
I solved this limitation problem in dzvents by using global persistent data instead or uservariables
Re: Keep data betwwen script calls
Posted: Friday 29 July 2022 18:25
by lost
boum wrote: ↑Wednesday 27 July 2022 11:17
Well, both in classic lua and dzvents, you can use
lua I/O interface to write a file to /tmp or wherever your ramfs is.
Basically, I find using files for this kind of use a bit far-fetched and so I wanted to avoid it... I did not carefully studied Lua & mostly learned from code snippets. As the interpreter looks to be embedded with Domoticz, maybe there may be a way to add a pointer/data array in a table that is managed by the interpreter or domoticz with entries that would remains between script calls?
Anyway, for now, cutting in stored info does the job to fit in uservariable size limit! But the need to store more may come back in the future: Lacking ability to store persistent data in Lua already lead to other solutions (like using last updates of switches as a hack) in the past...
Re: Keep data betwwen script calls
Posted: Saturday 30 July 2022 21:47
by zicht
I use a script with functions.
So all calls the functions als long as you are in the same script the globals are kept.
To include an external script file, but maybe different on linux, i am running it on windows.
Code: Select all
package.path = package.path .. ';' .. 'C:/PROGRA~2/domoticz/scripts/lua/functions.lua;'
local my = require ("functions")
So basically i have one file on time calling functions and one file on devicechange calling functions.
Of course if you need the keep values between runs you need to store them in uservars. (SLOW!)
Be aware ondevice change it can be 2 devices later before the uservar can be read with the new value.
There is no native transport in lua from one to another run or run parameters that can be set for var values like in Batch files.