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


Optimize LUA-script HC3 after aprox. 24h HC3 stalls


Apax
 Share

Recommended Posts

 

Hi all!!

Thank you all for this forum and all nice people that helping eachother out.

Now its my turn to ask a question regarding LUA scripting, a script that makes my system to stall within 24h

 

What the script basicaly does is that it checks if doors, windows, motionsencors etc is open or closed and then send it to a QA but also to a global value from a standard LUA scene.

I am running the QA on diffrent screens in my home to so i get a nice view of what´s going on. The global value i pick up then i am arming the house and sending it to a a TTS-script.

Always nice to hear a voice that tells me that a window is open etc... when i am leaving.

 

But i think something is draining resources, i have tried to only activate the script via Conditions and Triggers, but also via a loop with diffrent sleep times.

It does not say in Diagnostics that i am out of recourses 

 

se my sample below short version (The script works fine  but after aprox 24h HC3 stalls or not working as expected ). 

How can i do it better ? 

 

 

 

::BEGIN::

local var = {};
local debug = 1;

----------------WINDOWS------------
local Windows = "";
local WindowsAlarm = "";

local WindowsLiving = "";
local WindowsLivingAlarm = "";
local WLiving = fibaro.getValue(249, "value");

--...and 6 more sencors
    
----------------DOORS------------

local Doors = "";
local DoorsAlarm = "";

local Freezer = "" ;
local FreezerAlarm = "" ;
local DFreezer = fibaro.getValue(355, "value") ;

--...and 10 more sencors


----------------MOTION----------
local Motion = "";
local MotionAlarm = "";

local Kitchen = "";
local KitchenAlarm = "";
local MKitchen = fibaro.getValue(21, "value");

--...and 7 more sencors

 

 ----------------Switches 1st and 2nd floor----

--...About 30 switches 
 
 ----------------TEMPS----------------------
--... collecting temps round house

 

 ----------------Secure--------------------
local SecureFrontdoor = " "
local Parm = " "

-- ...Checking if frontdoor is locked and if it is armed etc... 

 

 ----------------Garage--------------------
  -- ... same with garage 

local Garage = "Garage : " ..IR ..Outlet ..Mainlight ..Port

 

 ----------------Setting Variable---------

if WLiving == true then WindowsLiving = "Livingroom" WindowsLivingAlarm = "Vardagsrums fönster, " end;

if DFreezer  == true then Freezer= "Frys, " FreezerAlarm = "Frysdörr. " end ;

if MKitchen  == true then Kitchen = "Köket, " KitchenAlarm = "Rörelse i köket, " end;

if fibaro.getValue(30, "value") == true then sink = fibaro.getName(30)..", "  end;


-------------CONSOLIDATE ---------------

    Windows = "Fönster: " ..WindowsLiving .." " .. Bathroom; -- for screens QA
    var.WindowsAlarm = WindowsLivingAlarm ..BathroomAlarm; 
    
    Doors = "Dörrar: " ..Refrigerator .." "..StoreTrash ;  -- for screens QA
    var.DoorsAlarm = RefrigeratorAlarm ..StoreTrashAlarm ;

 

    Motion = "Rörelse:" ..Kitchen .." "..Shower ;  -- for screens QA
    var.MotionAlarm = KitchenAlarm ..ShowerAlarm ;

 

-- .. and some more... 

 

-------------SEND UPDATES----------------------------------------------------------------------
fibaro.call(103,"updateView","windows","text", Windows);
fibaro.call(103,"updateView","doors","text", Doors) 
fibaro.call(103,"updateView","detectors","text", Motion);
fibaro.call(103,"updateView","avgtemp","text", avgtemp) ;
fibaro.call(103,"updateView","secure","text", SecureFrontdoor .."  " ..Parm );
fibaro.call(103,"updateView","garage","text", Garage) ;
fibaro.call(103,"updateView","first","text",first) ;
fibaro.call(103,"updateView","second","text",second) ;

fibaro.setGlobalVariable('Status',json.encode(var))


-------------DEBUG--------------

------Loop Me ------------------


fibaro.sleep(5*1000);
goto BEGIN

 

Link to comment
Share on other sites

A couple of refllections.

You have a scene and a QA - why not put all in the same QA?

 

QAs have another Lua engine and that may make a difference (5.3 vs 5.2).

Are you sure it's your QA/Scene, not something else - like the TTS or some other scene/QA?

 

I'm also a bit worried with the fibaro.call(103 to update the values of another QA.

Scenes are known for doing strange things with their values when passed as arguments to fibaro.call.

Ex. "777" becomes the integer 777 - which breaks updateView if it doesn't get a string as a value.

 

The fibaro.sleep could be replaced by a fibaro.setTimeout maybe - not sure if it helps but I don't trust sleep....

 

However, my  guess is that it's the web GUI from the QA (displayed on several screens?). There have been issues with this in the past and even if there seems to been an improvement there could still be issues.

 

You update every 5s with data even if it's unnecessary. 

Try this (defined at the beginning of the scene)

Please login or register to see this code.

and then replace the 

fibaro.call(103,...

with

updateView("windows",Windows) 

etc.

 

It will only update the UI when a value changes. Could make a difference - and it will run for 72 hours ;-)

 

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

  • Topic Author
  • Hi 

    Thanks for answering and for your nice comments. I will bring this in to a consideration. 

    Put every thing in to a QA , maybe it will improve stability 

     

    Yes it is a lot off "call 103" . it is diffrent text fieds in the QA that needs to be uppdated and as i said, it is working for a day :)

    But why not aim for 72h :D 

     

     

     

    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
    Reply to this topic...

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