Jump to content
  • 1

HC3 LUA vs HC2


Question

In making the transfer from HC2 to HC3 based on a cloud backup (update 4.581 Beta) it is stated that "scenes will not be moved and need to be created again". That's OK, but it would be helpful when planning the transfer to know what the differences are (in syntax and available functions) between the two LUA versions. I know that the new LUA editor is documented in https://manuals.fibaro.com/home-center-3-lua-scenes/ . What I would hope to see in addition, is a side by side comparison of all the crucial differences, to enable a pre-edit of the old LUA scenes before entering them into the new editor. Something like this:

 

If you used this in HC2 LUA:                You need to do this in HC3 LUA:

fibaro.debug("txt")                                   fibaro.debug("tag", "txt")

os.time()                                                   ??? 

etc.

 

If we all contribute to such a table as we identify all the differences, we may be able to help each other prepare for HC3. Not all differences can easily be summarized in the simple two-column format above, however. For the new definition of conditions and triggers, it seems it would be more appropriate to give a few examples of old codes (with triggers) converted to new codes. 

 

PS: I haven't even decided to buy the HC3 yet! But getting a feel for the amount of re-programming needed to convert my scene is an important factor in making that decision. 

 

The suggested table is now shown in a pdf file attached to this post, see below. It is regularly updated as new contributions are posted.

LUA HC2 vs HC3.pdf

Edited by knuth
Moved summary table to first post
  • Like 1
  • Thanks 1
Link to post
Share on other sites
  • Answers 67
  • Created
  • Last Reply

Top Posters For This Question

Top Posters For This Question

Popular Posts

First version of summary table, including some that are not mentioned above. I am sure there is more, please post your contribution once you find other differences. The trigger section is still e

Yeah, I'd like to add that on HC3 Fibaro works on an "alpha" version internally, then publishes that "alpha" to a group of end-users for feedback.   At the moment, I am not 100% sure if the

On the HC3 there is only one instance running. They skipped the multiple instance model that was used in the HC2. A HC3 running instance either block a new scene or the new scene kills the runnin

Posted Images

Recommended Posts

  • 0

Everything is try and error...

for example

HC2 -fibaro:getDevicesId

HC3 - fibaro.getDevicesID

No idea why Fibaro change suffix Id to ID. It took me 15 minutes to identify  the difference. (beside the change colon ":" to period ".")

and more others...

Edited by cag014
  • Like 2
Link to post
Share on other sites
  • 0

Hi @cag014 your hint was the right hint! 

 

But i get:

 

devices=fibaro.getDevicesID({visible = true, enabled = true}) 

 

[ERROR] 10.03.2020 13:28:39: (load):11: attempt to call a nil value (field 'getDevicesID')

 

Greetings!

Link to post
Share on other sites
  • 0

Wow... you're correct.

It works in QuickApp, but not in scene!?

Have reported to Fibaro

Edited by cag014
  • Like 1
Link to post
Share on other sites
  • 0

Thanks for sharing, @cag014 . Your two examples ("ID" and colon->period) are precisely the type of changes that are easily overlooked when preparing a conversion. I collect such examples in a table off-line, and will share the result when more contributions are in. Please keep them coming, users, as you discover the subtle differences between HC2 and HC3 LUA. 

  • Like 1
Link to post
Share on other sites
  • 0

Please add

HC2

fibaro:startScene(id,{args}) 

HC3

fibaro.scene("execute",{id,id})

no arguments anymore

  • Like 1
Link to post
Share on other sites
  • 0
Posted (edited)

First version of summary table, including some that are not mentioned above. I am sure there is more, please post your contribution once you find other differences.

The trigger section is still empty, ready to receive examples of old -> new code. 

Edit: The summary table is now attached to my first post

 

 

 

 

 

Edited by knuth
Moved summary table to first post
  • Like 3
  • Thanks 2
Link to post
Share on other sites
  • 0

This already helped me with zipato rfid reader. Big thanks.

Link to post
Share on other sites
  • 0

Sorry to say i have an inclusion that is not exactly positive:

 

HC2 LUA      fibaro: after 3 years work :good                                              

HC3 LUA     fibaro: not a finished product: negative                                                         

Comment     Feels like a giant step backwards, devices not recognized , relearning process and coding , backup scenes not     transferable. Released way too soon.

 

I admire your tenacity and work improving the functions of hc3 , but it seems fibaro are asking the community to finish their product, yet again.

Will pass on HC3 until it recieves major updates.

        

            

Edited by MARCUSP.I.L
  • Like 1
Link to post
Share on other sites
  • 0

@knuth

Please update file

fibaro:getGlobalModificationTime() not supported in HC3

Link to post
Share on other sites
  • 0
25 minutes ago, cag014 said:

@knuth

Please update file

fibaro:getGlobalModificationTime() not supported in HC3

