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

LUA to Read a Parameter Value from a Device


Question

Posted

Hi Everyone,

 

I have been adding Fibaro devices for many years in my home and finally have the time to begin some programming of scenes and QA's. I am a newbe in the programming area but very keen to learn.

I would like to read the value of a Fibaro Relay Switch in a QA

The device ID is 240 and the Parameter Value is 17 (Second Channel, time parameter for delay/auto on/off mode) which is 2 byte

I believe to change the value I use this,

 

hub.call(101,"setConfiguration",19,1,30)

where:

101 is the device-id

19 is the parameter to adjust

1 is the byte length

The new value is 30.

 

But I have no idea how to read the existing value?

 

Any help would be greatly appreciated.

 

Recommended Posts

  • 0
Posted (edited)

Please login or register to see this code.

 

Edited by Neo Andersson
  • 0
  • Inquirer
  • Posted

    Thankyou @Neo Andersson greatly appreciated. Can I ask as a newbie how in a QA I pass the device I’d and parameter into the function and then print the value in the debug window….

    • 0
    Posted
    8 hours ago, DannyDS said:

    Thankyou @Neo Andersson greatly appreciated. Can I ask as a newbie how in a QA I pass the device I’d and parameter into the function and then print the value in the debug window….

     

     

    I dont understand the question..What is the goal?

    • 0
  • Inquirer
  • Posted (edited)

    Hi @Neo Andersson

     

    I have a towel rail connected to the relay switch and a QA that has two buttons on it where i change my house mode to 'Summer' or 'Winter', that is how we are feeling with the weather and not the exact summer or winter weather.

    I have a delayed off parameter for the towel rail that I want to read the value of the parameter and display the value (that I will convert from seconds to hours) on a label in the QA. A button sets the value.

     

    Many thanks for your help!

    Edited by DannyDS
    • 0
    Posted
    19 hours ago, DannyDS said:

    Hi @Neo Andersson

     

    I have a towel rail connected to the relay switch and a QA that has two buttons on it where i change my house mode to 'Summer' or 'Winter', that is how we are feeling with the weather and not the exact summer or winter weather.

    I have a delayed off parameter for the towel rail that I want to read the value of the parameter and display the value (that I will convert from seconds to hours) on a label in the QA. A button sets the value.

     

    Many thanks for your help!

    I have showed you the function that can be used for reading a device parameter.. Used that function to read the auto off parameter of the device, if this is your intention.

    So use it. Read the parameter and print the value..

     

    Please login or register to see this code.

     

    • Like 1
    • 0
    Posted

    I also try to read the parameters from my devices, but I try to loop and get all devices.

     

        local device=api.get("/devices/")
        print(#device.." devices found!")
        for j = 1, #device do
            print(j.." - Id:"..device[j].id.." Name:"..device[j].name)
            local dev = api.get("/devices/"..device[j].id)
            for key,param in pairs(dev.properties.parameters) do
                print(param.id.."-"..param.value)
            end
        end
     

     

    Due to my lack in LUA experience, I encounter two issues:

    1. For some deviceIDs the loop crashes with an errormessage "bad argument #1 to 'for iterator' (table expected, got nil)"?

    2. For none of the devices the code goes into the for-loop and prints the parameter-data?

     

    I hope any of you guys can help me out here!?

    • 0
    Posted

    Anyone?

    • 0
    Posted
    On 6/4/2024 at 3:13 PM, MiZ said:

    I also try to read the parameters from my devices, but I try to loop and get all devices.

     

        local device=api.get("/devices/")
        print(#device.." devices found!")
        for j = 1, #device do
            print(j.." - Id:"..device[j].id.." Name:"..device[j].name)
            local dev = api.get("/devices/"..device[j].id)
            for key,param in pairs(dev.properties.parameters) do
                print(param.id.."-"..param.value)
            end
        end
     

     

    Due to my lack in LUA experience, I encounter two issues:

    1. For some deviceIDs the loop crashes with an errormessage "bad argument #1 to 'for iterator' (table expected, got nil)"?

    2. For none of the devices the code goes into the for-loop and prints the parameter-data?

     

    I hope any of you guys can help me out here!?

    Some devices don't have parameters, that is why you get the error message.

    What exactly you're trying to read? Just for a specific device?

    • 0
    Posted

    For the moment I just want to understand the build up. How can I check if parameters are present or not?

    • 0
    Posted

    If you request the parameters and you get the nil value back, they aren't there. You can check on the nil value. 

    And you can't loop through device number with +1, because the device numbers don't have to be sequential. 

    • 0
    Posted

    Does anybody have an idea on what the second point above is due to?

                2. For none of the devices the code goes into the for-loop and prints the parameter-data?

     

    It is probably my LUA-unexperience...

    • 0
    Posted (edited)

    As guys wrote you,...first check prameters table against nil value, and upon that continue..

    Try this code. I did not try it, but should work. But dont forget, if you have a lot of devices, this process might take quite a bit of time.

     

    Please login or register to see this code.

     

     

    Edited by Neo Andersson
    • 0
    Posted (edited)

    But this code still doesn't give me any parameter values?? It just gives me all Ids and Names.

    Edited by MiZ
    • 0
    Posted
    27 minutes ago, Neo Andersson said:

    As guys wrote you,...first check prameters table against nil value, and upon that continue..

    Try this code. I did not try it, but should work. But dont forget, if you have a lot of devices, this process might take quite a bit of time.

     

    Please login or register to see this code.

     

    Wait i will check it

    • 0
    Posted

    Please login or register to see this code.

     

    • 0
    Posted

    Still no parameters on my side!? Does this code work for you?

    • 0
    Posted (edited)
    1 minute ago, MiZ said:

    Still no parameters on my side!? Does this code work for you?

    yes, just roll through the devices..as not all of them have parameters..

     

    Please login or register to see this image.

    /monthly_2024_09/image.png.ecdac47903875939656d48b82200813a.png" />

    Edited by Neo Andersson
    • 0
    Posted

    Strange, I get nothing!

     

    I see you run it in a QA, could that be a difference to my scene?

    • 0
    Posted
    1 minute ago, Neo Andersson said:

    yes, just roll through the devices..as not all of them have parameters..

     

    Please login or register to see this link.

     

    change to this for better visibility

     

    Please login or register to see this code.

     

    1 minute ago, MiZ said:

    Strange, I get nothing!

     

    I see you run it in a QA, could that be a difference to my scene?

    I dont think so...I would be surprise,,I am not using scenes at all, so i cant tell you for sure..I have very rarly used scenes..but i doubt it is not working in scenes,,

    Try in a quickapp

    • 0
    Posted

    No difference in QA. Still no parameters printed?? Idea?

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