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

Something is eating my memory.....


Question

Posted

Hi,

I am looking for help to figure out what is causing the memory (RAM) consumption on my HC2 to climb to 90%.

If I reboot the HC in the evening the memory seem to climb over night and the following morning some scenes will start to fail and the box will ultimately become unresponsive.

 

My setup is as follows (approx.)

  • HC2 - 4.070
  • 60 devices
  • 15 virtual devices
  • 24 scenes – mix of “when true do” and ones that start vix a button
  • 35 global variables (mostly SonosLastCmd and TTS as I have 14 zones)

 

From reading on the forum I understand that the number of scenes, global variables, devices and virtual devices is not an issue for the HC2 from a capacity.

 

I suspect I have a rogue scene but have been through them all looping for infinite loops that accumulate resources over time. All of my scenes are Lua and reasonably simply. Determine house occupancy from a number of sensors, wat for a global variable to change and trigger an action, etc

 

I there some way to review a log of all that is happening so I can pick my way though it for issue. Or is there another way to see what is consuming the memory. I could disable one scene every evening but that would take too long and I am writing new scenes every week.

 

Any help appreciated

Thanks

-F

  • Answers 44
  • Created
  • Last Reply

Top Posters For This Question

Recommended Posts

  • 0
Guest bozman
Posted

Hi, It looks like you got more good suggestions here.

Now the memory usage and cpu is what I have.

 

As for your code: 

My suggestion:

Please login or register to see this code.

If you have a PIR or something that reacts on motion I usually change the parameter 6 for fibaro motion to 300s (5 min)

 

Please login or register to see this attachment.

 

 

 

 

Then I guessing there that you have other scenes that changes the value on these global values?

Those scenes will then trigger this scene, thats why you don't need a sleep function inside this scene.

Because when you are in a sleep state nothing will happen, if a trigger changes it will not react on that.

 

  • 0
Guest bozman
Posted

As for the ; it's a old habit that follows me around i every different language

Please login or register to see this image.

/emoticons/default_icon_smile.gif" alt=":-)" />

 

As petergebruers pointed out, it's not necessary.

  • 0
Guest bozman
Posted

I saw this to.

 

You don't need to turn on the device and then set 100%

Please login or register to see this code.

If I remember it correct then turnOn will set it to 100%

