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

Create global function


Question

Posted

Hello! This is probably a real newbie question, but how do I create a global function?

 

I have a couple of sceenes triggered by different events, Now I realize they have very much in common so I would like to create a Global function taking some parameters that can be called from all these scenes.

How and where can I define such a function?

 

Best regards, Mikael

 

 

Simple example:

----------------------

-- Scene 1

--[[
%% properties
33 value
–]]

-- Call function and do stuff with Id:s 33, 10, 12 and 14!

CallFunctionDoStuff(33, 10, 12, 14);

---------------------

-- Scene 2

--[[
%% properties
44 value
–]]

-- Call function and do stuff with Id:s 44, 20, 22 and 24!

CallFunctionDoStuff(44, 20, 22, 24);

---------------------

 

15 answers to this question

Recommended Posts

  • 0
Posted

Sorry you have stumbled on to one of the frustrations of LUA implementation on HC2 - no way to implement global functions.   You see many using a pattern that is parameters into a global variable.  Global variable read by scene/VD to perform common functionality.    Rather clumsy and a hurdle for more complex LUA developments ...

  • 0
Posted

See 

As a good starting point to get the idea.

  • 0
  • Inquirer
  • Posted

    Hmmmm.   This language is really a pain in somewhere....

     

    Is there some way I can use the HC2 as a "gateway" and do all the processing in another system instead? I'm just dreaming about developing in Delphi instead :-)

     

    Best regards, Mikael

     

    • 0
    Posted

    Well you can just build anything you want on Delphi and expose whatever you need via a json api, which in turn you can read from with lua on fibaro. For example the

    Please login or register to see this link.

     exposes all your speakers and functions via json. On which people create lua virtual devices/scenes where needed.

    • 0
    Posted
    On 2/5/2017 at 5:55 PM, ipsofacto said:

    Sorry you have stumbled on to one of the frustrations of LUA implementation on HC2 - no way to implement global functions.   You see many using a pattern that is parameters into a global variable.  Global variable read by scene/VD to perform common functionality.    Rather clumsy and a hurdle for more complex LUA developments ...

     

    Hi @ipsofacto

     

    I think it depends on how complex you want to get or what you're looking to do. The no global functions is a pain but for simpler stuff there are workarounds as @riemers said

    For example

    - I have a single scene 'alarm control' the activates my alarm. I set a global variable with SET, UNSET, NIGHTSET, etc and then call the 'alarm control' scene to do the rest.

    You could even extend this to a function such as roundup or encodeURL. Create a global variable to hold a parameter and a result. Put the function in a scene that will read the global variable, execute the function and pass the result back to the global variable. TBH - This approach works but I don't think this approach is more resource friendly that putting the function locally and if called a lot from a few scenes  or VD you may have collisions. 

    I use a mix of approaches and this is probably the same for most forum users.

    • 0
    Posted

    Indeed - I have used similar workarounds.   I would be interested to understand from Fibaro why a couple of obvious requests cannot be fulfilled.  The four most frustrating when trying to develop and exploit the fine underlying platform.  These don't seem to be difficult to address on the surface but we are requests are ignored and not even given a reason why it is harder than we can imagine...

     

    I have pretty much stopped tailoring and developing my installation because of these aspects.  

    1. Global Functions: What security or architectural problems prevent Fibaro from providing a "global functions with parameters" capability
    2. WIKI: Why not simply host a Fibaro: Wiki so we can publish what we do achieve in a more structured way than the forum -  there are plenty of volunteers who would happily moderate
    3. HTTP inconsistency:  why or why do we have different capability in scenes and virtual devices.  This is frustrating and confusing to learners, experimenters and tweakers!
    4. Edit code window:   for goodness sake give this more screen real estate ... Notepad++, zerobrain are great but we don't really need a full blown IDE (promised with some many other things previously)... just make that a proper window with appropriate sizing.

    You, Sankotronic and others are fairly prolific at the moment -  I really enjoy reading your successes and it has made me start to tweak again ... but if 1 to 4 were solved,  how much better would the community of passionate, engaged and active tweakers feel!

     

    Cheers!

     

    And of course ...  re-design the backup approach to allow more control by private user experts that are not resellers/VAR

    • 0
    Posted (edited)

    I raised this as a support query on the day I posted my comments.  I received an email today in response with absolutely zero useful information in the specific questions I raised.   I really look forward to the day that I can migrate away - it really is going down hill ... plug-ins anyone?   

     

    Dear Sir:
    First of all I want to apologize for such late answer, we had some issues during merging our systems.
    Thanks so much for your taking the time to share your feedback with us. We’re constantiously working to improve our system to meet our customers expectations.
    Please keep in mind that our services contain a lot of useful knowledge about our system (

    Please login or register to see this link.

    Please login or register to see this link.

    Please login or register to see this link.

    Please login or register to see this link.

    Please login or register to see this link.

    ).
    I hope you’ll have a great experience while using our system

     

    SO

     

    obviously great to have a reply - shame it wasn't an answer even in part to the questions.

     

    Edited by ipsofacto
    Clarification
    • 0
    Posted

    Hi @ipsofacto,

     

    very sad indeed..

    Fortunately this comunity gives a quit good support and some members have discovered things maybe Fibaro wasn't even aware of. I'm still learning much from thouse findings.

    I can only agree that that support from Fibaro is at least "weird"? besides expectation and that same i can say about documentation, which is only a part of complete documentation.

     

    • 0
    Posted

    I agree with @ipsofacto on all four aspects, but that is why I found it challenging and interesting to make code for this restricted box. Yes, HC2 is actually very restricted and it is really not that powerful as I was thinking at the beginning of my play with it. I manage to get to the limit of data that can be stored in global variables, but I was not warned of that. I realize that there is such restriction only after restarting my HC and then realizing that global variable does not contain any more data that was stored in it before reboot.

     

    I also managed to hit the limit of code that can be put under objects (buttons, sliders and main loop) of virtual devices! There is also no warnings or anything that tells you that you are about to hit the limit. No, no, no, you can save code and you realize that something is wrong only when it refuses to execute! I haven't yet checked if it is also deleted or partly destroyed after rebooting, but there is definitely a limit and it is set to such amount of code that you just can't write anything really serious. And just because of that reason it would be really nice to have global functions because they would definitely raise level of possibilities. Not to mention plugins, great idea, locked down and removed.

     

    Anyway, my goal to make system that can be easily installed and configured by users falls apart due to this restrictions. But I'm not going to give it up so easily. At the moment I'm making some compromises that I don't like, but I have to do so that this system can see daylight soon. I will have to do more research and learning but I'm convinced that anything is achievable and time is the only problem.

     

     

    • 0
    Posted
    12 minutes ago, Sankotronic said:

    I agree with @ipsofacto on all four aspects, but that is why I found it challenging and interesting to make code for this restricted box. Yes, HC2 is actually very restricted and it is really not that powerful as I was thinking at the beginning of my play with it. I manage to get to the limit of data that can be stored in global variables, but I was not warned of that. I realize that there is such restriction only after restarting my HC and then realizing that global variable does not contain any more data that was stored in it before reboot.

     

    I also managed to hit the limit of code that can be put under objects (buttons, sliders and main loop) of virtual devices! There is also no warnings or anything that tells you that you are about to hit the limit. No, no, no, you can save code and you realize that something is wrong only when it refuses to execute! I haven't yet checked if it is also deleted or partly destroyed after rebooting, but there is definitely a limit and it is set to such amount of code that you just can't write anything really serious. And just because of that reason it would be really nice to have global functions because they would definitely raise level of possibilities. Not to mention plugins, great idea, locked down and removed.

     

    Anyway, my goal to make system that can be easily installed and configured by users falls apart due to this restrictions. But I'm not going to give it up so easily. At the moment I'm making some compromises that I don't like, but I have to do so that this system can see daylight soon. I will have to do more research and learning but I'm convinced that anything is achievable and time is the only problem.

     

     

    I'm very interested in your new system/new approach......

     

    • 0
    Posted
    9 hours ago, TRicky said:

    I'm very interested in your new system/new approach......

     

     

    Hi @TRicky,

     

    What I'm working on you can check here:

     

    • 0
    Posted

    What about that?

     

     

    • 0
    Posted

    @Sankotronic

    Maybe you can strip some variables regarding to Languages to win some space.

    So you can offer us to download VD or Scene per region.

    Like Europe, Asia etc…
     

    • 0
    Posted

    Having spent a couple hours catching up on forum I see you can now at least pass parameters when calling a scene.  A small step forward ... global or library functions surely is not too much further and would really make VD and scene development worth the pain!

     

    did I miss the big announcement in the change log for that?

     

    certainly I have not seen it in any documentation?

     

    how did we find out?  Is there some restricted information source somewhere!

     

    cheers

    • 0
    Posted
    On 5/23/2017 at 11:03 AM, Ibie said:

    @Sankotronic

    Maybe you can strip some variables regarding to Languages to win some space.

    So you can offer us to download VD or Scene per region.

    Like Europe, Asia etc…
     

     

    No need for stripping languages at least with new approach at the moment. Actually today I added Norwegian to the list. For now, Asia is covered only for China since that language is listed on HC2. 

     

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