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


  • 0

synchronize two instances of a LUA code scene


Question

Posted

Hello,

 

I want to "synchronize" two instances of a LUA code scene, which can be triggered by either device ID 76 or ID 77.

 

If one instance is already running (independent from 1st trigger device) and a new instance starts, the second/new instance should wait until first one is finished.

 

My LUA code given as example below does not work.

Do you have a working code example?

 

 

Thanks for the support!

Please login or register to see this code.

3 answers to this question

Recommended Posts

  • 0
Posted

One way would be to write to a global variable when the scene starts with something like "running", but only write to the global if the value of the global is <> "running". Then when the scene finishes update the global to "stopped" 

 

In your scene (after the initial code stated above) check if the global variable = "running", if so, then fibaro:sleep for an appropriate length of time for your first scene to run (and update the global = "stopped" i.e. put the scene into a loop checking the global,  once the global is = "stopped" or ~= "running" update the global to "running" and finish running the scene.

 

This will create a backlog of scene all sitting there waiting to run. They will also not necessarily run in the order in which they were triggered. To do this would require some extra code, but without knowing all the details/requirements of your scene I can't say if this is needed or not.

  • 0
  • Inquirer
  • Posted

    Thanks for your feedback.

     

    I have already considered to use a global variable, but this method is "more complex" than using the scene counter functionality.

    From my point of view, my example code should also work.

     

    Some debug output shows, that the "scenes" value does not become greater than 1.

    It seems to be a bug. Some ideas?

     

    Thanks!

    • 0
    Posted

    Thanks for your feedback.

     

    I have already considered to use a global variable, but this method is "more complex" than using the scene counter functionality.

    From my point of view, my example code should also work.

     

    Some debug output shows, that the "scenes" value does not become greater than 1.

    It seems to be a bug. Some ideas?

     

    Thanks!

     

    Are you sure the 1st instance is still running when the 2nd is triggered? If the 1st one finish before the 2nd start, you always see 1 as scene count.

    Also, if i remember correctly, there's a max number of instances to be set in the scene configuration screen (i think default is 2)

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