At the moment I have just been playing with blocky code events to do what I want (basic on/offs and timers, just learning).
Is there a benefit to using one method over the other? Does one function quicker etc?
Blocky code events or LUA script?
Moderators: leecollings, remb0
- mobisat
- Posts: 25
- Joined: Thursday 31 October 2013 17:21
- Target OS: Linux
- Domoticz version: 2020.1
- Location: Scotland
- Contact:
Blocky code events or LUA script?
Raspberry PI 3 model B running Domoticz. RFLink, Zigbee2MQTT,
Domoticz V2020.1, utilising 1 wire DS18B20 Digital Temperature Sensors. Running Domoticz Premium android app.
Domoticz V2020.1, utilising 1 wire DS18B20 Digital Temperature Sensors. Running Domoticz Premium android app.
-
- Posts: 63
- Joined: Sunday 14 July 2013 11:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Ipswich, UK
- Contact:
Re: Blocky code events or LUA script?
Blockly is good for simple situations and entry level programmers. As soon as things get complicated then lua is the way to go.
I found a book called "beginning lua programming". It's always open on my tablet - I've learnt everything Lua reading it.
To test things out I create a script called script_device_play.lua on my RasPi happy in the knowledge it'll get called every 30 seconds and I can look at the log to see the results of my endeavours. If i mess up, domoticz will try it again 30 sec later.
Some of the names the developers choose for data tables are very long winded and result in code where you can't see wood for trees. All my scripts start with some VERY SHORT aliases for these arrays. It cuts down on typing and results in clean looking code. For example, I create an alias called "odsv' which is my shorthand for "otherdevices_svalues", similarly, I abbreviate "commandArray" to "set" as in "Set switch On". You need to do whatever you are comfortable with and what results in code you can read in a few weeks time and still understand it. I've also relearnt the old addage "if it ain't broke, don't fix it". Get your code working the way you first figured out how to solve the problem. Don't optimise/improve unless you have to.
Just my opinion, perhaps others could chip in.
I found a book called "beginning lua programming". It's always open on my tablet - I've learnt everything Lua reading it.
To test things out I create a script called script_device_play.lua on my RasPi happy in the knowledge it'll get called every 30 seconds and I can look at the log to see the results of my endeavours. If i mess up, domoticz will try it again 30 sec later.
Some of the names the developers choose for data tables are very long winded and result in code where you can't see wood for trees. All my scripts start with some VERY SHORT aliases for these arrays. It cuts down on typing and results in clean looking code. For example, I create an alias called "odsv' which is my shorthand for "otherdevices_svalues", similarly, I abbreviate "commandArray" to "set" as in "Set switch On". You need to do whatever you are comfortable with and what results in code you can read in a few weeks time and still understand it. I've also relearnt the old addage "if it ain't broke, don't fix it". Get your code working the way you first figured out how to solve the problem. Don't optimise/improve unless you have to.
Just my opinion, perhaps others could chip in.
-
- Posts: 2
- Joined: Thursday 10 October 2013 12:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Sweden
- Contact:
Re: Blocky code events or LUA script?
I agree that lua is the way to go. It has its quirks, but is fairly simple to learn. There are loads of lua examples and tips online, and the Domoticz-specific commands aren't that many so you'll learn them fast.
If you take a simple Blockly example and "convert" it to lua, you'll learn as you go along. You'll also get a lot more freedom in how you want to control things, as Blockly is quite limited. And if you get stuck you can always ask here.
I'm not a big fan of KISS (Keep It Simple, Stuipd), probably due to being on a tight leash when coding at work, so I tend to write quick messy scripts with lots of bells and whistles (notifications etc) then come back after a few days when I know it works and clean up the code.
I wish I could use aliases, but I've found that if it's been more than a few weeks since I read a script, I spend more time relearning the abbreviations than reading the script. But that's me.
If you take a simple Blockly example and "convert" it to lua, you'll learn as you go along. You'll also get a lot more freedom in how you want to control things, as Blockly is quite limited. And if you get stuck you can always ask here.
I'm not a big fan of KISS (Keep It Simple, Stuipd), probably due to being on a tight leash when coding at work, so I tend to write quick messy scripts with lots of bells and whistles (notifications etc) then come back after a few days when I know it works and clean up the code.
I wish I could use aliases, but I've found that if it's been more than a few weeks since I read a script, I spend more time relearning the abbreviations than reading the script. But that's me.

/Shunt
-
- Posts: 63
- Joined: Sunday 14 July 2013 11:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Ipswich, UK
- Contact:
Re: Blocky code events or LUA script?
Good advice - I hadn't realised blockly could export to lua. That said, I pretty much code on my headless RasPi using a terminal emulator from my el cheapo android tablet. Blockly doesn't work on some tablet based browsers - mine included - so l didn't have much choice.
I should also say that there is hardly a line of code I haven't changed but mostly that's because I learned better ways while reading the book I mentioned.
I should also say that there is hardly a line of code I haven't changed but mostly that's because I learned better ways while reading the book I mentioned.
- mobisat
- Posts: 25
- Joined: Thursday 31 October 2013 17:21
- Target OS: Linux
- Domoticz version: 2020.1
- Location: Scotland
- Contact:
Re: Blocky code events or LUA script?
@Commodore white, I have just found that book too, in PDF. I might give it a glance through when I get time 

Raspberry PI 3 model B running Domoticz. RFLink, Zigbee2MQTT,
Domoticz V2020.1, utilising 1 wire DS18B20 Digital Temperature Sensors. Running Domoticz Premium android app.
Domoticz V2020.1, utilising 1 wire DS18B20 Digital Temperature Sensors. Running Domoticz Premium android app.
-
- Posts: 247
- Joined: Sunday 29 November 2015 20:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.9639
- Location: Spain
- Contact:
Re: Blocky code events or LUA script?
I want to do that too, but cannot find it.commodore white wrote:Good advice - I hadn't realised blockly could export to lua.
After just two weeks with Domoticz blocky is restricting me and I don't have time to start studying LUA right now.
Converting them to lua would help a lot.
Who is online
Users browsing this forum: No registered users and 1 guest