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

On 8/11/2022 at 2:28 PM, ABDULLAH258 said:

I try in it and write this code but I am not sure what is wrong 

Please login or register to see this code.

it give me error in console 

Please login or register to see this code.

can any one help me with this. 

sign chqnge avery time, see on tuya auth sign

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

On 8/27/2022 at 1:24 PM, meme81 said:

sign chqnge avery time, see on tuya auth sign

 

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

/monthly_2022_08/image.png.df85758baf70750e93986c993af4148a.png" />

 

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)

 

Edited by tinman
  • Like 5
  • Thanks 1
Link to comment
Share on other sites

Please help, with sending http from a HC3 to an external device. I am a beginner, so please explain ind detail ;-)

I have several Matrix Logic Group devices and they do not work 100% in Homey. That’s why I bought an HC3, where they are added.

How do I send a http from my HC3 to, in my case, a Homey using http?
I can send an http from my Homey to the HC3, but not the other way around. 
I want to use it to turn on a virtual button on my Homey Pro, when I press a button on the Matrix (that is included in the HC3). In that way I can use the Matrix buttons from the HC3, to control a flow on my Homey Pro.
The reason why I use a Homey, is because a am a novice, not very much in to programming :-) 

In principle, HC3 must send this command to the Homey Pro, when the button is pressed :
192.168.xxx.xxx/api/app/com.internet/Light when a button/switch is pressed.