Maybe a column with ways to achieve the same functionality?

function fibaro.getGlobalModificationTime(var) return select(2,fibaro.getGlobalVariable(var)) end

 

Link to post
Share on other sites
  • 0

I will have to trust you on this one, @jgab , as I do not know the "select" function and how it works. Your suggestion will indeed be included in my "HC3 LUA" column as a solution. The file will be updated very soon.

Link to post
Share on other sites
  • 0
30 minutes ago, knuth said:

I will have to trust you on this one, @jgab , as I do not know the "select" function and how it works. Your suggestion will indeed be included in my "HC3 LUA" column as a solution. The file will be updated very soon.

So fibaro.getGlobalVariable(var) returns 2 values. The value of the var and the modification time. Like fibaro.get.

local value, time = fibaro.getGlobalVariable(var)

You don't need to define fibaro.getGlobalModificationTime(var)

It's as easy to do as in the example above or just use it direct in expressions

print(os.date("Variable modified %c",select(2,fibaro.getGlobalVariable(var))))

select(n,...)  is a standard Lua function that selects the remaining 'n' values of the argument '...' (it's a surprisingly useful function...)

It may seem a bit wasteful to retrieve the value to just get the modification time. 

However, I believe in the HC2 Lua API they get the whole variable data structure and return just the modified key so this is very little overhead.

Link to post
Share on other sites
  • 0

Another subtlety that may surprise people.

In HC2 

a = {[1]=8,[4]=9}
fibaro:debug(json.encode(a))
[DEBUG] 21:21:51: {"1":8,"4":9}

In HC3 (scene)

= {[1]=8,[4]=9}
fibaro.debug("",json.encode(a))
[ERROR] 16.03.2020 21:24:59: /opt/fibaro/lua_engine/lua/lib/json.lua:78: invalid table: sparse array

 

Edited by jgab
Link to post
Share on other sites
  • 0
19 hours ago, jgab said:

Another subtlety that may surprise people.

Subtle, indeed, and maybe beyond the simple tabulation that I try to put together. Besides, this looks like a bug, since the json.encode should work the same in both versions.

 

Thanks for putting me straight on the Global Variable update time issue. To convert your last post to my two-column format, it seems I could just write:

HC2 LUA                                                                      HC3 LUA

fibaro:getGlobalModificationTime()                       select(2,fibaro.getGlobalVariable(var))

 

If you confirm (or correct), I can insert this in my pdf table.

Link to post
Share on other sites
  • 0
3 hours ago, knuth said:

Subtle, indeed, and maybe beyond the simple tabulation that I try to put together. Besides, this looks like a bug, since the json.encode should work the same in both versions.

 

Thanks for putting me straight on the Global Variable update time issue. To convert your last post to my two-column format, it seems I could just write:

HC2 LUA                                                                      HC3 LUA

fibaro:getGlobalModificationTime()                       select(2,fibaro.getGlobalVariable(var))

 

If you confirm (or correct), I can insert this in my pdf table.

Confirmed... works fine

Link to post
Share on other sites
  • 0

HC2:

fibaro:isSceneEnabled(sceneID)

fibaro:setSceneEnabled(sceneID , enabled)

fibaro:getSceneRunConfig(sceneID)

fibaro:setSceneRunConfig(sceneID ,runConfig)

 

HC3:

function fibaro.isSceneEnabled(sceneID) return api.get("scenes/"..sceneID).enabled end

function fibaro.setSceneEnabled(sceneID,enabled) return api.put("scenes/"..sceneID,{enabled=enabled}) end

function getSceneRunConfig(sceneID) return api.get("scenes/"..sceneID).mode end

function setSceneRunConfig(sceneID,runConfig) return api.put("scenes/"..sceneID,{mode=runConfig}) end -- mode is 'automatic' or 'manual'

Link to post
Share on other sites
  • 0

Other missing functions in HC3 scenes

function split(s, sep)
      local fields = {}
      sep = sep or " "
      local pattern = string.format("([^%s]+)", sep)
      string.gsub(s, pattern, function(c) fields[#fields + 1] = c end)
      return fields
end

function urlencode(str)
      if str then
        str = str:gsub("\n", "\r\n")
        str = str:gsub("([^%w %-%_%.%~])", function(c)
            return ("%%%02X"):format(string.byte(c))
          end)
        str = str:gsub(" ", "%%20")
      end
      return str    
end

 

Link to post
Share on other sites
  • 0

Does anyone know how to control the RGBW controllers via LUA? I've already tried everything. For me only goes on / off ...

Link to post
Share on other sites
  • 0
19 minutes ago, boomx said:

Does anyone know how to control the RGBW controllers via LUA? I've already tried everything. For me only goes on / off ...

 fibaro.call(<deviceID>,"setColor",R,G,B,W) ?

  • Like 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...