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


HC3 QuickApps coding - tips and tricks


jgab

Recommended Posts

  • Topic Author
  • 6 hours ago, FBerges said:
    Transfer string from a QA

    Hello
    I would like to transfer a string or a linked variable from a QA.
    I only get integers with this.
    self: updateProperty ("value", 54)
    How does something get transmitted?

    Example to illustrate what I want
    self: updateProperty ("value", "Hello world")
    self: updateProperty ("value", {"A1", true, 54})

     

    QAs definitions (what fields and properties they have) are defined by schemas that vary a little between devices. Sometimes the "value" property is a number, sometimes a boolean, and as in @tinman's example in the previous post that device has a state property that can be a string "Closed", "Opening" etc. ("state" is often a boolean for sensors)

    So, if your QA is ex. a "com.fibaro.binarySwitch" the value is a boolean,. If it is a "com.fibaro.multilevelSwitch" it is a number.

    What I get from your example is that you want to store an arbitrary value in a QA. You want the value to be accessible from another QA/Scene?  or you want to store the value in the QA from another QA/Scene?  Have you looked at quickAppVariables accessible with self:getVariable and self:setVariable?

    • Like 1
    Link to comment
    Share on other sites

  • Topic Author
  • 5 hours ago, FBerges said:

    That sounds good, but how do I create a QA with the type "com.fibaro.baseShutter"
    If I want to create a new QA, I don't see anything like that.
    The QA types are anything but a "com.fibaro.baseShutter"
    can you send me an empty QA with the type?
    Or better explain how I create it.
    Greetings Frank

    You can't do it from the GUI when you create the QA.

    The easiest way is to create the QA with some code in a scene or another QA

    Please login or register to see this code.

     

    Edited by jgab
    • Like 1
    Link to comment
    Share on other sites

  • Topic Author
  • You can retrieve the various device types that the system knows about with

    Please login or register to see this code.

    It's a hierarchical table meaning that subtypes appears as children to parent  types.

    The system has UI/schema representations for a limited set of "base types", and if you specify a more specific type it will infer the base type.

    You can see the base type in the device struct field .baseType

    ex. api.get("/devices/42").baseType

     

    Some types have "nice" UI interfaces, like the baseShutter that @tinman used in an earlier post.

    Another example is "com.fibaro.philipsHueLight" that gives us the color slider.

     

    Edited by jgab
    • Like 2
    Link to comment
    Share on other sites

    Good Morning
    So that with creating a QA worked.
    Then I took a look at which interface is available.
    There are no limits.
    I found that out.

     

    function QuickApp:onInit()
        self:debug("onInit")
        local d,b = __fibaro_get_device(self.id),false
        for _,i in ipairs(d.interfaces or {}) do 
            print("i = ",i)
            if i=="state" then 
                b=true
                break 
            end
        end
        if not b then 
            --self:addInterfaces({"state"}) 
        end
    end
     

    Then I tried to insert "state" but that doesn't work.
    Somehow I think I'm stupid.

     

    Link to comment
    Share on other sites

  • Topic Author
  • 16 minutes ago, FBerges said:

    Good Morning
    So that with creating a QA worked.
    Then I took a look at which interface is available.
    There are no limits.
    I found that out.

     

    function QuickApp:onInit()
        self:debug("onInit")
        local d,b = __fibaro_get_device(self.id),false
        for _,i in ipairs(d.interfaces or {}) do 
            print("i = ",i)
            if i=="state" then 
                b=true
                break 
            end
        end
        if not b then 
            --self:addInterfaces({"state"}) 
        end
    end
     

    Then I tried to insert "state" but that doesn't work.
    Somehow I think I'm stupid.

     

     

    I believe that types of interfaces are predefined  - and 'state' is not one of them  - you got an infinite loop of restarts eh?

    Interfaces added to a QA are tags that makes the system treat the QA in specific ways. Therefore tags that are unknown to the system doesn't make sense.

    Why do you want to add the interface? You want to add a property?

    Edited by jgab
    Link to comment
    Share on other sites

    It is clear that it is an endless loop.
    This is just a test to check what is there.
    Back to the problem.
    I just want to pass a string from the QA to a scene.
    It's best that way!
    self: updateProperty ("xyz", {"String1", "String2"})

    Then query in the scene with

    local a = fibaro.getValue (QA-ID, "xyz")
    print ("xyz =", a)
    if a == "OK" the
    .
    .

    This is a control output of a send command that the QA should take care of.

    String1 = "OK" everything sent
    String1 = "Error" not sent
    String2 = "" no error
    String2 = "Error illegal send data"

    That's how I thought it would be.
    Doesn't actually sound complicated.
    Certainly you can also do this with integer and coding, but that is not so elegant and easy to understand because there must always be an explanation.
    I think I do it with the integer and write the error in plain text in a QA variable then you can read it there if necessary.
    Certainly only a makeshift solution but a solution.

     

    Link to comment
    Share on other sites

  • Topic Author
  • 43 minutes ago, FBerges said:

    It is clear that it is an endless loop.
    This is just a test to check what is there.
    Back to the problem.
    I just want to pass a string from the QA to a scene.
    It's best that way!
    self: updateProperty ("xyz", {"String1", "String2"})

    Then query in the scene with

    local a = fibaro.getValue (QA-ID, "xyz")
    print ("xyz =", a)
    if a == "OK" the
    .
    .

    This is a control output of a send command that the QA should take care of.

    String1 = "OK" everything sent
    String1 = "Error" not sent
    String2 = "" no error
    String2 = "Error illegal send data"

    That's how I thought it would be.
    Doesn't actually sound complicated.
    Certainly you can also do this with integer and coding, but that is not so elegant and easy to understand because there must always be an explanation.
    I think I do it with the integer and write the error in plain text in a QA variable then you can read it there if necessary.
    Certainly only a makeshift solution but a solution.

     

    Ok, I understand.

    Short answer, you can't do that.

    As you know, fibaro.getValue only returns property values and you can't make up your own properties.

    You can hijack some existing property like "userDescription" to store values

     

    Please login or register to see this code.

    ...but it's not that elegant...
     
    You can also store it in a quickVar in the QA

    Please login or register to see this code.

     

     
    and in the scene define

    Please login or register to see this code.

     

     
     
     
    • Like 1
    Link to comment
    Share on other sites

    missing Own props it’s pain as for me... most my QA stored value in userdesicription... it’s ugly but it’s works

    For example my QA for ring 

    ring QA now has two child’s 

    1 - motion sensor 

    2 - switch what triggered by ding-button 

    the next child should be cam (I can grab photo every 30 sec according to policy by Ring) but can’t show cuz camera device can’t use own source :( 

    so, I have store pic iin... ta-da - user description:( and in scene can trigger and send this pic to home telegram channel 

    another pain async calling 

    if my ring device call by snapShort method - device do it.. but response will asynchronous by some reasons 

    and how to flag caller what pic now is ready for use - I do not know.... 
    but if we will have a user props for device it will be ok... prop for pic, prop for action kind etc

    hey @A.Socha please allow to setup user defined properties at least for generic devices 

    please.... 

    • Like 1
    Link to comment
    Share on other sites

    Interesting stuff ???

     

    yesterday I was just looking for the right property with the Api and the different types of devices. I haven’t found it ?

     

    In the dashboard the icon shows the value followed by the unit. Below is the name and below the name there is also some tekst, depending on the type “off”, “on” plus the used energy, or “transfer ok” etc. 
     

    For a multilevelsensor , what is the name of that property?

    Link to comment
    Share on other sites

    14 hours ago, 10der said:

    @petergebruers thank you but I know how work MQTT

     question was how to develop this behavior! How to add option for pinging / reconnection or how to set callback on disconnected evened 

    Sorry @10der - we talked about mqtt client for HC2 and I forgot about that. I am on to it. I have a mqqt test scene and I'll report back.

    Link to comment
    Share on other sites

    1 hour ago, SmartHomeEddy said:

    there is also some tekst, depending on the type “off”, “on” plus the used energy,

    Educated guess, if the device has property "power" then it will be shown as "... W"

     

    1 hour ago, SmartHomeEddy said:

    or “transfer ok” etc. 

    I am sure about this one, it is actually 2 properties: "log" and "logTemp". I happen to know because I have a logger script and it will print for example:

    Please login or register to see this code.

    • Like 1
    Link to comment
    Share on other sites

    In this case they don't have a power property. I'm looking for the text on the bottom of these icons:

     

    Please login or register to see this image.

    /monthly_2020_07/image.png.de546d1176603dd72edee70ef964e1e7.png" />

     

    These are the types:

    com.fibaro.temperatureSensor / com.fibaro.humiditySensor / com.fibaro.multilevelSensor / com.fibaro.multilevelSensor
     
    I would like to show a short text for instance to show the air quality (GOOD, SATISFACTORY, POOR, etc). 
     
     
    Edited by SmartHomeEddy
    Link to comment
    Share on other sites

    9 minutes ago, SmartHomeEddy said:

    would like to show a short text for instance to show the air quality (GOOD, SATISFACTORY, POOR, etc). 

    self:updateProperty("log", "GOOD")

    • Like 2
    Link to comment
    Share on other sites

    5 hours ago, 10der said:

    self:updateProperty("log", "GOOD")

     

    6 hours ago, petergebruers said:

    I am sure about this one, it is actually 2 properties: "log" and "logTemp". I happen to know because I have a logger script and it will print for example:

     

    Yes, thanks ?

     

    Please login or register to see this attachment.

     

     

    Edited by SmartHomeEddy
    • Thanks 2
    Link to comment
    Share on other sites

    20 hours ago, 10der said:

    question was how to develop this behavior! How to add option for pinging / reconnection or how to set callback on disconnected evened

     

    Okay so had to test that, there is no info on what the errors mean. But I tried MQTT server and client disconnects and suspends and checked with Wireshark. This is what I think is a good start to build on:

     

    Please login or register to see this code.

    The code also "resists" bogus URLs in the "connect" part (using pcall) at startup, and if the startup does not run then nothing in "connect" will get called. So even though self.client will be nil in that case, no code uses this.

     

    I really should spend more time with MQTT... But I have to go now...

    • Like 2
    • Thanks 1
    Link to comment
    Share on other sites

    8 hours ago, SmartHomeEddy said:

     

    Please login or register to see this attachment.

     

     

     

    was wondering what unit is ug/m³, so ran my own test

    1.8.whatsoever app

     

    Please login or register to see this image.

    /monthly_2020_07/image.png.0c319169eafe9857d0dd7e737172c6cb.png" />

    and BUI

     

    image.png.7a95163feb59330a1afed4b87c71f06b.png

     

     

    first one is 12,34 μg/m³, second one 12,34 ug/m³, third one 12,34 mg/m³

     

    Knowing that Fibaro is using μg/m³ or μg/m3 in templates, i thought it might be good idea to use as well .. but it seems to be not ^^

     

    Edited by tinman
    Link to comment
    Share on other sites

    15 minutes ago, tinman said:

    Knowing that Fibaro is using μg/m³ or μg/m3 in templates, i thought it might be good idea to use as well .. but it seems to be not ^^


    I saw the μ was translated to M, I think because of the uppercase. So I used u to be as close as could be ? 

     

     

    Edited by SmartHomeEddy
    Link to comment
    Share on other sites

    And trying to get a linefeed in the “log” text, hasn’t been successfull up til now.
     

    Please login or register to see this code.


     

    Please login or register to see this attachment.


     

    And can I make that “0” zero value disappear ? 
     

     

     

    Edited by SmartHomeEddy
    Link to comment
    Share on other sites

    1 hour ago, tinman said:

     

    was wondering what unit is ug/m³, so ran my own test

    1.8.whatsoever app

     

    Please login or register to see this link.

    and BUI

     

    Please login or register to see this link.

     

     

    first one is 12,34 μg/m³, second one 12,34 ug/m³, third one 12,34 mg/m³

     

    Knowing that Fibaro is using μg/m³ or μg/m3 in templates, i thought it might be good idea to use as well .. but it seems to be not ^^

     

     

    r u looking for this?

    Please login or register to see this attachment.

    1 hour ago, SmartHomeEddy said:

    And trying to get a linefeed in the “log” text, hasn’t been successfull up til now.
     

    Please login or register to see this code.


     

    Please login or register to see this attachment.


     

    And can I make that “0” zero value disappear ? 
     

     

     

    nope.

    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
    Reply to this topic...

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