Link to comment
Share on other sites

  • Topic Author
  • Posted (edited)
    On 8/30/2022 at 6:44 AM, Klavs van Hauen said:

    Please help, with sending http from a HC3 to an external device. I am a beginner, so please explain ind detail ;-)

    I have several Matrix Logic Group devices and they do not work 100% in Homey. That’s why I bought an HC3, where they are added.

    How do I send a http from my HC3 to, in my case, a Homey using http?
    I can send an http from my Homey to the HC3, but not the other way around. 
    I want to use it to turn on a virtual button on my Homey Pro, when I press a button on the Matrix (that is included in the HC3). In that way I can use the Matrix buttons from the HC3, to control a flow on my Homey Pro.
    The reason why I use a Homey, is because a am a novice, not very much in to programming :-) 

    In principle, HC3 must send this command to the Homey Pro, when the button is pressed :
    192.168.xxx.xxx/api/app/com.internet/Light when a button/switch is pressed.

     

    The buttons on the Matrix are of type centralSceneEvents. That means that they generate events with a keyId (ID number of the key pressed) and keyAttribute ('Pressed', 'HeldDown', and 'Released'.

    Please login or register to see this attachment.

    My first thought was to use a HC3 Scene as we can have conditions that triggers on centralSceneEvent and then let the action send the http command. 

    However, I'm a bit unsure how well it works as we can only have one instance of a Scene - and people may press many buttons quickly in a row.

     

    So, I would use a QA. The example below uses fibaroExtra so we can get the triggers that the Matrix device generate.

    The table in the beginning of the code maps buttons to urls.

    The table key is <deviceID>_<key id>_<key attribute>.

    I suggest that you run the QA and press buttons and see what key is logged (it will just warn that the button is not mapped to an url), and then go into the QA code (main) and edit the table.

    The QA can handle multiple Matrix devices.

     

     

    Please login or register to see this code.

     

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

    9 hours ago, jgab said:

     

    The buttons on the Matrix are of type centralSceneEvents. That means that they generate events with a keyId (ID number of the key pressed) and keyAttribute ('Pressed', 'HeldDown', and 'Released'.

    Please login or register to see this attachment.

    My first thought was to use a HC3 Scene as we can have conditions that triggers on centralSceneEvent and then let the action send the http command. 

    However, I'm a bit unsure how well it works as we can only have one instance of a Scene - and people may press many buttons quickly in a row.

     

    So, I would use a QA. The example below uses fibaroExtra so we can get the triggers that the Matrix device generate.

    The table in the beginning of the code maps buttons to urls.

    The table key is <deviceID>_<key id>_<key attribute>.

    I suggest that you run the QA and press buttons and see what key is logged (it will just warn that the button is not mapped to an url), and then go into the QA code (main) and edit the table.

    The QA can handle multiple Matrix devices.

     

     

    Please login or register to see this code.

     

    Hi Jan

     

    I looks like that the Matrix ID are not posted with value.keyId,value.keyAttribute though i see id in the code.

    At least when i tried the id was not resolved to the Matrix, just showing nil.

     

      quickApp:debugf("Matrix:%s key:%s, attribute:%s",id,value.keyId,value.keyAttribute)
      local key = string.format("%s_%s_%s",id,value.keyId,value.keyAttribute)

     

    [30.08.2022] [17:11:03] [DEBUG] [QUICKAPP1746]: Matrix:nil key:1, attribute:Pressed
     

    Edited by ChristianSogaard
    Typo
    • Thanks 1
    Link to comment
    Share on other sites

  • Topic Author
  • Posted (edited)
    31 minutes ago, ChristianSogaard said:

    Hi Jan

     

    I looks like that the Matrix ID are not posted with value.keyId,value.keyAttribute though i see id in the code.

    At least when i tried the id was not resolved to the Matrix, just showing nil.

     

      quickApp:debugf("Matrix:%s key:%s, attribute:%s",id,value.keyId,value.keyAttribute)
      local key = string.format("%s_%s_%s",id,value.keyId,value.keyAttribute)

     

    [30.08.2022] [17:11:03] [DEBUG] [QUICKAPP1746]: Matrix:nil key:1, attribute:Pressed
     

    Yes, it's a bug. Fixed in the code above but not the .fqa

    Should be

    Please login or register to see this code.

     

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

    4 minutes ago, jgab said:

    Yes, it's a bug. Fixed in the code above but not the .fqa

    Should be

    Please login or register to see this code.

     

    Confirmed it works - but you knew that already :-) Thank you for fast reply and great work 

     

    [30.08.2022] [17:58:10] [DEBUG] [QUICKAPP1746]: Matrix:73 key:1, attribute:Pressed

     

    Link to comment
    Share on other sites

    • 2 weeks later...

    i promised some time ago a Quick App for the really cool LOQED Touch Smart Lock, finally got some time to "finalize it". You can find it in here

     

     

     

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

    On 8/30/2022 at 8:06 AM, jgab said:

     

    The buttons on the Matrix are of type centralSceneEvents. That means that they generate events with a keyId (ID number of the key pressed) and keyAttribute ('Pressed', 'HeldDown', and 'Released'.

    Please login or register to see this attachment.

    My first thought was to use a HC3 Scene as we can have conditions that triggers on centralSceneEvent and then let the action send the http command. 

    However, I'm a bit unsure how well it works as we can only have one instance of a Scene - and people may press many buttons quickly in a row.

     

    So, I would use a QA. The example below uses fibaroExtra so we can get the triggers that the Matrix device generate.

    The table in the beginning of the code maps buttons to urls.

    The table key is <deviceID>_<key id>_<key attribute>.

    I suggest that you run the QA and press buttons and see what key is logged (it will just warn that the button is not mapped to an url), and then go into the QA code (main) and edit the table.

    The QA can handle multiple Matrix devices.

     

     

    Please login or register to see this code.

     

     

    Hi @jgab

    We got the integration you provided to work yesterday, with Fibaro HC3 and Homey. They guy asked for the code where truly happy. Thank you...

     

    I really like this syntax of writing, so i was wondering if a subset of above could be re-used in Eventrunner 4 ?

    A normal EV4 rule using the Matrix would look like this for me

    Please login or register to see this code.

     

    Would it be possible to simplify like this for the Matrix ?

    rule("['1001_2_Pressed'] => stuff with hueconnector-hue-v2-api")

     

    A mix of the HueConnector and above would also be great, perhaps better, because above finds the Matrix's automatic

    Like

    local Action = {
      ["1001_2_Pressed"] = "setTimeout(function() fibaro.call("Guest_room_Tim","setColor","green") end",

    or

      ["1001_2_Pressed"] = "Guest_room_Tim","setColor","green")",


    }

    Edited by ChristianSogaard
    Typo
    Link to comment
    Share on other sites

    Folks,

     

    how do I control the display format of the unit? This QA is of the typy Energy meter, uses self:updateProperty("unit""V"), and the result looks like subscript:

     

    Please login or register to see this image.

    /monthly_2022_09/985535659_Screenshot2022-09-16195158.png.e0cf38d1bab19ce3fbe17fafb8a7b02c.png" />

     

    Can I control subscript/superscript and font size? I didn't find anything like this in tinman's table. It seems to depend on device type as well. Some don't seem to have the "unit" property at all. For example Humidity sensor always has a superscript "%" regardless of the unit setting.

     

    Anyone who could share some light here?

     

    Thanks,

     

    jayrock

     

     

     

     

     
    Link to comment
    Share on other sites

    2 hours ago, jayrock said:

    how do I control the display format of the unit?

     

    This QA is of the typy Energy meter, uses self:updateProperty("unit""V"), and the result looks like subscript:

     

    Please login or register to see this link.

     

    Can I control subscript/superscript and font size?

     

    no you can't, all you can do is to use - if using own unit - to use special unicode characters instead of e.g. xx/yy

     

    2 hours ago, jayrock said:

    It seems to depend on device type as well. Some don't seem to have the "unit" property at all. For example Humidity sensor always has a superscript "%" regardless of the unit setting.

     

    that's right, some devices types are using the predefined unit (they have to), like humidity which is always in %.

     

     

    Link to comment
    Share on other sites

    Please advice me how to fix, in my two buttons QA I want:

    By external cmd change icon

    button On >> GV Test is "On"

    button two >> GV Test is "Off"

    Also reverse if GV Test is "Off" by another command  >>QA button2 change Icon

    I can't get it working

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

  • Topic Author
  • On 9/15/2022 at 10:24 AM, ChristianSogaard said:

     

    Hi @jgab

    We got the integration you provided to work yesterday, with Fibaro HC3 and Homey. They guy asked for the code where truly happy. Thank you...

     

    I really like this syntax of writing, so i was wondering if a subset of above could be re-used in Eventrunner 4 ?

    A normal EV4 rule using the Matrix would look like this for me

    Please login or register to see this code.

     

    Would it be possible to simplify like this for the Matrix ?

    rule("['1001_2_Pressed'] => stuff with hueconnector-hue-v2-api")

     

    A mix of the HueConnector and above would also be great, perhaps better, because above finds the Matrix's automatic

    Like

    local Action = {
      ["1001_2_Pressed"] = "setTimeout(function() fibaro.call("Guest_room_Tim","setColor","green") end",

    or

      ["1001_2_Pressed"] = "Guest_room_Tim","setColor","green")",


    }

    You have to turn 1001_2_Pressed into an event. Unfortunately events can not start with digits so we need to put the attribute first.

    Please login or register to see this code.

     

    • Thanks 1
    Link to comment
    Share on other sites

    On 8/30/2022 at 8:06 AM, jgab said:

     

    The buttons on the Matrix are of type centralSceneEvents. That means that they generate events with a keyId (ID number of the key pressed) and keyAttribute ('Pressed', 'HeldDown', and 'Released'.

    Please login or register to see this attachment.

    My first thought was to use a HC3 Scene as we can have conditions that triggers on centralSceneEvent and then let the action send the http command. 

    However, I'm a bit unsure how well it works as we can only have one instance of a Scene - and people may press many buttons quickly in a row.

     

    So, I would use a QA. The example below uses fibaroExtra so we can get the triggers that the Matrix device generate.

    The table in the beginning of the code maps buttons to urls.

    The table key is <deviceID>_<key id>_<key attribute>.

    I suggest that you run the QA and press buttons and see what key is logged (it will just warn that the button is not mapped to an url), and then go into the QA code (main) and edit the table.

    The QA can handle multiple Matrix devices.

     

     

    Please login or register to see this code.

     

    Hi @jgab

     

    I question for above QA

    Klavs sees these errors in his log, he exported the QA and I imported it to my HC3,

    It dont show this error, and seems to run fine. I changed a single Matrix value in the URL to test .

    Any idea why ?

     

    Attaching the Key structure as well.

     

    Please login or register to see this code.

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

  • Topic Author
  • 1 hour ago, ChristianSogaard said:

    Hi @jgab

     

    I question for above QA

    Klavs sees these errors in his log, he exported the QA and I imported it to my HC3,

    It dont show this error, and seems to run fine. I changed a single Matrix value in the URL to test .

    Any idea why ?

     

    Attaching the Key structure as well.

     

    Please login or register to see this code.

     

    Yes, it's a bug in the code res.status -> resp.status

    It should be 

    Please login or register to see this code.

    (fixed in the original post)

    • Thanks 1
    Link to comment
    Share on other sites

    38 minutes ago, jgab said:

     

    Yes, it's a bug in the code res.status -> resp.status

    It should be 

    Please login or register to see this code.

    (fixed in the original post)

    Sorry i wasn't awake here

    Thank you for your indefatigable help ?

    Link to comment
    Share on other sites

    On 9/24/2022 at 10:30 AM, jgab said:

    You have to turn 1001_2_Pressed into an event. Unfortunately events can not start with digits so we need to put the attribute first.

    Please login or register to see this code.

     

    Would it be possible to merge this QA into your Hue API 2.0 QA?

    So I easy could trigger HUE bulps from my MAtrix ?

     

     

    Link to comment
    Share on other sites

    here a way how to set zigbee values from QuickApp, example hue lamp colors. One can of course (try) to use it for other values.

     

     

     

    Link to comment
    Share on other sites

    On 8/28/2022 at 12: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.

     

     

    Hi tinman, I understand that you've integrated many Tuya devices into HC3 and would really appreciate your help.

     

    I have a ceiling fan with light that's Wi-Fi Tuya enabled that I really want to integrate into HC3, I have the Device ID and Local key but i'm having trouble trying to work out how to do the rest to integrate it into HC3. Could you please help me do the rest of the integration.

     

    Please login or register to see this link.

     

    Thanks for any help

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