Page 1 of 1

lua events and lua scripts

Posted: Monday 23 May 2016 19:03
by darlomrh
Hi
Still new to Domoticz and scripting. I have set up a virtual switch to be triggered by pilot (iOS app) using geolocation.
I have done a solution using events and a solution using script in /domoticz/scripts/lua and I'm struggling to see what the differences are. Can I confirm that if *any* device state changes, domoticz/lua runs any scripts labelled script_device_xxxx in /domoticz/scripts/lua.

So if you have multiple script_device_xxxx scripts they all run regardless. How does this differ from events?

Is it best practice to have one script_device_xxxx script that calls out to other lua scripts?

Thanks in advance.

Re: lua events and lua scripts

Posted: Tuesday 24 May 2016 22:01
by simonrg
If you mean writting your Lua script in the UI events page versus having a file in the scripts/lua directory, then functionaly no difference.

The UI events page scripts are stored in the mysql database - domoticz.db, whereas obviously the scripts/lua directory stores the files. So convenience of single file to back up versus having individual files you can edit anywhere.

When any device changes in Domoticz, then Domoticz will run each of your Blockly events, Lua UI events and Lua file events.

Experimentation has shown there is a penalty to having lots of separate scripts, as each time Domoticz loads a script it has to set up all the variables to be passed, devicechanged, otherdevices etc..

So performance will be better if you use a single device and a single time script which calls appropriate scripts. This can be as simple as a single master script or a complete framework (search for dzvents on the forum).

Re: lua events and lua scripts

Posted: Tuesday 24 May 2016 22:04
by georgesattali
Can I confirm that if *any* device state changes, domoticz/lua runs any scripts labelled script_device_xxxx in /domoticz/scripts/lua :
Yes that's true.
So if you have multiple script_device_xxxx scripts they all run regardless. How does this differ from events?
I suppose you are speaking of blocky, the graphical event editor in "Setup/More options/Events".
Functionnality is similar,
using written lua scripts, one gets all the power of a complete programming language.
using blocky, one can make simpler commands without knowing programmation.
In blockly, you can choose when you command will be run (click on "All").
Is it best practice to have one script_device_xxxx script that calls out to other lua scripts?
I don't think so. You should stick to one script for one usage.
Each script_device_xxxx contains a test like

Code: Select all

if devicechanged["mydevice"] == "On" then
   ...
end
lua as well as blocly are executed very quicly and having several script has very few impact on performances.

Bye
GD

Re: lua events and lua scripts

Posted: Wednesday 25 May 2016 0:12
by darlomrh
I suppose you are speaking of blocky, the graphical event editor in "Setup/More options/Events".
Functionnality is similar,
using written lua scripts, one gets all the power of a complete programming language.
Hi it's in that area, however you have the option to chose Blocky or lua so you can create event scripts there rather than the directory.


Thanks for the replies