Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 1

HC3 LUA vs HC2


knuth
 Share

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 

Please login or register to see this link.

 . 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.

Please login or register to see this attachment.

Edited by knuth
Moved summary table to first post
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Recommended Posts

  • 1

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 comment
Share on other sites

  • 1
15 minutes ago, parip69 said:

With which command can I find out which profile is active

print( api.get("/profiles").activeProfile)

Link to comment
Share on other sites

  • 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
Link to comment
Share on other sites

  • 0

Wow... you're correct.

It works in QuickApp, but not in scene!?

Have reported to Fibaro

Edited by cag014
Link to comment
Share on other sites

  • 0
  • Inquirer
  • 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. 

    Link to comment
    Share on other sites

    • 0

    Please add

    HC2

    fibaro:startScene(id,{args}) 

    HC3

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

    no arguments anymore

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • 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 1
    Link to comment
    Share on other sites

    • 0

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

    Link to comment
    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 comment
    Share on other sites

    • 0

    @knuth

    Please update file

    fibaro:getGlobalModificationTime() not supported in HC3

    Link to comment
    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?

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • 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 comment
    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.

    Please login or register to see this code.

    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

    Please login or register to see this code.

    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 comment
    Share on other sites

    • 0

    Another subtlety that may surprise people.

    In HC2 

    Please login or register to see this code.

    In HC3 (scene)

    Please login or register to see this code.

     

    Edited by jgab
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • 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 comment
    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 comment
    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 comment
    Share on other sites

    • 0

    Other missing functions in HC3 scenes

    Please login or register to see this code.

     

    Link to comment
    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 comment
    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.

     Share

    ×
    ×
    • Create New...