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


Recommended Posts

Posted (edited)
23 hours ago, jgab said:

So to read in a json file from the pc when you run in the emulator you can do

I have created this QA:

if require and not QuickApp then require('hc3emu') end

--%%name=testQA
--%%description=Test QuickApp
--%%type=com.fibaro.binarySwitch
--%%offline=true


function QuickApp:onInit()
  self:debug("welcome")
  local data
  if fibaro.hc3emu then -- We run in the emulator
    local f = fibaro.hc3emu.lua.io.open("jgabsQAs.json", "r")
    assert(f,"Couln't open the file")
    data = f:read("*a")
    f:close()
    
    if data == nil then
      self:debug("data is nil")
    else
      self:debug("data is not nil")
      print("data", data)
    data = json.decode(data)
    end
    --return data
  else -- running on HC3
    data = {}
  end
end

 

Note that I do not have any access to my HC3  working from another network.

Working but I am getting the following DEBUG message with an 'event handler error':

Process started
[23.05.2025][20:45:49][SYS] Parsing TestQA.lua directives...
[23.05.2025][20:45:50][SYS] Main QA file TestQA.lua

HC3Emu - Tiny QuickApp emulator for the Fibaro Home Center 3, v1.1.6
[23.05.2025][20:47:00][SYSERR]    Event handler error: ...apps\luarocks\current\rocks\share\lua\5.4\hc3emu\api.lua:192: attempt to call a nil value (method 'match')
[23.05.2025][20:47:00][SYS] Starting QuickApp 'testQA'
[23.05.2025][20:47:00][DEBUG ][TESTQA5001]: welcome
[23.05.2025][20:47:00][DEBUG ][TESTQA5001]: data is not nil
[23.05.2025][20:47:00][DEBUG ][TESTQA5001]: data [
  {"user":"jangabrielsson","repo":"EventRunner5","name":"EventRunner5.fqa"},
  {"user":"jangabrielsson","repo":"Dirigera","name":"Dirigera.fqa"},
  {"user":"jangabrielsson","repo":"HassQA","name":"HASS.fqa"},
  {"user":"jangabrielsson","repo":"SonosQA","name":"SonosPlayer.fqa"}
]

 

 

