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

fibaro:callGroupAction working?


Question

Posted

I was playing around with the LUA command I only recently noticed: fibaro:callGroupAction. Would be quite handy to e.g. turnon/turnoff all lights in a room with a single command. However, when I try to use it, it does not seem to work. See the script below:

 

Please login or register to see this code.

Running this scene provides the following output:

Please login or register to see this code.

It seems that the filter is not applied to the groupaction as it returns all my devices and switches off all the lights/devices in my house (instead of only the ones in room 4 as I defined in the filter <data>. Anything I missed/doing wrong, or is this a bug? I'm running 4.110.

 

Thx, Rene.

15 answers to this question

Recommended Posts

  • 0
Posted (edited)

Hi, so i was searching for how the "getDevicesId" command worked as the code on the developer page wasn't working and i found the solution to my problem.

My situation was the opposite of yours, i got "callGroupAction" to work.

 

So it seem that the "data" structure is different for the 2 commands?

Im not an expert programmer but using your example i now understand how to use "getDeviceId" command.

 

The callGroupAction seems to need a different data set. This is my code.

I use it to get all IDs of the room when i couldn't get the developer code to work.

 

Please login or register to see this code.

 

Edited by speedy
  • 0
  • Inquirer
  • Posted

    Thanks for this, I'll try your code when at home. Same as you I struggled with the code provided on the developer page, wasn't working. Also interesting to see that in your structure the filter seems to apply an OR (i.e. in your example select devices in room 4 OR 5 OR 6). In my example I always got an empty set when I selected multiple rooms (roomID={4,5,6}), so it seems that an AND function is used in my example...

     

    But cool, so you could use in your example also a direct command to e.g. switch off all lights selected by the filter by using fibaro:callGroupAction("turnOff", data) command.

     

    Thx for sharing.

    • 0
  • Inquirer
  • Posted

    BTW, did you get/find what the   args = { 1 } means in the filter? What if you change to 0 or 2? Again, I'll play around with this later ;-)

    • 0
    Posted
    1 hour ago, ReneNL said:

    Thanks for this, I'll try your code when at home. Same as you I struggled with the code provided on the developer page, wasn't working. Also interesting to see that in your structure the filter seems to apply an OR (i.e. in your example select devices in room 4 OR 5 OR 6).

    Yes, its wired that its so different between the 2 commands.

    I actually find the way you did it very logical and easy to understad in the data structure. The {args} (developer with "filter") data structure is more complex and not as logical  (to me).

     

    I think its and AND function I'm using, it checks roomID 4 And 5 And 6 for the specific devices.

     

    1 hour ago, ReneNL said:

    In my example I always got an empty set when I selected multiple rooms (roomID={4,5,6}), so it seems that an AND function is used in my example...

     

    This function work for me, i get all the devices in all the rooms specified.

     

     

    1 hour ago, ReneNL said:

    But cool, so you could use in your example also a direct command to e.g. switch off all lights selected by the filter by using fibaro:callGroupAction("turnOff", data) command.

     

    Yes, if works great wit the command: fibaro:callGroupAction("turnOn", data)

     

     

     

    And thank you for sharing in your post, where would i be without nice people sharing code! :-) 

    • 0
    Posted
    1 hour ago, ReneNL said:

    BTW, did you get/find what the   args = { 1 } means in the filter? What if you change to 0 or 2? Again, I'll play around with this later ;-)

    No, i tried 0,1,2, and 55 with no difference in returned answers :-) 

    • 0
    Posted

    anyone got any bright ideas why the data structure for filters would be different ... anything smarter than two different developers neither of whom appear to talk with each other or test what they are doing.   my bet,  iOS app developer uses and built groupaction into server side code base and Android developer went with and developed getdevicesID .... i.e. they don't even talk to each other let alone us poor users.   really not very clever.

     

    • 0
    Posted (edited)
    On 14-6-2017 at 11:43 PM, ipsofacto said:

    anyone got any bright ideas why the data structure for filters would be different ... anything smarter than two different developers neither of whom appear to talk with each other or test what they are doing.   my bet,  iOS app developer uses and built groupaction into server side code base and Android developer went with and developed getdevicesID .... i.e. they don't even talk to each other let alone us poor users.   really not very clever.

     

    I do know a bit about this... The oldest http API to search for data is the "devices" API that returns data (in JSON format) for all devices or a device meeting a certain set of criteria. Try this in a browser:

     

    Please login or register to see this code.

    That should return all data of all Wall Plugs you have.

     

    Because it takes some "string manipulation and juggling" to build that URL, Fibaro decided to provide us with a more Lua-native solution (that actually builds and calls the same URL)

     

    Please login or register to see this code.

    The print and the json encode are e (neat) trick to print out the resulting table of IDs.

    If you look at the output of the http call, you will see there are properties "at the root" of the data structure, like "type", but other data sits below "properties".

     

    Please login or register to see this code.

    This prints the IDs of the devices that meet two criteria: the wall plug tape and the device is on. Note the extra table structure under "properties".

     

    The result of the http API is a data structure, full of information and the Lua getDevicesId() actually throws away all that date and leaves only the IDs.

     

    Much, much later the "callGroupAction" was introduced (maybe around firmware 4.100, I can't remember. But it didn't exist in 4.080). I bet the idea behind it was that very often you do a "getDevicesId" followed by a very simple action like "turnOff". So instead of looping over the result of that call, you could use this:

     

    Please login or register to see this code.

     

    With my elaborate white spacing and indenting that looks daunting, doesn't it? That's because at different levels, you can have arrays of values. But once you see where to plug in the fields and their values, it's quite the same...

     

    For api functions that need extra arguments, on has to set args to a table containing the arguments. Like this:

     

    • If it's a dimmer and you want to set the brightness to 25 --> args = {25}
    • If it's a RGBW and you want it to set to orange (for my strip R=255 and G=25) --> args = {255,32,0,0}
    •  

    If you don't need extra arguments, leave out args or set args = nil to make that explicit.

    Please login or register to see this code.

     

     

    Edited by petergebruers
    Explain "args"
    • Thanks 1
    • 0
  • Inquirer
  • Posted

    Thanks @petergebruers, as always your posts provide some true insights and deepens my understanding of our little box :-) Thx!

    • 0
    Posted

    Indeed - helped thanks Peter

    • 0
    Posted
    On 15.06.2017 at 1:02 PM, petergebruers said:

    With my elaborate white spacing and indenting that looks daunting, doesn't it? That's because at different levels, you can have arrays of values. But once you see where to plug in the fields and their values, it's quite the same...

     

    I don't know why "args" is there.

     

    Thank you, @

    Please login or register to see this link.

     for the explanation. So I have a code below, working well:

     

    Please login or register to see this code.

    Please login or register to see this code.

     

    But, what if I need to use "setValue" instead of "turnOn"? How callGroupAction must be used? Is it possible at all?

     

    • 0
    Posted
    20 hours ago, cashe said:

    (...)

    But, what if I need to use "setValue" instead of "turnOn"? How callGroupAction must be used? Is it possible at all?

     

     

    Ah, thanks for asking! That's what args is for... Just put the part after "setValue" in the args table. Works for api functions that need extra arguments. Like this:

    • If it's a dimmer and you want to set the brightness to 25 --> args = {25}
    • If it's a RGBW and you want it to set to orange (for my strip R=255 and G=25) --> args = {255,32,0,0}

    If you don't need extra arguments, leave out args or set args = nil to make that explicit.

     

     

    Please login or register to see this code.

     

     

    • 0
    Posted
    17 hours ago, petergebruers said:

    Ah, thanks for asking! That's what args is for... Just put the part after "setValue" in the args table. Works for api functions that need extra arguments. Like this:

    • If it's a dimmer and you want to set the brightness to 25 --> args = {25}
    • If it's a RGBW and you want it to set to orange (for my strip R=255 and G=25) --> args = {255,32,0,0}

    If you don't need extra arguments, leave out args or set args = nil to make that explicit.

     

    Thank you! It works!

    • 0
    Posted

    @petergebruers,

     

    are there any other filtering operators known to you besides propertyEquals like propertyGreater... 

    Or maybe any other way of filtering ON devices. 

     

    Please login or register to see this code.

     

    true is not working on the dimmers. Since propertyValue is a table one could provide all the values from 0 to 99 but...

    • 0
    Posted
    On 4/23/2021 at 6:55 AM, Jacławiciel said:

    @petergebruers,

     

    are there any other filtering operators known to you besides propertyEquals like propertyGreater... 

    Or maybe any other way of filtering ON devices. 

     

    Please login or register to see this code.

     

    true is not working on the dimmers. Since propertyValue is a table one could provide all the values from 0 to 99 but...

     

    Hi @petergebruers,

     

    Thanks for share your knowlege. Could you help me? i tried to use the "propertyEquals" to filtering ON dimmer devices too but i had not success. Do you know where the error is? Thanks in advance. 

     

                        Hernán

     

    • 0
    Posted
    On 7/24/2022 at 6:54 PM, Herni said:

    Could you help me?

    1) I am holiday

    2) My HC2 is turned off

     

    Maybe later

    • Like 1

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