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

Advice for infinite loop with global variables


Question

Posted

Hi all

I need some advices regarding a LUA script I would like to write.

I would like to monitor an air sensor using a virtual device and then select the icon depending on the quality of the air. 2 solutions :

- I use the main loop of the virtual device but the main loop is executed each 3 seconds so if I need global variables (to summarize value, first one, last one, etc), I have to create them into the panel Variables and load them each time the main loop is executed (I choose this one but not very conveniente with global variable)

- I use a scene with an infinite loop so I can declare and manage variables only in my scene abd I can change the icon of the virtual device

I don't know what is the best practice in term of performance and ressource

Thanks a lot for your advices

2 answers to this question

Recommended Posts

  • 0
Posted

Depends on how often you are looking for updates. If you want updates every time the air sensor changes value, you could just create a lua scene with the device as a trigger. As soon as the value changes, the scene triggers and the icon is updated accordingly. The scene then kills itself, when the value changes again, same thing. This will put very little strain on your hc if the value changes rarely, but if it changes conatantly, it might be better to have a scene run in an infinite loop with a preset delay i.e. 10 seconds.

Personally, I try to avoid using the main loop as i find that it is very ressource heavy.

  • 0
  • Inquirer
  • Posted

    Thanks for your feedback

    I think I will use a scene with infinite loop because using trigger on variable means to use global variables from the panel variables.

    There is a lack on the HC with context of global variables. It would be fine to declare global variable in a scene running by trigger without using variables from panel. We have no choice today because with the trigger, all the local variable of the scene are reset

    I hope they will change this in V4.0

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