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?
Keep data betwwen script calls
Moderator: leecollings
-
- Posts: 662
- Joined: Thursday 10 November 2016 9:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Keep data betwwen script calls
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.
- boum
- Posts: 135
- Joined: Friday 18 January 2019 11:31
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10717
- Location: France
- Contact:
Re: Keep data betwwen script calls
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.
-
- Posts: 220
- Joined: Friday 04 November 2016 12:33
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: France
- Contact:
Re: Keep data betwwen script calls
I solved this limitation problem in dzvents by using global persistent data instead or uservariableslost 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?
-
- Posts: 662
- Joined: Thursday 10 November 2016 9:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Keep data betwwen script calls
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?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.
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...
-
- Posts: 272
- Joined: Sunday 11 May 2014 11:09
- Target OS: Windows
- Domoticz version: 2023.1+
- Location: NL
- Contact:
Re: Keep data betwwen script calls
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.
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.
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")
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.
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
Who is online
Users browsing this forum: No registered users and 1 guest