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

Hi @jgab,

 

I am converting my HC2 configuration to a brand new HC3 one.

I have discovered your TQAE tools :  Warm Respects!🙏

 

Today I think I have hit a bug in your TCP emulating tools:

 

I initialise a TCP soket  using:

          self.TCP.sock = net.TCPSocket({timeout = 5000})

          self.TCP.sock:connect(IP ,Port,{...

 

This device, I am successfully connected to, does not  send any thing before you ask (and I dont ask...)

 

Then, if I use

        self.TCP.sock:read(....

 

in real world:  the error function is call after 5s, as waited.

 

in TQAE world:  it loops enlessly it never falls into error callback function

 

     (and, even worth ?, it seems to receive some chars (\n) every xs with x varying from 30s to. But I feel that this point depends on My config)...

 

For your Info / or advices to me :-)

 

Link to comment
Share on other sites

  • Topic Author
  • Try to add copas=true in the header.

    Please login or register to see this code.

    and see if you get another behaviour. Without copas=true I'm trying to do some quasi-asynchronous IO. Copas makes the IO more asynchronous...

    Link to comment
    Share on other sites

    Hi @jgab,

    Copas = true does timeout as expected  Thanks,

     

    but I feel that it raises another issue:

    the time out error message is 'closed' on a read.

    and any attempt to write returns the same error. never goes in 'success' callback

     

    Today I think i won't have time to dig further ... Especially consdering that the codde works in real environment

    Link to comment
    Share on other sites

    On 7/29/2020 at 7:20 PM, jgab said:

    Interactive push works (sometimes,. I got some errors)

    Anyway, we can now do an interactive push in a QA that makes a callback to a function of our choice if the user press Yes. This was a bit more complex on the HC2.

    Please login or register to see this code.

     

    I was wondering if the still work ?

    I tried and i get the PUSH message on the iPhone, but not the YES/No option
    Is there some settings on the Phone i need to Allow ?

     

    Link to comment
    Share on other sites

  • Topic Author
  • 2 minutes ago, ChristianSogaard said:

    I was wondering if the still work ?

    I tried and i get the PUSH message on the iPhone, but not the YES/No option
    Is there some settings on the Phone i need to Allow ?

     

    I've had issues with it also when I tried the last time - I don't get any button. Anyone else using interactive push lately?

    • Like 1
    Link to comment
    Share on other sites

    Am I missing something with child devices? I have only recently got my HC3 and just learning how to develop Quickapps. I have some Lifx bulbs and have written a QA to control them. I have now created child devices for each bulb but it seem like the UI for children is very basic and can't be modified, is that correct? 

     

    UPDATE: found @jgab post on Hue example with adding child device interface of quickapp with a UI string (march 21). Possible progress. @jgab can the toolbox_ui functions be used along with fibaroExtra?   I'm not sure how the callbacks would be specified in createChild

     

    Ideally it would be good to define the UI for the child when it is created  (buttons, sliders, labels) and then have all the UI events handled by the parent  - can self.parent:xxx be set up in the callbacks?

    Edited by James R
    found more in forum
    Link to comment
    Share on other sites

    Some progress. I have used the UI build functions from the TollboxUI module and continue to use fibaroExtra. When createChild is called I get an error "no static 'notify' in class 'QuickApp'"

     

    This error is thrown when the annotateClass function is called by createClass in fibaroExtra. I'm defining my own class in my main but is there something I need to do to register the class so fibaroExtra can copy the annotations across?

     

    Edited by James R
    Link to comment
    Share on other sites

    On 6/20/2020 at 11:19 AM, jgab said:

    File: 

    Please login or register to see this attachment.

    v0.23 

     

    Some documentation on the basic toolbox <

    Please login or register to see this link.

    >

     

    I have started to assemble a toolbox of "QuickApp" functions that are missing or "good to have". Based on my best practices so far - or functions that I'm "missing". I'm using it as a baseline for the QAs I'm currently...

     

    OOF, what a treasure trove.

    Link to comment
    Share on other sites

  • Topic Author
  • 10 hours ago, RedRocketFire said:

    OOF, what a treasure trove.

    It's not developed/maintained anymore. I moved over to fibaroExtra

     

    Link to comment
    Share on other sites

    Thanks. I have got it all working now - my class constructor was not right in the parent. Using fibaroExtra and the UI builder functions from the old UI toolbox. I now have dynamic children based on discovery, each child gets the extra UI it needs and the events are handled by the class functions in the parent thanks to the QuickerAppChild functions which do all the work. fibaroExtra is so helpful.

     

    Link to comment
    Share on other sites

    Is there an event such as onView or onOpen, that I can use to update the QuickApp when it is first viewed ?  I need to populate some labels with current values.  In HC2, one just kept updating them.  I was hoping HC3 to be more refined.

    Link to comment
    Share on other sites

  • Topic Author
  • 4 hours ago, RohitNz said:

    Is there an event such as onView or onOpen, that I can use to update the QuickApp when it is first viewed ?  I need to populate some labels with current values.  In HC2, one just kept updating them.  I was hoping HC3 to be more refined.

    No, there is not. On the other hand I don't think there is a lot to gain unless the calculations of the values are extremely cpu intensive....

    Link to comment
    Share on other sites

    How can I read the current text value of a label in a QuickApp ?

     

    I tried QA:GetView and QA:GetValue but they don't exist.

    Link to comment
    Share on other sites

  • Topic Author
  • 14 hours ago, RohitNz said:

    How can I read the current text value of a label in a QuickApp ?

     

    I tried QA:GetView and QA:GetValue but they don't exist.

    There is a link in the first post in this thread...

    • Please login or register to see this link.

     

    another approach is to use or copy code from the fibaroExtra code library - has solutions to most of the "missing" QA functions.

     

    Edited by jgab
    Link to comment
    Share on other sites

  • Topic Author
  • Here is a way to have better format control over label text.


    We can add to this with a generic table template

    Please login or register to see this code.

     

    It creates a template with tags that makes it quick and easy to modify text or attributes in the table and update our label....

    Please login or register to see this image.

    /monthly_2023_04/image.png.44460334360b3f9f83be84bb509722c4.png" />

    Here is a <

    Please login or register to see this link.

    > to HTML4 table and tags.

    Edited by jgab
    double mustasch...
    • Like 3
    Link to comment
    Share on other sites

  • Topic Author
  • So with the Table label we can have fun like this

    Please login or register to see this attachment.

     

    or

     

    Please login or register to see this attachment.

    Edited by jgab
    Link to comment
    Share on other sites

    minecraft in fibaro 😆 But this opens so many doors in styling youre QA

    Link to comment
    Share on other sites

  • Topic Author
  • Here is an application of the Table class (now called 'UITable')

    Please login or register to see this attachment.

    It creates a calendar that can easily be updated with time and day and add an item that is mapped to an emoji. The time rows are automatically adjusted to the number of unique times across the week.

    The table is 300pixel width and fits on a mobile and is automatically adjusted in size to fit the contents.

    Please login or register to see this attachment.

    The code to make this table is

    Please login or register to see this code.

     

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

    • 4 weeks later...
    On 8/28/2022 at 1:09 AM, tinman said:

     

    TUYA over cloud is nice (easier to recognize device type/class), however i prefer to use local access. Attached TUYA QuickApp, for Näve Divora (Wisdom) lamps (CW/WW) and NEO Smart Bulb RGBW E27 (RGBW-WW).

     

    For local access you need the obtain the key and id from your device, so the "long way" over tuya dev portal, free account and dev local_key readout over web console is necessary.

    The good thing about tuya, once you get these keys, your subsripton can expire, the local_key never expires once generated and stored on device (whch happens during registration of device in the app itself).

     

    I will post soon other tuya QuickApps, and cloud maual (updated, that picture below is year old or so), but for now for these who knows how to use (or who wish to cry about my code hehe).

     

     

    Please login or register to see this link.

     

    Please login or register to see this attachment.

     

    Please login or register to see this attachment.

     

     

     

     

    EDIT: this is really dirty implementation, but of course working. The best way to work with TUYA is to read device template / information over cloud api, filter the included classes, types and conversions, assign then matching BUI element and create such child QA. But that means, one need still, at leat at time of creation, cloud acces, and when this is offline, one would be unable to create anything. So my implementation (wrote some of them for tuya) is always hardcoded for specific device, lot of them will match one of the other QA, but for others one need to change part of the code.

     

    EDIT2: When trying to implement / change the QuickAps above, to support your specific tuya device, you might use the attached tuya sniffer:

     

    Please login or register to see this attachment.

     

    How to use it:

    - instal the sniffer QA

    - ensure non of your mobile devices has TUYA app opened, if so, close them

    - set IP, device id and device key and save

    - disable wifi ony you mobile device, open the TUYA app (TUYA can handle only ONE connection locally, that's why)

    - click on "connect" button from this QuickApp (if the QuickApp is crashing, won't connect, click few times on disconect, and try again to connect)

    - click / select this you wish to sniff, e.g. you wish to know what need to be send to turn light on, cick "On" in the TUYA app

    - watch the console window on your HC3, you should see some messages:

     

    -- CB: 9 CMD: HEART_BEAT -> these are just "pings", the QuickApp need to ping the TUYA device from time to time

    -- CB: 10 CMD: DP_QUERY -> these are queries, showing your TUYA device current state, e.g.

     

     {"dps":{"23":736,"20":true,"22":467,"21":"white"},"devId":"f4326db31e606356632c"}

     

    dps -> is command set, it contains number:value, where number is the TUYA command and value the current value

    from above this means, TUYA command 23 is set to 736, 20 to true, 22 to 467, 21 to "white". From developer portal you might check what these command are representing, 20 is on/off, 23 (in this class) warm/cold white value * 10, 22 is brightness * 10 and so on. However, there is as well bit older set, e.g. 1 is o/off, 2 is mode, 3 is intensity/level of 2, etc. So  just don't worry if the QuickApp is showing different things as you might expect from API docummentation (you simply reading wrong one).

     

    devID: is your TUYA device id

     

    -- CB: 8 CMD: STATUS, followed by e.g.

     

      {"t":1665264639,"dps":{"20":false},"devId":"f4326db31e606356632c"}

     

    t is unix time timestamp, dps is again TUYA command, which the sniffer have seen while you did something in the TUYA app. In this case i turned light off

    devID: is your TUYA device id

     

    These TUYA command are of course defined in TUYA API, one might get crazy however if the device is combination of two or more devices, e.g. ceiling fan with light - the turn on/off is for the major device, ceiling fan, not for light :) But as said above, with the sniffer one can check every function within few minutes.

     

    Having all the TUYA command (and values) information it's easy to wrie own function, e.g

     

    local chandata = {
                    ['20'] = true
            }

    self:sendCommand(chandata)

     

    will send TUYA Command 20 with value "true"

     

    You might see other CBx CMD:yyy messages as well, they are more or less docummented on TUYA dev page (or in the QuickApp itself, tuyaAPI file)

     

     

     

    Hi! This is info is really helpful to me, since I am quite newbie around this "world".

     

    I am trying to pair a Tuya remote control within Fibaro HC3 following your steps without success. There you have some questions:

     

    - Once I add your sniffer ot my system, do I have to change only the "Variables" conditions or do I have to change items listed as "changeme" within the code? 

    - Is it normal that my devKey is something as "_UrO.E{c'54d***"??

     

    Anyway, as said, if I follow all your steps and I hit one button from my Tuya app, this is the info I get from the console, it doesn't matter where I hit, of even if I don't hit any button:

     

    [22.05.2023] [02:26:14] [DEBUG] [QUICKAPP372]: CB: 9 CMD: HEART_BEAT
    [22.05.2023] [02:26:19] [DEBUG] [QUICKAPP372]: tuya QA - DP_Query sent
    [22.05.2023] [02:26:20] [DEBUG] [QUICKAPP372]: {"dps":{"1":"study_key"},"devId":"10088605a4e57c******"}
    [22.05.2023] [02:26:20] [DEBUG] [QUICKAPP372]: CB: 10 CMD: DP_QUERY

     

    Would you help me, please? Thanks.

     

    Edited by Vicent13
    Link to comment
    Share on other sites

    • 2 weeks later...
    On 5/22/2023 at 2:01 AM, Vicent13 said:

    I am trying to pair a Tuya remote control within Fibaro HC3 following your steps without success.

     

    remote control? interessting, newer tried it, give me the name / product link

     

     

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