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

Guys if I want to replace in a QA:

Please login or register to see this code.

in every full hour start at midnight

How to write it?

Thanks in advance

Link to comment
Share on other sites

8 hours ago, Sjakie said:

Guys if I want to replace in a QA:

Please login or register to see this code.

in every full hour start at midnight

How to write it?

Thanks in advance

for every full hour you can use 

Please login or register to see this code.

Didn't understand what do you mean by start at midnight? When to stop it?

Edited by cag014
Link to comment
Share on other sites

Thanks this will work for me and is okay it starts and no stop at all

 

Link to comment
Share on other sites

  • 2 weeks later...

@jgab,

 

I have really liked the TQAE. I have a small problem when I use it. If I go into the HC3 main menu drop down and try to hit "Device types" I only get a partial list of device types. Then, if I try to select one of the devices I get nothing displayed. I have seen this populated fully and able to drop down but it seems to come and go (mostly go) in my setup. Where does the TQAE get that information? I'm sure it's something I don't have set up correctly. Any thoughts?

 

Thanks

 

Peter

Link to comment
Share on other sites

  • Topic Author
  • 9 hours ago, PeterV959 said:

    @jgab,

     

    I have really liked the TQAE. I have a small problem when I use it. If I go into the HC3 main menu drop down and try to hit "Device types" I only get a partial list of device types. Then, if I try to select one of the devices I get nothing displayed. I have seen this populated fully and able to drop down but it seems to come and go (mostly go) in my setup. Where does the TQAE get that information? I'm sure it's something I don't have set up correctly. Any thoughts?

     

    Thanks

     

    Peter

    I just made a script that generated quick apps of all types in the HC3 and downloaded their json structs. So it's static. It's probably a year old so there are new types that have come.

    All the data is there in the web view but the drop down don't open anymore. It's implemented using bootstrap accordion js/css templates, and for some reason it's not working. Googled around and couldn't find any obvious reason why it shouldn't - tried the latest 5.3 version of bootstrap too and no difference. Will see if I get some time to dive deeper into it (anyone in the forum that worked with bootstrap and have an opinion?)

    In general, I mustered a few weeks fighting with css/bootstrap and html to get the web ui in place, but I haven't maintained it after that as I'm not using it in my daily work anyway (however, I do all my development in TQAE)

     

    I'm tinkering with a follow up on TQAE for vscode that is quite promising... a kind of hybrid python/lua plugin that can run QAs with the required runtime and still use the vscode Lua debugger... will come a post on that soon.

    Link to comment
    Share on other sites

    • 1 month later...
    On 6/4/2023 at 11:35 PM, tinman said:

     

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

     

     

    Sorry bro, I was out of place. 

     

    The product is a standing lamp with an IR remote control. What I do with Tuya is to "learn" the IR frequencies to program ON/OFF scenes.

     

    So the lamp itself does not have internet connection, it is more an IR universal remote the one that has it. The product comes from AliExpress and I don't know how to tell you the model, tbh. Tell me how can I do it and I will.

     

    Thanks again.

    Link to comment
    Share on other sites

  • Topic Author
  • Running api.get("/devices/hierarchy") through Graphviz

    Please login or register to see this attachment.

    • Like 2
    Link to comment
    Share on other sites

  • Topic Author
  • ...and with some data-mining, here with interfaces, properties and actions

    Please login or register to see this attachment.

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

  • Topic Author
  • I have a faint memory that someone posted something about an url that gave a web view of a single quickapp UI? (or device)

    Someone remembers that? something like http://<hc3 ip>/app/devices/<ID>... but not that...

    Edited by jgab
    Link to comment
    Share on other sites

    1 hour ago, jgab said:

    I have a faint memory that someone posted something about an url that gave a web view of a single quickapp UI? (or device)

    Someone remembers that? something like http://<hc3 ip>/app/devices/<ID>... but not that...

    Please login or register to see this spoiler.

     

     

    @jgab Did you mean this??:::

    http://<hc3 ip>/app/webView/devices/<ID>

    • Thanks 1
    Link to comment
    Share on other sites

    And if you lean towards the dark side :D

     

    Please login or register to see this code.

    • Like 2
    Link to comment
    Share on other sites

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

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

     

    Hi, is there a way to retrieve the status of my tuya device, whether locally or via cloud? I have a light and would like to be able to update a variable dynamically to on or off depending on the state.

     

    Any help here is greatly appreciated. Thanks.

    Link to comment
    Share on other sites

    On 9/4/2023 at 8:49 AM, erliang89 said:

    Hi, is there a way to retrieve the status of my tuya device, whether locally or via cloud? I have a light and would like to be able to update a variable dynamically to on or off depending on the state.

     

    Any help here is greatly appreciated. Thanks.

    I can't remember where I saw it (it might have been on the SmartThings site), but I saw something that allowed for local access to the device over your wifi. There was something of a kludge to get the appropriate information but it did work. At the time I had a couple of switches and I was playing with my old SmartThings hub. Since then I have migrated to the Z-Box Hub and found it to be a better platform for me. I also got rid of my Tuya based devices because I think I have fewer issues with my z-wave devices. I am trying not to clutter my wifi with unnecessary traffic and I prefer to avoid many cloud based devices. When I lose the internet, I lose access to those devices. Further, I am trying to avoid any systems which integrate with Chinese based software systems. My belief is that the CCP is using their clout to insinuate themselves into foreign countries' affairs through stealthy means. (Sorry for the political statement).

     

    I will try to seek out the information this weekend and post my findings here.

     

    Peter

    Link to comment
    Share on other sites

    On 9/4/2023 at 3:49 PM, erliang89 said:

    Hi, is there a way to retrieve the status of my tuya device, whether locally or via cloud? I have a light and would like to be able to update a variable dynamically to on or off depending on the state.

     

    TUYA app itself connects first over clound, and if device is in local network it does swich do local. My implementation is pure local only. Both local and cloud way shows the status of the device, as long the device is mains powered wifi device. For zigbee/thread one need "hub between", same for battery powered devcies, the "hub between" collects all the data and one can get the status of them from there (and of course control those which can be controlled)

    Link to comment
    Share on other sites

    On 2/22/2020 at 9:58 AM, jgab said:

    Here is an iCalendar QD. v0.11

    Please login or register to see this attachment.

      (new doc here 

    It's not strictly a tips & trick's but I'm awaiting a HC3 section for download - the next fw - and to find any bugs - before submitting to the general audience.

     

    I'm also not completely satisfied with the functionality yet...

     

    You configure it with a secret but public url to an icalendar (I tried with Google and iCloud and it works for me)

    Variables in code:

    CALURL=<url>
    CALNAME=<name>  -- ex. "Joe"

    Ex.
    Google  

    Please login or register to see this link.


     

    I had hoped to use the quickvaraibles panels to allow users to define the url without having to go into the code - of course they don't allow you to enter longer strings as values. (however, we can set longer strings with self:setVariable...)

     

    If successful the QD starts to read the calendar every 30min (can be changed) and schedules customEvents at the time of the event.

    The name of the customEvent depends on another variable 'CUSTOMEVENT'

    If CUSTOMEVENT=='title' then the customevent's name is just the title (spaces replaced with '_')

    if CUSTOMEVENT=='name' then the customevent's name is "iCalendar_"..CALNAME, ex. 'iCalendar_Joe'

    The userDescription of the event is always the full json encoded icalender entry.

    This is posted for all events in the calendar.

     

    Another trick. If the text of the event (description) contains lines with 

    Please login or register to see this code.

    and/or

    Please login or register to see this code.

    a customevent at start resp. end of the event will be posted with the name <eventA> resp. <eventB>

    Ex.

    A calendar entry with the text

    Please login or register to see this code.

    and if set to start at 20:00 and end at 05:00 will post customevent 'turnOnGarageLamp' at 20:00 and customevent 'turnOffGarageLamp' at 05:00

    You can use a block scene to trigger on these events and do the appropriate stuff - like turning on/off that lamp.

    Per default the QD will delete the events after 6s (to not littering the customevents panel list)

    There is a variable REMOVEDELAY that if set to nil will not remove the events after they have been emitted.

     

    The problem with blockscenes is that you can only use events that are defined, so you can pre-defined them and set REMOVEDELAY to false and it will not delete the events.

     

    If you update the calendar and want the QD to re-read the events immediately there is an UI button "Refresh calendar"

     

    Any bugs?

     

    P.S this was completely developed offline with the fibaroapiHC3.lua and ZeroBrane - and it worked almost directly when copy&pasted into the HC3. It's a real productivity boost to debug the code with a real debugger, set breakpoints and inspect variables etc..

    The only issue was that pesky setTimeout that can't schedule times too far away in the future.... need to replicate that limitation in the fibaroapiHC3.lua code :-) 

     

     

     

    @jgabJan hello,

    iCal is not working?

    I am getting this error while setting up.

    Or did i miss some step?

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

  • Topic Author
  • Well, I haven't touch that code for 3 years. I believe it has problem with some items - like recurring events etc. There is a lot of options to be able to parse a full ical spec and this is not a full implementation.

    Link to comment
    Share on other sites

    2 minutes ago, jgab said:

    Well, I haven't touch that code for 3 years. I believe it has problem with some items - like recurring events etc. There is a lot of options to be able to parse a full ical spec and this is not a full implementation.

    I don't have any recurring event at all. I think, if this was working some day, it must be my fault. I don't really know if I made all the steps needed. I just changed the CALURL and CALNAME, nothing more.

    Link to comment
    Share on other sites

    • 2 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 everything clear untill point that sniffer returns like encoded data,......do i miss something/Tuya changed something on their side/anything else?

     

    Thank you! 

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

    On 9/27/2023 at 6:32 PM, Juzio999 said:

    do i miss something/

     

    ensure no space signs in the variables, and ensure you copy/paste the special characters from tuya local password via tool like notepad (to not copy with formating/wrong character set)

     

    On 9/27/2023 at 6:32 PM, Juzio999 said:

    Tuya changed something on their side/anything else?

     

    yes, they changed last year how the local password looks like (it contains now special characters as well) and i had already some issues with one person, however i boudht exact same tuya device and it's working for me. 

    • Like 1
    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...