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

Global Function - well kind of, this works, but it is not perfect...


Question

Posted

So from time to another people like my self needs "global functions" - we are a bit tired/lazy of rewriting function codes all the time in all scripts and/or virtual devices.

 

Then some time ago I got the idea of using a VD (virtual device) as a "global function"-kind of solution. And today I got a bit bored so I tested it - and well it works. Not the perfect way or solution, however it is okay I guess... And if someone already figured this solution out, well sorry I just re-invented the wheel I guess

Please login or register to see this image.

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

 

For this test I decided to have a "Global Function" that controls my switches/dimmes. So I started with a VD, and added one key and three labels. The key is for executing the "global function", the labels are for "ReturnCode", "Arg1" and "Arg2". Arg1 is in this case the DeviceID I would like to control, and Arg2 is what I would like to do with this DeviceID. Now since I like to have only one function that covers both switch and dimming devices, I need some extra code. So let's start. Let's add the VD first:

 

GF_VD1.JPG

 

And then we need the key's LUA code, and the label fields:

 

GF_VD2.JPG

 

Since the above is screen copies, here is the LUA code in the key above:

Please login or register to see this code.

After this, all we need is for example a script that executes this "Global Function"-VD, and it look likes this:

Please login or register to see this code.

The above example turns off a lamp, and turns up to max another lamp, sleeps for 5 seconds, and then reverses the process. I added a 5 second sleep so that I had the time to verify that the lamps did what I ordered them to do

Please login or register to see this image.

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

 

Now let's look on a few things:

 

One needs to preset the Labels in the "Global Function"-VD, to have the right values, and also set the ReturnCode - now I can not set it in the VD, since the VD is fired in the background (multitasking) so I have to control this from the place I call this. Now that is okay for me. After the Labels has been set I simply push the button to "execute" the "Global Function"-VD.

 

This does work as intended.

 

With one limitation I guess, this is multitasking, and if a sceen fires this "Global Function" and then another does it at the same "time" - well I guess some sort of collision will happen, and well it will be "not nice" result I guess. One could of course add the extra code before the call to verify that the function is not executing or something, however I guess in the end well this is not a true global function - so it will never work perfectly - we will have to live with it until Fibaro let's us have true Global Functions.

 

Anyway it is a good experiment, and for some sort of applications/installations it may be enough and work just as intended - but be aware that there might be bumps on the road

Please login or register to see this image.

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

0 answers to this question

Recommended Posts

There have been no answers to this question yet

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