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


AutoFrank
 Share

Question

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

Link to comment
Share on other sites

Recommended Posts

  • 0

You can write to support when your memory will be filled, they will check what eats your ram using console.

 

Link to comment
Share on other sites

  • 0

I had the same issue for 3 months and no help from support.

Only thing I got back from them was , check your scenes.... Case closed or make a scene that restarts every night( I had 3 of them!!!)

They never bothered go in to the box even.

 

Here how I solved it.

Started with disconnect all wall-plugs, then I restarted the HC2 and then plug them back one after another.

Noticed that one of the wall plugs behaved doggy.

Reincluded that one. Couldn't switch it on or off, no power readings at all. Dead node suddenly.

 

After that I took one scene at the time of and monitored the CPU , found a couple of scenes behaving funny, even if they worked fine up to firmware version 4.6x something, can't really memorise what version worked.

 

Changed all of theme not to have to many triggered devices to a few instead. 

Cleaned out sleep functions or setTimeouts, if I remember it correct now I have 2(total 44) scenes with setTimeout function. 

 

Changed the code to of the scenes to mainly have these lines instead for having sleep or setTimeout function on looping.

Please login or register to see this code.

This way I found out that it will trigger either on global value or property without having a sleep or setTimeout.

Did a lot of research on this one.

 

if you have a device that you monitor like a dishwasher then you have to have that one inside , for me in this example it was id:292

Please login or register to see this code.

 

Now days after going trough the scenes and even the faulty wall plug I'm on 2-3% cpu and around 30 % in memory usage.

 

And unfortunately without help from Fibaro support.

 

I hope that you understood anything and good luck.

