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

Set device property in QA


Bernhard Stockman
 Share

Question

In a QA I use fibaro.getValue(deviceID, property) to get the property value. I also need to set a device property value

but I can not find a corresponding fibaro.setValue function. How do I set a device property value from within a QA?

Link to comment
Share on other sites

Recommended Posts

  • 0

Here you should find what you are looking for.

Please login or register to see this link.

 

and here

Please login or register to see this link.

Edited by RH_Dreambox
Link to comment
Share on other sites

  • 0

Your own property with 

self:updateProperty(prop,val)

but you probably already know this.

 

Another QA, ex. a boolean "value" property

fibaro.call(ID,"updateProperty","value","true")

 

Here the argument is a bit fishy as the QA and scene framework seems to marshall the arguments differently.

If I send true to a QA from another QA it arrives as 1 (false as 0), if I send "true" it arrives as true.

So you need to test...

Link to comment
Share on other sites

  • 0

One can amuse oneself with this test.

 

QA 400

Please login or register to see this code.

QA300

Please login or register to see this code.

Log

Please login or register to see this code.

 

And the same calls to QA400 from a Scene

Please login or register to see this code.

...behaves just a little bit different 

...and it's really annoying.

This issue has been around since the HC3 came out.

 

This is the worst kind of bugs - the one that bugs out sometimes....

Imagine that you have a QA with a function that receives a string.

For months everything runs fine and then suddenly one day the QA function gets a string that happens to look like a number or a table - and it becomes the wrong type and your QA crash because you didn't expect it...

 

A general rule that can be derived from is that if you send a table or boolean, always json encode it and it will arrive as a table or boolean.

...and be careful to not use strings that look like tables, like "[1] First entry"  that will actually become the lua table {1}. And don't use "true" if you want to send it as a string, use something like "TRUE"...

...but in general it's a mess....🙄

 

Edit: Actually, the general rule is to json.encode every argument, then they arrive correctly. Strings that looks like tables will be quoted properly and it decodes right to a string.

Please login or register to see this code.

However, I see no reason why not fix this in the framework - it should be much more efficient to json encode the whole {...} table and unpack it on the receiving side. There is no reason that the whole responsibility should fall on the caller.

 

Edit2:

One thing still doesn't work

Please login or register to see this code.

because in a QA it's encoded wrongly to "{"200":42}

and in a Scene it crashes because the encoder does the right thing and refuse to encode a sparse array.

 