I usually just use the setValue to turn on dimmable devices.

  • 0
  • Inquirer
  • Posted

    There's an error on line 95:

    Please login or register to see this code.

    That function expects a color as the first argument, like:

    Please login or register to see this code.

    thanks peter.. nice catch and thanks for taking the time

    I was thinking about getting rid of fSleep and fDebug all together just to simplify things...but not sure yet.

     

    I'll step through each part of the code make sure it all ties together ......

    between your feedback and bozman's feedback I am beginning to think my original issue was an endless loop causing the race condition

    I think that the odd sleep (100) or sleep (1000) at select points would prevent the system having to run continuously and have the scenes still operate as expected.

     

    The other side benefit of this was a good understanding on the baseline operational stats on my setup

    • 0
    Posted

    I saw this to.

     

    You don't need to turn on the device and then set 100%

    Please login or register to see this code.

    If I remember it correct then turnOn will set it to 100%

    I usually just use the setValue to turn on dimmable devices.

    Regarding "setValue": 0 = equivalent to "turnOff". Value 99 = 100% on (someone probably decided that only 2 decimals were available, I don't know.)

    Regarding "turnOn": sets the dimmer to the last know dim level.

    • 0
  • Inquirer
  • Posted

    Hi, It looks like you got more good suggestions here.

    Now the memory usage and cpu is what I have.

     

    As for your code: 

    My suggestion:

    Please login or register to see this code.

    If you have a PIR or something that reacts on motion I usually change the parameter 6 for fibaro motion to 300s (5 min)

     

    Please login or register to see this image.

    /public/style_images/master/attachicon.gif" alt="attachicon.gif" />

    Please login or register to see this link.

     

     

     

     

    Then I guessing there that you have other scenes that changes the value on these global values?

    Those scenes will then trigger this scene, thats why you don't need a sleep function inside this scene.

    Because when you are in a sleep state nothing will happen, if a trigger changes it will not react on that.

     

    Thanks - good suggestion on the PIR's

     

    Re your code and if I understand you right...

     

    If I place the main code in the function and use an 'if then' as you did in your sample then I don't need a 'while true do' loop. 

     

    Since I have the global variable in the header the scene will trigger only when the global variable changes anyway executing the function  ???

     

    is my understanding correct ? 

     

    the final code would be....

    Please login or register to see this code.

    • 0
  • Inquirer
  • Posted

    Regarding "setValue": 0 = equivalent to "turnOff". Value 99 = 100% on (someone probably decided that only 2 decimals were available, I don't know.)

    Regarding "turnOn": sets the dimmer to the last know dim level.

     

    that's interesting peter

     

    Do you know if it causes an issue if I try and set the value = 100 .. curiosity query as I'll change them all to 99 ...

    • 0
    Posted

    (...)

    Do you know if it causes an issue if I try and set the value = 100 .. curiosity query as I'll change them all to 99 ...

    You might fall in a trap later... You set it to "100" and if you read the value back from the device it says: "99".
    • 0
  • Inquirer
  • Posted

    You might fall in a trap later... You set it to "100" and if you read the value back from the device it says: "99".

     

    ahhhhhh.. thx

    • 0
  • Inquirer
  • Posted

    You might fall in a trap later... You set it to "100" and if you read the value back from the device it says: "99".

     

     

    from bozman I created the following code that I'm use as my basic structure for all my scenes

    Would you be happy with it or would you have thoughts

    Please login or register to see this code.

    • 0
    Guest bozman
    Posted

    Yes, that's the way I have it...

     

    Simple and easy to read.

    Start with that and expand as you go!

    Please login or register to see this image.

    /emoticons/default_icon_smile.gif" alt=":-)" />

     

    Let me know if that solved the memory fragmentation!

    • 0
  • Inquirer
  • Posted

    Yes, that's the way I have it...

     

    Simple and easy to read.

    Start with that and expand as you go!

    Please login or register to see this image.

    /emoticons/default_icon_smile.gif" alt=":-)" />

     

    Let me know if that solved the memory fragmentation!

     

    A couple tweaks and it ran perfectly and its definitely a good template for other scenes which I'll start to rebuild over the next while

    thanks a million for the help.. i'll post again on the consumption once I have all scenes re-activated

     

    final code below...

    Please login or register to see this code.

    • 0
    Guest bozman
    Posted

    Looks good, but you are still using a sleep inside a scene, that's not optimal code.

    I have a similar motion code that's is triggered with a motion detector.

    If you bring in the motion/pir sensor as a trigger you could have inside the code.

    When there is no motion set lights value of 5.

     

    If you use the setting that I showed you earlier you will have a benefit if motion is going on the counter will post pone until there is no motion.

    Please login or register to see this code.

    The benefit to have it this way the motion detector will give the clear signal after 5 min and then trigger the scene again if there is no motion.

    The value for id 221 will change from breached to safe.

     

    If you have a sleep inside the scene it will not trigger on motions and lower the lights and then raise them again because you have a motion that breached.

     

    This way they will stay on until no motion for 5 min.

     

    Please login or register to see this attachment.

     
    Try it.
    • 0
  • Inquirer
  • Posted

     

    Looks good, but you are still using a sleep inside a scene, that's not optimal code.

    I have a similar motion code that's is triggered with a motion detector.

    If you bring in the motion/pir sensor as a trigger you could have inside the code.

    When there is no motion set lights value of 5.

     

    If you use the setting that I showed you earlier you will have a benefit if motion is going on the counter will post pone until there is no motion.

    Please login or register to see this code.

    The benefit to have it this way the motion detector will give the clear signal after 5 min and then trigger the scene again if there is no motion.

    The value for id 221 will change from breached to safe.

     

    If you have a sleep inside the scene it will not trigger on motions and lower the lights and then raise them again because you have a motion that breached.

     

    This way they will stay on until no motion for 5 min.

     

     
     
    Try it.

     

     

    That's very clever

    Please login or register to see this image.

    /emoticons/default_icon_smile.gif" alt=":-)" />

    I do have a motion sensor looking at the driveway but its not working since the last HC2 update. I need to get into that corner of the garage and reset it and could modify the code then. This will be perfect because sometime I open the door just to let the cat out and sometimes to get something from the garage or the car and this approach would help separate the two scenarios.

     

    For a device to trigger (from the header code ) - I assume it is any change in state that will cause the scene to re-run.

     

    BTW - I have added back in 5 scenes with your modified code and the RAM is still at the baseline of 32-33% 

    I think this approach will solve my memory issue as long as I keep the code clean and free from unnecessary loops or constant checks

     

    Thanks again for all the help and advice. .. my confidence is returning that I will be able to get all this hardware working as I originally envisioned

    Please login or register to see this image.

    /emoticons/default_icon_smile.gif" alt=":-)" />  

    • 0
  • Inquirer
  • Posted

    Update on where this journey has taken me..

     

    I have modified all the scenes as discussed and re-activated them

    I now have 17 back running and they are a mix of trigger via a start and triggered via a property/variable

    There is not a "while xxxxx do" in sight and most of the scenes are more compact and hopefully a little more efficient.

     

    Resources when complete = Buffer 1%, Used 28%, Cache 18%, Free 50%

    After a reboot = Buffer 1%, Used 17%, Cache 11%, Free 71%

     

    I'll let it sit for the next 24 hours  and see how these numbers change

     

    So far I'm very happy with the result and my lua has improved a lot.

     

    Thanks a million for all the help......

    • 0
  • Inquirer
  • Posted

    12 house later

     

    After a reboot = Buffer 6%, Used 20%, Cache 21%, Free 53%

     

    looking good so far....

    • 0
    Guest bozman
    Posted

    Excellent news!

    I wish that Fibaro had a section for "best practice" on lua scenes.

    • 0
  • Inquirer
  • Posted

    Excellent news!

    I wish that Fibaro had a section for "best practice" on lua scenes.

     

    I would have found it very useful

    Please login or register to see this image.

    /emoticons/default_icon_smile.gif" alt=":-)" />

    I had a idea of the language atthe outset but the nuances/best practice when using it with the HC2 took a bit of tinkering and lot of help from you and peter. A quick tutorial would have shortcut that process quite a bit 

     

    That template you created is a dream and I imagine that a few lines explaining how it works would be very welcome to a lot of beginners. I now have about 3 standard scripts that I use depending on what I am trying to achieve

     

    do you think if we created a crisp explanation and some sample scripts that the moderators would consider making it a sticky ?

    • 0
    Guest bozman
    Posted

    Sure, I belive in sharing is caring!

    Please login or register to see this image.

    /emoticons/default_icon_smile.gif" alt=":-)" />

    • 0
  • Inquirer
  • Posted

    I think we have stabilized the patient 

    Please login or register to see this image.

    /emoticons/default_icon_rolleyes.gif" alt=":roll:" /> 

    Please login or register to see this image.

    /emoticons/default_icon_rolleyes.gif" alt=":roll:" /> 

    Please login or register to see this image.

    /emoticons/default_icon_rolleyes.gif" alt=":roll:" /> 

    Please login or register to see this image.

    /emoticons/default_icon_rolleyes.gif" alt=":roll:" /> 

    Please login or register to see this image.

    /emoticons/default_icon_rolleyes.gif" alt=":roll:" /> 

    Please login or register to see this image.

    /emoticons/default_icon_rolleyes.gif" alt=":roll:" />

     

    Stats from this morning 

    6% buffer

    22% used space

    21% cache

    51% free space

     

    20 scenes running and all functioning as expected. FW 4.0.7.0

     

    In the meantime I have attached some sample lua code attached that were developed with a lot of help from bozman, peter and others. These are very simple but may help others get started and are all based on a core standard template

     

    Out and Garage Lights off: No autostart - designed to be run manually or from another scene

    Gate Entry Night : Autostart, triggers off a property value (sensor under gate) when gate opens

    Pillar Lights Night: Autostart, triggers off a global variable (front door alarm contact sensor) - its a global variable in my setup as my alarm sensors are mirrored in my HC2 as gv

     

    Please login or register to see this link.

    Please login or register to see this link.

    Please login or register to see this link.

     

    Hope this help others

    -F

     

     

     

     

     

     

     

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