Edited by Christb
add a note
  • Topic Author
  • Posted

    It's a bug when running in offline and when starting up. 

    It tries to calculate the sunset/sunrise to use offline, but a function call was wrong.

    Will fix in 1.1.9 tomorrow.

    • Like 1
    Posted
    20 hours ago, jgab said:

    Will fix in 1.1.9 tomorrow.

    Yes I do not have any more the Event handler error but before starting the QA the emulator needs a little more than a minute, normal?

  • Topic Author
  • Posted
    12 hours ago, Christb said:

    Yes I do not have any more the Event handler error but before starting the QA the emulator needs a little more than a minute, normal?

    No, it's not normal. Running offline or online?

    If it starts up after more than a minute (as opposed to crashing), the issue must be that it takes a long time to read in data from the HC3.

    It does a api.get("/devices") when starting up online.

    Posted (edited)
    3 hours ago, jgab said:

    No, it's not normal. Running offline or online?

    I am still offline using the QA I gave you the code in my previous post.

    [24.05.2025][19:07:35][SYS] Main QA file TestQA.lua
    HC3Emu - Tiny QuickApp emulator for the Fibaro Home Center 3, v1.1.9                                   
    [24.05.2025][19:08:46][SYS] Starting QuickApp 'testQA'                                                              

    [24.05.2025][19:08:46][DEBUG ][TESTQA5001]: welcome                                                            
    [24.05.2025][19:08:46][DEBUG ][TESTQA5001]: data is not nil                                                   
    [24.05.2025][19:08:46][DEBUG ][TESTQA5001]: data [                                                                   
      {"user":"jangabrielsson","repo":"EventRunner5","name":"EventRunner5.fqa"},            
      {"user":"jangabrielsson","repo":"Dirigera","name":"Dirigera.fqa"},                                      
      {"user":"jangabrielsson","repo":"HassQA","name":"HASS.fqa"},                                           
      {"user":"jangabrielsson","repo":"SonosQA","name":"SonosPlayer.fqa"}                            

     ]                                                                                                                                                                                  

     

    I was the same long time with previous hc3emu version giving the Event handler error.

     

    Do you have a way to get information of what the emulator is doing during this minute?

    Edited by Christb
    Add a question
  • Topic Author
  • Posted

    Add this

    Please login or register to see this code.

     

    • Like 1
  • Topic Author
  • Posted

    Ah, there was a miss so it tried to do 2 calls to the HC3 at startup even if offline was set.

    They hang ~30s each...

     

    Pushed v1.1.10 with the fix.

     

    Posted
    46 minutes ago, jgab said:

    Ah, there was a miss

    You fix it, now only 4seconds to get the result and file content print. Thanks

  • Topic Author
  • Posted

    Yes, but I introduced another bug when you are online. :-) 

    Pushed v1.1.11 with a fix for that.

    • Like 2
  • Topic Author
  • Posted

    So. the last week I have been working on a alternate version of Hc3Emu.

    In my quest to rewrite and simplify the emulator, I realized that I wanted the redo the core architecture (the old felt a bit "overengineered"). So instead of a normal update to the code, I started from scratch and have been lifting over features from Hc3Emu - which has worked surprisingly well due to its modularity - and allowed me to have a new emulator that is now on feature parity with the old (minus some rarely used features).

     

    The new emulator is named, Fanfare 🥳, Hc3Emu2.

     

    It will be installed with

    Please login or register to see this code.

    and it uses the same libraries like the old hc3emu. So it's a painless switch between them.

    I have decided to keep them both around for a while, but all my focus is on hc3emu2 and it runs all my other projects - so that's what I'm using now. I may update the old hc3emu for glaring bugs, but I would recommend users of hc3emu to come along on the hc3emu2 ride with me.

     

    From a usage perspective, they are very similar. --%% directives in the code, proxy, emulated web UI etc.

     

    The major breaking changes are

    • How it's launched (a new vscode launch.json, tasks.json, and for zerobrane studio there is a interpreter plugin)
    • There is no need for "if require and not QuickApp then require('hc3emu') end" at the top of the file. 
    • A new configuration file format (again). Back to a plain lua file and no Web UI editor for the config file (It was unmaintainable code, not worth the effort)

    There are also some minor changes to some directives, that is not compatible between emulators and need to be changed in QAs. It's a good reminder what emulator you are running (can be confusing when switching between them - I know from experience this week :-) )

     

    I will release it later this week. I will also keep it to this forum thread and start to change the documentation in the first post to reflect the usage of hc3emu2.

    Eventually, when I feel confident enough that there is nothing from the old hc3emu worth keeping, I may remove it and rename hc3emu2 to just hc3emu...

     

    • Like 3
  • Topic Author
  • Posted

    I pushed a prerelease now

    It will be installed with

    Please login or register to see this code.

    It has the version number 2.0.0 to signal that it's the second generation of hc3emu. I will still refer to the emulator as hce3mu, it's only the rock that is named hc3emu2.

     

    What's missing is some of the vscode tasks that are under development as we speak...

    • Like 1
    Posted

    Change to a new version maybe is a good moment to fix (or clarify) the following issue probably related to HC3Emu:

    When I run "Task → Upload QA", the QA is created in the HC3. QA runs as desired.

    However, when I then open the QA on the HC3 and try to edit one of the "files", some fails to open – showing only:

     

    Please login or register to see this image.

    /monthly_2025_05/image.png.5dba827d2dcce0e3fda9b4f3a874e2e4.png" />

     

    Interestingly, not all files are affected - some can be viewed/edited normally.

    Restarting central, refreshing the browser or downloading the .fqa file (and reinstalling) does not solve the issue.

    Moreover, trying to "Task → Update QA" (for the previously uploaded QA) leads to an error:

    Please login or register to see this code.

    I will be glad that so powerful tools would work fine. I can send you "affected" fqa.

  • Topic Author
  • Posted
    6 hours ago, Łukasz997 said:

    Change to a new version maybe is a good moment to fix (or clarify) the following issue probably related to HC3Emu:

    When I run "Task → Upload QA", the QA is created in the HC3. QA runs as desired.

    However, when I then open the QA on the HC3 and try to edit one of the "files", some fails to open – showing only:

     

    Please login or register to see this link.

     

    Interestingly, not all files are affected - some can be viewed/edited normally.

    Restarting central, refreshing the browser or downloading the .fqa file (and reinstalling) does not solve the issue.

    Moreover, trying to "Task → Update QA" (for the previously uploaded QA) leads to an error:

    Please login or register to see this code.

    I will be glad that so powerful tools would work fine. I can send you "affected" fqa.

     

    Yes, please send me the fqa. 

  • Topic Author
  • Posted (edited)
    7 hours ago, Łukasz997 said:

    Moreover, trying to "Task → Update QA" (for the previously uploaded QA) leads to an error:

    Please login or register to see this code.

    I will be glad that so powerful tools would work fine. I can send you "affected" fqa.

     

    So, looking at the error, it seems like it is trying to create (do a POST command) the QA file 'main'

    which is an error. 'main' should always exists and we can't create a new 'main' with 'POST', thus the 'Error: creating QA:736'

     

    So, the question is why it tries to upload a QA without 'main' - that seems to be a bug, I haven't seen before with other QAs...

    Would be nice if you could gzip together the development files for the QA so I can try to reproduce it. The fqa is probably already

    damaged so it can be difficult to understand why - but please send that too.

     

    So, this does not really explain the 501 error. I wonder if it is that you name the QA files with some strange names?

    (the names they get on the HC3). The HC3 is pretty restrictive on the names, no spaces, not too short, not too long.

    I don't have any sanity check on it currently.

     

    quick test, the names seems to have to be 3-20 characters long, and only contain alphanumeric characters and underscore.

    hc3emu2 makes that check now.

    Edited by jgab
    Posted

    Good morning Jan,

    please find included the example - fqa created from quick app that suffers from above phenomenon and 2 lua files consisting of this fqa. Names are original. File named on HC3 HTMLTablesLC cannot be displayed, second - named main, can be. 

    Please login or register to see this attachment.

  • Topic Author
  • Posted

    Yes, you have a space before the name

    Please login or register to see this code.

    and it's because you do 

    Please login or register to see this code.

    and I take everything after the comma as the name.

    So the HC3 accepts importing a bad filename but crashes when trying to open it...

    hc3emu2 makes a sanity check of the filename before making an fqa for upload.

    • Thanks 1
    Posted (edited)

    Thank you - I had no idea it was that strict.
    I've checked and all is editable now.

     

    However, this does not change non-functioning update. Still got error.
     

    Please login or register to see this code.

     

    Edited by Łukasz997
  • Topic Author
  • Posted

    Are you sure that the the QA on the HC3 has deviceId 736?

  • Topic Author
  • Posted

    I'm running your QA and can update the file

    Please login or register to see this code.

     

    Posted
    51 minut temu, jgab napisał:

    Are you sure that the the QA on the HC3 has deviceId 736?

    ID is not 736, but historically it was. Now is 745 in HC3 and in lua file. But update still refers to old 736 ID, I have no idea why - I can't find a place in my files where 736 is used. These are the directives:

    Please login or register to see this code.

    The path was the following, maybe it will help: 
    --%%id=736 this was first

    then task->upload, 736 was not available, 745 "automatically" was assumed as first free slot

    --%%id=745 I made correction in lua file, save

    task->update still refers to 736 and ends with error.

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