Edited by jgab
Link to comment
Share on other sites

  • 0
  • Inquirer
  • I have read the links provided by RH_Dreambox above several time without finding how to link

    devices to an QA.

     

    The thing I would like to do is to copy the power property value from an energy meter to the value property of that device.

    The reason for this is that the value proberty is much more visible in the home window of HC3. I have three energy meters,

    one for each phase in a three phase system. Below you see the result:

     

     

     

     

    Please login or register to see this image.

    /monthly_2021_07/Power.jpg.592b65ef8da96b972951f2c8e33cc740.jpg" />

     

    As you can see in the first colum the is power propery is reported at the bottom with very small letters.

    The large number is the value property, never used by the HC3 and therefore zero (besides Fas 3 where

    a strange value is set, Dont now how).

     

    I would like to have power property in the value property (the larget number).  Besides I need the redfine the unit for Fas2

    as it is W, not kWh. The Total Power Watt is produced by a simple QA:

     

    function QuickApp:onInit()
        self:loop()
    end
     
    function getPower()
        F1 = fibaro.getValue(70"power")
        F2 = fibaro.getValue(27"power")
        F3 = fibaro.getValue(33"power")
        F = F1 + F2 + F3
        return F 
    end
     
    function QuickApp:loop()
        self:updateProperty("power", getPower())
        fibaro.setTimeout(300000function() self:loop() end)
    end
     
    This works well but as mentioned now several time I would like to move the F1, F2 and F3 values to the value property of
    each device. Doing it for the QA itself is simple uisng self:updatePorperty but for each device I have no idea how that is done.
    The most straight forward solution would be a cuntion fibaro.setValue(device, property) butn that function does not seem
    to exist. When it comes to updateProperty I have only seen it used within a QA as self:updateProperty. Could it be used
    to another class the self e.g. the class of devices if such class exist?
    Link to comment
    Share on other sites

    • 0
    1 hour ago, Bernhard Stockman said:

    The most straight forward solution would be a cuntion fibaro.setValue(device, property) butn that function does not seem

    to exist. When it comes to updateProperty I have only seen it used within a QA as self:updateProperty. Could it be used
    to another class the self e.g. the class of devices if such class exist?

    From my first post...

    Ex. fibaro.call(device,"updateProperty","power",5.5)

     

    Your missing setValue you could define yourself as

    Please login or register to see this code.

     

    Edited by jgab
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Checked the Swagger output

    Please login or register to see this code.

    And, as mentioned above, the only thing I would do is copy the power field to the value field.

    In the Swagger output various entries have different color. Don't know why.

     

    Link to comment
    Share on other sites

    • 0

    Well, when I try it it works very well - however I try it on a QA with power property.

    But you are trying to set a real device (z-wave device) power property? Not sure you can set that if it's controlled by the hw device....

    Link to comment
    Share on other sites

    • 0

    you have to use api put in swagger, to test if the devices can accept it

     

     "{\"properties\":{\"power\":80}}"

     

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • The QA is a of type Power Sensor. The device are of type energy meter. No, I am not trying to set the real

    device. That is done via the parameter section in the settings.

    Link to comment
    Share on other sites

    • 0

    So I also made a Power sensor QA and I could update the power property.

    I did notice that in swagger (GET /devices/<ID>) the result seems to be cached. Even if I "executed" the GET several times after calling fibaro.setValue, the property in the device structure in the swagger result didn't update. That fooled me for a while. However, when doing GET on another device and then back to the Power sensor the updated property was shown in swagger. 

    Well, that was just swagger - the real QA was was always updated.

    Please login or register to see this code.

    return 99.0 (the schema knows it should be a float)

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Using this code:

        print("SET "99)
        fibaro.setValue(70,"power",99)
        fibaro.sleep(2000)
        print("GET ",fibaro.getValue(70,"power"))
    DEBUG Output
    SET 99
    GET 356.6
     
    Obviously the value have not been set.
     
    Link to comment
    Share on other sites

    • 0

    QA power sensor? then it should work, i use some of them

    Edited by tinman
    Link to comment
    Share on other sites

    • 0

    What is your Power sensor QA's code doing? Are you running in some loop with fibaro.sleeps that blocks all other handlers from running?

    If the QA is busy it will not handle the fibaro(70,"updateProperty,...) call.

    Edited by jgab
    Link to comment
    Share on other sites

    • 0

    You  could try to add this to your Power sensor QA  and see if you get the updateProperty call and with what values

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Yes, the updateProperty for the devices are within a loop:

     

    function QuickApp:loop()
        do
            local oldUpdateProperty = QuickApp.updateProperty
            function QuickApp:updateProperty(prop,val)
            self:debug("updateProperty called with ",tostring(prop),tostring(val))
            oldUpdateProperty(self,prop,val)
            end
        end
        pow = getPower()
        self:updateProperty("power", pow)
        self:updateProperty("value",pow)
        fibaro.setTimeout(300000function() self:loop() end)
    end
     
    As you see I have included your code and the result is:
    [26.07.2021] [08:18:21] [DEBUG] [QUICKAPP85]: updateProperty called with power 1087.7
    [26.07.2021] [08:18:21] [DEBUG] [QUICKAPP85]: updateProperty called with value 1087.7
    which is exactly the value of the QA. I have had no problem with updating the value property for the QA itself.
    The problems come when I try yo do this for the involved devices.
     
    The getPower() function is:
     
    function getPower()
        F1 = fibaro.getValue(70"power")
        F2 = fibaro.getValue(27"power")
        F3 = fibaro.getValue(33"power")
        fibaro.setValue(70,"value",F1)
        fibaro.setValue(27,"value",F2)
        fibaro.setValue(33,"value",F3)
        F = F1 + F2 + F3
        return F 
    end
     
    Here I have no problems in retrieving the power values for the devices. 
    The problems comes when I try to copy power property to the value property.
    I.e. no error is reported when saving but nothing changes on the devices
    when the QA runs.
     
    So, I can update the properties for the QA using self:updateProperty but I cannot update
    the same property for the devices.
     
    Link to comment
    Share on other sites

    • 0
    19 minutes ago, Bernhard Stockman said:

    Yes, the updateProperty for the devices are within a loop:

     

    function QuickApp:loop()
        do
            local oldUpdateProperty = QuickApp.updateProperty
            function QuickApp:updateProperty(prop,val)
            self:debug("updateProperty called with ",tostring(prop),tostring(val))
            oldUpdateProperty(self,prop,val)
            end
        end
        pow = getPower()
        self:updateProperty("power", pow)
        self:updateProperty("value",pow)
        fibaro.setTimeout(300000function() self:loop() end)
    end
     
    As you see I have included your code and the result is:
    [26.07.2021] [08:18:21] [DEBUG] [QUICKAPP85]: updateProperty called with power 1087.7
    [26.07.2021] [08:18:21] [DEBUG] [QUICKAPP85]: updateProperty called with value 1087.7
    which is exactly the value of the QA. I have had no problem with updating the value property for the QA itself.
    The problems come when I try yo do this for the involved devices.
     
    The getPower() function is:
     
    function getPower()
        F1 = fibaro.getValue(70"power")
        F2 = fibaro.getValue(27"power")
        F3 = fibaro.getValue(33"power")
        fibaro.setValue(70,"value",F1)
        fibaro.setValue(27,"value",F2)
        fibaro.setValue(33,"value",F3)
        F = F1 + F2 + F3
        return F 
    end
     
    Here I have no problems in retrieving the power values for the devices. 
    The problems comes when I try to copy power property to the value property.
    I.e. no error is reported when saving but nothing changes on the devices
    when the QA runs.
     
    So, I can update the properties for the QA using self:updateProperty but I cannot update
    the same property for the devices.
     

    But 70,27,33 are real devices? not QAs? (my thinking was that the patch for updateProperty should be applied to the QAs that were called by setValue)

    Link to comment
    Share on other sites

    • 0
    14 minutes ago, Bernhard Stockman said:

    Yes, they are real devices. Qubino Smart Meter.

     

    The answers you received here are about updating a QA properties, which you have also done.
    But updating properties in a physical device I do not think you can do.
    This means that you must then in some way try to overwrite the unit's own property which is "hard coded".

    Link to comment
    Share on other sites

    • 0

    Yep, these values are controlled by the meter - I would expect "sensors" to have read-only properties - what would it mean to change it? - you don't agree to the value the meter has measured? It's like trying to update the 'value' property on a door sensor to true - forcing it to report open even if it's not.

    What you can do is to create 3 Energy meter QAs that gets the values (and power) from the real devices. Then hide the real devices. The QAs properties you can set,

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

     Share

    ×
    ×
    • Create New...