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

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

Recommended Posts

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

  • 0
  • Inquirer
  • @jgab Your function definitions are now added to the pdf file above. Great job, thanks! Keep testing! 

    @boomx Is there a difference between HC2 and HC3 in the way RGBW controllers are addressed in LUA? Those differences are the only issue for this thread.

    Link to comment
    Share on other sites

    • 0
    Guest kallecux

    Hi @knuth - thanks for you good idea!

     

    I had noticed that there was a difference between QA-LUA and scene-LUA.

     

    Specifically in my case the command fibaro.profile:

     

    QA LUA: fibaro.profile("activateProfile",1)

    ScriptLUA: fibaro.profile (1, "activateProfile")

     

    I hope it is a mistake on the part of fibaro and we do not have to distinguish between QA-LUA and Script-LUA....

     

    Greetings!

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • @kallecux I agree, it would be strange to have different syntax between LUA used in scenes and LUA in QAs. Still, I will include your observation as a note in my next update. 

    Actually, I would expect the missing functions described by @jgab to be included in a future update by Fibaro, as well as obvious errors like the one you describe. But so far, we have to give users advice based on the current version. Thanks, both of you.

    Link to comment
    Share on other sites

    • 0

    In scenes there is fibaro.setTimeout but there is no fibaro.clearTimeout, used to cancel a timer that is not yet activated. Used to be there on the HC2 and is useful.

    Hopefully they will add it but there are ways to overcome the issue - a small performance penalty (memory) as timers will hang around until they expire.

    Please login or register to see this code.

     

    There used to be a fibaro:calculateDistance in HC2 scenes - not sure how useful it is these days, but for completeness...

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    • 0

    Hi!

     

    Event handling by example Fibaro Button event handling:

     

    HC2:

    local button_source = (fibaro:getSourceTrigger()["event"]["data"]);

    if (tostring(button_source["keyAttribute"]) == "Pressed")

     then fibaro:debug("Pressed 1x")

    elseif (tostring(button_source["keyAttribute"]) == "Pressed2")

     then fibaro:debug("Pressed 2x")

    end

     

    HC3:

    if (sourceTrigger.value.keyAttribute == "Pressed")
     then fibaro.trace("Scene13", "Pressed 1x")
    elseif (sourceTrigger.value.keyAttribute == "Pressed2")
     then fibaro.trace("Scene13", "Pressed 2x")
    end 
    Link to comment
    Share on other sites

    • 0
    23 minutes ago, Jacławiciel said:

    What about fibaro:countScenes() and fibaro:abort()? Anyone found a replacement?

    countScenes is not relevant as there is only one instance running.

    fibaro.abort() can be avoided by structuring the code so the scene terminates.

    If you absolutely need it it you could try

    Please login or register to see this code.

    See discussion here

     

    Link to comment
    Share on other sites

    • 0
    36 minutes ago, jgab said:

    See discussion here

    I think, that issue not in  fibaro:abort(), but in fibaro:countScenes() to know - is it exist another (parallel) running instance of the scene and make appropriate processing this case in code. In a particular case, a  fibaro:abort() call.

    Edited by vsokolov
    Link to comment
    Share on other sites

    • 0
    4 minutes ago, vsokolov said:

    I think, that issue not in  fibaro:abort(), but in fibaro:countScenes() to know - is it exist another (parallel) running instance of the scene and make appropriate processing this case in code. In a particular case, a  fibaro:abort() call.

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

    But ok, here is a countScenes function

    Please login or register to see this code.

    ;-) 

    • Like 2
    • Thanks 2
    Link to comment
    Share on other sites

    • 0
    4 minutes ago, jgab said:

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

    Thanks for explain. Appropriate fibaro hint on this scene attribute is not so evident as for me.

    Link to comment
    Share on other sites

    • 0
    1 minutę temu, jgab napisał:

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

    But ok, here is a countScenes function

    Please login or register to see this code.

    ;-) 

     

    Yeah, funny! ? 

     

    I was not aware of that. Thank's for explanation. 

     

    BTW: It's my first occasion to thank you personally for your time and dedication. I'm a big fan of your "out of the box" thinking that must be based on your vast technical experience. Your solutions to many problems are based on solid foundations and I try to a handful of it with benefit to my Fibaro and professional knowledge. 

    • Thanks 1
    Link to comment
    Share on other sites

    • 0
    39 minutes ago, jgab said:

    A HC3 running instance either block a new scene or the new scene kills the running instance. 

    By default a trigger indeed kills the running instance, because new scenes on HC3 get "Allow to restart a running scene" under "Basic Configuration" set to "Yes". If you change that to "No", a trigger won't kill a running instance but also does not start a new instance, so setting it to 'No' comes close to what many scenes on HC2 did by adding "if countscenes > 1 then fibaro:abort" at the start of a scene.

    Link to comment
    Share on other sites

    • 0
    9 minutes ago, petergebruers said:

    By default a trigger indeed kills the running instance, because new scenes on HC3 get "Allow to restart a running scene" under "Basic Configuration" set to "Yes". If you change that to "No", a trigger won't kill a running instance but also does not start a new instance, so setting it to 'No' comes close to what many scenes on HC2 did by adding "if countscenes > 1 then fibaro:abort" at the start of a scene.

    Do we know if the scene queues up if there is a scene already running? or it's just never allowed to start and we loose the trigger/event? I guess it's lost...

    Edited by jgab
    • Like 1
    Link to comment
    Share on other sites

    • 0
    3 minutes ago, jgab said:

    Do we know if the scene queues up if there is a scene already running? or it's just never allowed to start and we loose the trigger/event? I guess it's lost...

    iirc it is lost and there is a request to get back the HC2 behaviour of running multiple instances (up to 10). I support this request, not because it is a good idea (imo, it is not a great idea...) but because some scripts rely on the fact that you can have more than one instance... I prefer the HC3 way (one instance, either kill or leave running).

     

    I know you use refreshStates too and I think that is the most flexible way and would not miss events.

    Link to comment
    Share on other sites

    • 0
    14 minutes ago, petergebruers said:

    comes close

    Hi @petergebruers,

    could you please elaborate a bit what means come close to?

     

    Link to comment
    Share on other sites

    • 0
    Just now, Bodyart said:

    could you please elaborate a bit what means come close to?

    Two things come to mind. the first is, on HC2 you can do things, then check the number of instances and abort (say halfway your scene). The second thing is it does not emulate this HC2 bug: when a trigger comes very fast after another on HC2 your scene will start with countscenes 2. If your scene aborts if count is > 1 your scene won't run (because there never was an instance with count 1). I still have to double check this on my HC3 but I think this is no longer an issue.

    • Like 1
    Link to comment
    Share on other sites

    • 0
    5 minutes ago, petergebruers said:

    I still have to double check this on my HC3 but I think this is no longer an issue.

    I really hope, that that instance issue is already solved on HC3.

     

    Link to comment
    Share on other sites

    • 0
    9 minutes ago, petergebruers said:

    iirc it is lost and there is a request to get back the HC2 behaviour of running multiple instances (up to 10). I support this request, not because it is a good idea (imo, it is not a great idea...) but because some scripts rely on the fact that you can have more than one instance... I prefer the HC3 way (one instance, either kill or leave running).

     

    I know you use refreshStates too and I think that is the most flexible way and would not miss events.

     

    I don't think the multiple instances is a good idea either. I hope they don't revert to that.

    I would like to have a better way to interact with the event queue -like registering callbacks for specified event types. 

     

    However, it's kind of unacceptable to drop events - if they only want to run one instance they could as an option allow to queue up the events - much less memory needs for events vs scene instances.

    • Like 1
    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.

    ×
    ×
    • Create New...