Link to comment
Share on other sites

  • 0
  • Inquirer
  • HI bozman, this helps a lot. Thanks for taking the time...

    no response from fibaro support so I'm not holding out much hope there.

     

    I had started through some of this but not in a structured fashion but will backtrack and follow your ideas.

    CPU now at 40% when stable and it seems to have stopped going 'critical'.. for now

    This also happened several weeks ago and I tweaked some scenes and it went away. I was not very happy that I found a definitive problem that I fixed.

     

    Scenes

    1) I had suspected a scene and have been picking my way through them (about 22 in total)

    They are pretty simple but I've started to tidy them but I couldnt find any gross issues

    2) I did have some of the code for "autostart" and "other" but I haven't come across "global" or "property"

    I'm new to lua and not sure what this block of code does.. could you explain ?

    3) I have a couple of scenes that use "while true do" or "while <global variable name> do"

    I have been told that run tens of these types on the HC2 without experiencing an issue

    If I trigger on a global variable in #2 do I need to use 'while true do' with it ?

     

    I asked about putting the ID in the scene header but couldn't get a straight answer

    Is it needed and what does the 'power' represent

     

    2 samples of my code is below - all suggestions welcome

    Please login or register to see this code.

    and one that is triggered on a global variable in a "while - - do"

    Please login or register to see this code.

    Devices

    1) I have a lot of in-wall micro switches (dimmers/relays) for lights so I might just kill the power to them all to reset. including / excluding would be a huge chore but I'll check and see if any misbehave over the coming days

    2) I have a 7 swiid inline lamp switches and noticed that they would respond to a HC2 command but not a physical press of the switch. I unplugged and when I plugged them back in they now work okay but I'll keep an eye on them

     

    Thanks again for taking the time

    -F

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Hi,

    I think I may have found a bug but am not sure how to interpret the error or fix

    I get this error periodically 

     

    Please login or register to see this attachment.

     

    when I run this script .. but line 35 is a comment so I'm puzzled

    Any help appreciated

    Please login or register to see this code.

    Link to comment
    Share on other sites

    • 0

    Hi, not a problem!

     

    I have struggled whit this pice of *** for a couple of month now and invested a lot of time and pain.

    I understand your frustration.

    This is what I have learned so far and of course things can be done differently.

     

    This is my code example of a dishwasher notification:

     

    I use it to be sure that I'm not killing my water fuse for the house when the alarm is enabled, otherwise it will no do the dishes.

    Please login or register to see this code.

    Form start:

    Please login or register to see this code.

    These are your triggers you want to have, keep them to minimal.

    In my case I only have it for the power of the plug.

    If you have a power change then it will start your scene.

    You can do a bit of tuning on the plug not to send a changes in power.

    Please login or register to see this code.

    This one you maybe know already, it will keep your instances to 1.

    Please login or register to see this code.

    I like functions, I like more to keep it simple so I use the default name from Fibaro, if you use a block scene and then convert it to LUA it will give you a lot of free code to reuse!

    Please login or register to see this image.

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

    I'm lazy!

    Please login or register to see this code.

    This is the heart of everything.

    If some of the triggers changes in some way then they will call the main function.

    In my case property will kick my scene every time, no need for sleep och setTimeouts etc...

     

    This script actually has a sleep function to make sure that the last time something happened on the wallplugg was 5 min ago. I true then dishwasher is done.

    Please login or register to see this code.

    And at the end if I manually trigger the scene (other) then it will do the something as the function except for some small changes.

     

    Link to comment
    Share on other sites

    • 0

    Forgot to mention another thing,

    do not have global values as triggers if you set theme in the code

    Please login or register to see this code.

    if you have 

    Please login or register to see this code.

    it will create a loop when you trigger that value again.

    Be really careful here, I saw when I went trough scene with set global value:s and cleaned theme out, suddenly all my max instances error went away!

     

    30% of CPU sound high, my system is now on 1-3% CPU and stable on that, sometimes is spikes at 20% for a few milliseconds.

    Keep digging on why so high CPU, disable on scene at the time.

     

    This if for the scenes, I have another chapter on VD:s to, they could case a lot of pain to...  But that's another story!

    Please login or register to see this image.

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

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Forgot to mention another thing,

    do not have global values as triggers if you set theme in the code

    Please login or register to see this code.

    if you have 

    Please login or register to see this code.

    it will create a loop when you trigger that value again.

    Be really careful here, I saw when I went trough scene with set global value:s and cleaned theme out, suddenly all my max instances error went away!

     

    30% of CPU sound high, my system is now on 1-3% CPU and stable on that, sometimes is spikes at 20% for a few milliseconds.

    Keep digging on why so high CPU, disable on scene at the time.

     

    This if for the scenes, I have another chapter on VD:s to, they could case a lot of pain to...  But that's another story!

    Please login or register to see this image.

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

     

    thanks bozman that helps explain a lot, the more I learn the more gaps appear :-

    Overall I'm very happy with my setup, I seem to have created an 'issue' over the last few weeks as I started to build out my scenes.

     

    I'll need to get into functions more,... they seem to simplify the code more

     

    1)

    I'll use your "This is the heart of everything." code in my scenes.. %autostart

    Actuallyt if you have some time would you mid stripping out the execution code and just posting the "template" you use across all your scenes, variables, autostart code, repeatable functions, etc. I could replace all my code with that as you seem confident that it's rocksolid 

     

    2)

    I think I have one or two bugs throughout all my code (as I use the same template)  that is causing a race condition 

     

    3) 

    in #7 post of this topic above I posted an error that appears in a few of my scenes periodically, it seems to abort the scene and may be causing other issues like my high memory consumption . The execution code is very basic and the error is being called out in the peripheral code line 35 

     

    Could you take a look ?

     

    4)

    I do set some global variables - Could you explain what you meant in that space above as I have a few scenes that run all the time to determine occupancy and these may be another source of the problems (I'll post the code below, would you mind taking a look and seeing if you can spot a problem.

     

    Lastly in an effort to give something small back

    Have you used Imperihome ? its an overlay/alternative UI for HC2 and works great..

     

    Thanks again

    Frank

     

    code for #4 above

    Please login or register to see this code.

    Link to comment
    Share on other sites

    • 0

    Hi,

    Glad to help!

     

    4)

    I do set some global variables - Could you explain what you meant in that space above as I have a few scenes that run all the time to determine occupancy and these may be another source of the problems (I'll post the code below, would you mind taking a look and seeing if you can spot a problem.

     

    What I meant was in your case you're not using it but be aware

    Please login or register to see this code.

    you're code.

    Please login or register to see this code.

    My example was this, if you have a global value in the trigger part then it will trigger the scene again and again, every time that global value changes.

     

    About you're other question regarding the error message, not sure how string.format works but it could be something there, I'm guessing that you are trying to colorise the output.

    Please login or register to see this code.

    Simple template.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Hi,

    Glad to help!

     

    What I meant was in your case you're not using it but be aware

    Please login or register to see this code.

    you're code.

    Please login or register to see this code.

    My example was this, if you have a global value in the trigger part then it will trigger the scene again and again, every time that global value changes.

     

    About you're other question regarding the error message, not sure how string.format works but it could be something there, I'm guessing that you are trying to colorise the output.

    Please login or register to see this code.

    Simple template.

     

    Thanks a millions, this really helps.

     

    I have a few scenes where I would like a change to a global variable should trigger the scene so I can include that in the --[[ % header (trigger part ?)

    I'll also any device ID that is triggering a scene

     

    I'll also take your code to standardise my scripts if thats okay - I have one from Chaicka but it seems very complicated for what I'm trying to do

     

    One last one if I might.

    Do you have any issues with global variables not updating when you use "setGlobal"

    I have one for day/night based on lux and it seems unreliable

     

    I started out using a local variable tied to global variable and then leverage the local variable.

    This also seemed to give me issues as the scene triggering when the global variable changed 

    I have gone back to using just the global variable

    Please login or register to see this code.

    Do you know which is best practice ??

     

    It sounds like from what you said above if I want a scene to trigger on global variable I should include it in the triggers at the start under %globals and then use it as part of the while do to get rid of as many loops inside loops

     

    This approach would change the following code segment from 

    Please login or register to see this code.

    to this 

    Please login or register to see this code.

    Wrapping all this in your other suggestions would give me the following more straight forward scene

    Please login or register to see this code.

     ( I haven't it yet but should work ..)

    does this sound like the right approach ?

     

    BTW - should I always put a ; at the end of each line ?

     

    Thanks again

    Frank

    Link to comment
    Share on other sites

    • 0

    Let me quickly jump in, because I had to answer the ";" issue in another topic, so I can quickly copy/paste it here for your convenience:

    Please also note that I *never* use ";" unless it is required, which is almost... *never*.

    Please login or register to see this link.

    Quote:

    A semicolon may optionally follow any statement. Usually, I use semicolons only to separate two or more statements written in the same line, but this is just a convention. Line breaks play no role in Lua's syntax; for instance, the following four chunks are all valid and equivalent:

    a = 1

    b = a*2

    a = 1;

    b = a*2;

    a = 1 ; b = a*2

    a = 1 b = a*2 -- ugly, but valid

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Let me quickly jump in, because I had to answer the ";" issue in another topic, so I can quickly copy/paste it here for your convenience:

    Please also note that I *never* use ";" unless it is required, which is almost... *never*.

    Please login or register to see this link.

    Quote:

    A semicolon may optionally follow any statement. Usually, I use semicolons only to separate two or more statements written in the same line, but this is just a convention. Line breaks play no role in Lua's syntax; for instance, the following four chunks are all valid and equivalent:

    a = 1

    b = a*2

    a = 1;

    b = a*2;

    a = 1 ; b = a*2

    a = 1 b = a*2 -- ugly, but valid

     

    Thanks Peter and I appreciate you jumping in here to help with some of my basic questions. I have seen some of your post and discussions and they are light years ahead of where I am now

    Please login or register to see this image.

    /emoticons/default_icon_sad.gif" alt=":-(" />

     

    I pasted an error earlier the I seem to get periodically across a number of different scenes( 3 at least)

     

    Please login or register to see this attachment.

     

    Would you know what the error means or how I could find out what is causing it ?   

     

    Secondly if I may..

    I am looking to create a sort of standard scene template that i could reuse. In my discussion with bozman following his advise/suggestions I generated a code sample. It is #12 in this post near the text "Wrapping all this in your other suggestions would give me the following more straight forward scene

     

    would you have 2 minutes to give it the once over and let me know what you think or if you have suggestions ?

    The parts I'm looking to get correct are the header (triggers), scene start and trigger management and general good scripting practice

     

    Many Thanks again

    Frank

    Link to comment
    Share on other sites

    • 0

    I'm not 100% sure but I think that error ("unexpected character") sometimes happens when you copy/paste some code from a web site. I've seen it mentioned before. Some things that get changed are quotes (straight versus angled), dashes and spaces. If you want me to have a look at it, you can copy/paste your code into your favorite local text editor, then save that as txt and upload it here. Then I can run the code on my machine.

    Regarding programming. It is partly science, partly poetry. Which one of these identical performing snippets do you prefer? The code is runnable:

     

    Please login or register to see this code.

    Isn't that nice and compact? No ballast? Do you find it difficult to read (or understand)?

     

    Please login or register to see this code.

    Doesn't this one have a nice layout? Does it read like a recipe? Do you think it's (too) long?

    And what to think of this:

     

    Please login or register to see this code.

    Maybe the third way is... clean? But... is it also arty-farty? Does it make sense to turn your problem into a function? Does it make sense to group my functions into a table called "pgbr", so "your compare" and "my compare" won't clash if you copy paste them in the same script? Or is this... too far from "the usual stuff"?

    But I'll have at you post and see if I can formulate an opinion

    Please login or register to see this image.

    /emoticons/default_icon_wink.gif" alt=";-)" />

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • I'm not 100% sure but I think that error ("unexpected character") sometimes happens when you copy/paste some code from a web site. I've seen it mentioned before. Some things that get changed are quotes (straight versus angled), dashes and spaces. If you want me to have a look at it, you can copy/paste your code into your favorite local text editor, then save that as txt and upload it here. Then I can run the code on my machine.

    Regarding programming. It is partly science, partly poetry. Which one of these identical performing snippets do you prefer? The code is runnable:

     

    Please login or register to see this code.

    Isn't that nice and compact? No ballast? Do you find it difficult to read (or understand)?

     

    Please login or register to see this code.

    Doesn't this one have a nice layout? Does it read like a recipe? Do you think it's (too) long?

    And what to think of this:

     

    Please login or register to see this code.

    Maybe the third way is... clean? But... is it also arty-farty? Does it make sense to turn your problem into a function? Does it make sense to group my functions into a table called "pgbr", so "your compare" and "my compare" won't clash if you copy paste them in the same script? Or is this... too far from "the usual stuff"?

    But I'll have at you post and see if I can formulate an opinion

    Please login or register to see this image.

    /emoticons/default_icon_wink.gif" alt=";-)" />

     

     

    Thanks Peter,

    The first one seems to work best for me and easily understood

    2 seems too 'simplified' and as you say there wouldn't seem to be any advantage in turning the snippet into a function.

     

    I'm still learning Lua and like many new users on this forum I'm searching for some good resources. 

     

    Re the error - I'm using ZeroBrain (your suggestions, thanks)

    I saved it as .txt and it's attached

     

    you help and bozman's help is much appreciated

     

    -Frank

    Please login or register to see this link.

    Link to comment
    Share on other sites

    • 0

    I've run the script locally and on my HC2 and I don't get the error. I've "do-a-lized" the script (meaning, make empty if-then else statements and make do ... end blocks so much of the code runs without having to simulate all possible conditional paths) and doing so I've caught one unrelated error. You have "fibre:countScenes()" on line 52.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • thanks 

     

    in the meantime I'm disabling block of scenes and seeing what this has on the memory usage

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Back with some stats

     

    I disabled all the scenes - 23 in total

     

    RAM and CPU attached (RAM still at 30%)

     

    devices - active in the UI = 138 

    hidden - 178 in the UI (64 of these are from one of the alarm plugins that I don't need and cant find a way to un-install)

     

    does this look as expected ?

    Please login or register to see this attachment.

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • A quick thanks to all that contributed to this thread and in particular bozman, peter and Piotr (though another thread) .. in helping me try and solve my problem.

    I've learnt a huge amount and have some good ideas to chase and a huge amount of cleanup/tidy up to do. I also have a better understanding of lua and will simplify what I have there as well.

    Link to comment
    Share on other sites

    • 0

    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.

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