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)

Please login or register to see this link.

My new attempt at a tool for developing QuickApps on your PC/Mac before pushing them to the real HC3.
Plua stands for Python Lua, and is a lua compatible app written in Python, wrapping a real lua engine within. The advantage is that we can easily add functionality that is difficult to achieve with Lua.
So instead of using lua to compile and run your program, you use plua. Plua is mostly backwards compatible with how the standard lua interpreter takes command line arguments so it is fairly easy to integrate in existing IDEs. I have made it work for VSCode and ZerobraneStudio.
If you code using Agents/AI help - Claude, Codex, Copilot etc. there are a collection of skills <

Please login or register to see this link.

> that can be added to your project that makes the AI better at coding QuickApps and using plua. The skills also informs the AI how to use plua as the tool to upload, download, update QAs to the HC3 and do some other tasks.
 

This is the tool I use to develop my own QAs these days, so Plua is constantly being improved as I run into limitations and bugs (

Please login or register to see this link.

). 

 

Please login or register to see this link.

Please login or register to see this link.

Please login or register to see this link.

 

It requires that Python is installed (including pip, that is a part of most Python installations)

To install run

Please login or register to see this code.

To upgrade to latest

Please login or register to see this code.

 

Setup a .env file in your home directory with the content

Please login or register to see this code.

 

To run a QA file use plua as a lua interpreter with the flag --fibaro

Please login or register to see this code.

 

We can then use plua as the executable lua interpreter in vscode to run our QA code.

add a launch config in .vscode/launch.json

Please login or register to see this code.

You must make sure that plua is available as a command globally on you machine for the vscode launch command to work, because we are just referring to executable "plua"
If you install plua in a python virtual environment, make the executable point to the plua app in your <venv>/bin/...

 

A simple QA lua file looks like:
 

Please login or register to see this code.



Please login or register to see this link.


 

The plua interpreter has a lot of options and capabilities

Please login or register to see this code.


It is a reuse of the code from my last effort, hc3emu, but with some major improvements.
It's constantly under development, so beware of some rough edges appearing now and then. However, I promise to try and smooth them out as soon as possible.

More extensive documentation in the

Please login or register to see this link.

.
QuickStart to develop a QuickApp with

Please login or register to see this link.


 

Edited by jgab
  • Like 8
  • Thanks 1
  • Topic Author
  • Posted

    v1.2.6 is up.
    - Lots of bugfixes as always...
    - Works under zerobrane now

    • Like 1
  • Topic Author
  • Posted (edited)

    v1.2.11 is up

    Please login or register to see this code.

     

    • Lots of bugfixes, as always...
    • >plua --diagnostic
        will log some of the configurations and make a test access to the HC3.
        will be improved over time to do more tests...
    • Fixed tools support. New vscode tasks.json format:
       

    Please login or register to see this code.


    Can also be used from command line. Ex.
     

    Please login or register to see this code.

     

    Edited by jgab
    • Like 1
  • Topic Author
  • Posted

    v1.2.17 is up

    Please login or register to see this code.

    • Fix for printing results for -e and -i option
    • Load ~/.plua/user_funs.lua if available
    • Help for logging what "tools" are available, and their syntax: >plua -t help

    Please login or register to see this code.

     

    Posted

    Hi Jan,
    I'm very interested in the PLUA development environment and trying to set it up.
    Everything is set-up correctly, but when executing some test, the PLUA process stops immediately after having initalised.
    e.g.

    • I launch a Simple multilevel test QA using 'plua --fibaro main.lua'
      The Quickapp UI starts, but looses immediately the connection because the process has stopped.

      Please login or register to see this attachment.


      Please login or register to see this image.

      /monthly_2025_09/image.png.434aa1c66d445d4ac2982b1e23404a80.png" />
    • The same with VSCODE debug mode, even not passing in the QuickApp:onInit() function
      image.png.30071546f20549645758295c3c7e08a1.png

    The only way I'm able to make it works is with the '--interactive' mode. It keeps the process running and it is all ok.

    But the interactive mode doesn't seem to work if I add the parameter in the launch.json.

    Please login or register to see this attachment.

     

    in vscode

    image.png.2f24b2c4852446e5b0e906af3ea33cbf.png

     

    If I activate the debug logs, the logs end with :

    Please login or register to see this attachment.

     

    Something might be wrong in my configuration, but I do not see anything else I can do.

     

    Thanks.

    Please login or register to see this attachment.

  • Topic Author
  • Posted (edited)

    Hi, I'm happy you want to test Plua....


    1. Per default, Plua terminates if there are no timers running. It is controllable with the --run-for flag,

    In .vscode/launch.json I recommend to add

    Please login or register to see this code.

    A positive time terminates plua if there are no timers after that time (60s in the example)
    A negative value makes a hard kill of Plua after the time.

    A value of zero runs forever - or until ctrl-C (or stop/restart in VSCode)

    Interactive mode sets the flag to 0. Interactive mode can't be run from VSCode as there is no stdin to read commands from...

    Are you on Windows or MacOS?
    Who prints these logs - is it your program?

    Please login or register to see this image.

    /monthly_2025_09/image.png.961e7d9139df848d01caad5b54d3f600.png" />

     

    Ah, no it's the web UI that can't connect back to Plua - because it's terminated. It will retry until Plua starts again - or you close the WebUI window. (but it's the js log console?)

    Edited by jgab
    Posted

    Hi Jan,
    Thanks for your reply and explanation.
    I'm on Windows 11.

    Indeed, the logs come from the WebUI.

    Here is my launch.json

    Please login or register to see this code.

     

    When I set the "--run-for" to 60, the execution stops immediately (not after 60 seconds) --> Not even giving me the time to play with the UI components

    When I set the "--run-for" to 0 the execution doesn't stop until I stop the debugger --> this is Ok

    Please login or register to see this code.

     

    Now, While I have installed the correct extensions, I cannot use the debug features yet...

    Any Ideas on troubleshooting?

    Please login or register to see this image.

    /monthly_2025_09/image.png.3e9242cbb9f65b0e70a2ca84f9d067da.png" />

     
     

  • Topic Author
  • Posted

    --run-for > 0, stop when no timers or when time is up

    --run-for = 0, never stop (or until user stops program)
    --run-for < 0, stop exactly at time, even if there are timers running.

    If you do GUI development where there is no timers, just events from user interaction, it makes sense to set --run-for=0

     

    Are you familiar with vscode? Is the run F5, and run ^F5 available as options? Can you set breakpoints in the left margin of the code?

    Please login or register to see this link.

     

    Posted

    Hi Jan,

    Thanks for the tips about --run-for parameter.
    Yes, I'm familiar with VScode, Debugger launch with F5 / ^F5 and I can set break point ;-) 

    Looking more in details, I finally found the issue for the debuging.

    Actually, when you do --init-qa,  it creates the .vscode folder with this launch.json.

    Please login or register to see this code.

     

    The issue comes from the "executable": "plua", statement.

    I changed it with  "interpreter": "plua", and it works now 😊

    Please login or register to see this code.

     

    The difference betwen "executable and "interpreter" being :

    executable = the final product you're debugging (compiled binary).

    interpreter = the engine that runs your source code (used in scripting languages).

     

    I do assume that you should adapt the generated ".vscode\launch.json" file to replace the "executable" configuration by "interpreter".

     

    Thanks for the tips, I'll continue my testings !👌

  • Topic Author
  • Posted

    Sorry, that's a bug in the init-qa template.
    It's should be fixed in v1.2.37 + some other small stuff.

    • Like 1
    Posted

    Hi @jgab, is it possible to run in vscode PLUA parallel to hc3emu2?  

    I guess yes but prefer to ask before installing...

  • Topic Author
  • Posted

    Yes, just make sure you have launch.json items for them ( they are started differently)

    • Like 1
    Posted

    Ok, the plua installation seems to went well, I create the launch.json file in my new plua-dev folder.

    I can now select plua:Run Current Fibaro File with Debugger (hc3emu-main) and F5 launches the process

    Please login or register to see this attachment.

    But just after I am getting an Exception message:

    Exception in thread Thread-1 (_readerthread): 
    Traceback (most recent call last): 
    File "C:\Users\ASUS\AppData\Local\Programs\Python\Python311\Lib\threading.py", line 1045, in _bootstrap_inner 
    self.run() 
    File "C:\Users\ASUS\AppData\Local\Programs\Python\Python311\Lib\threading.py", line 982, in run 
    self._target(*self._args, **self._kwargs) 
    File "C:\Users\ASUS\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 1597, in _readerthread 
    buffer.append(fh.read()) 
    ^^^^^^^^^ 
    File "C:\Users\ASUS\AppData\Local\Programs\Python\Python311\Lib\encodings\cp1252.py", line 23, in decode 
    return codecs.charmap_decode(input,self.errors,decoding_table)[0] 
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
    UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 79: character maps to <undefined> 
    Exception in thread Thread-3 (_readerthread): 
    Traceback (most recent call last): 
    File "C:\Users\ASUS\AppData\Local\Programs\Python\Python311\Lib\threading.py", line 1045, in _bootstrap_inner 
    self.run() 
    File "C:\Users\ASUS\AppData\Local\Programs\Python\Python311\Lib\threading.py", line 982, in run 
    self._target(*self._args, **self._kwargs) 
    File "C:\Users\ASUS\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 1597, in _readerthread 
    buffer.append(fh.read()) 
    ^^^^^^^^^ 
    File "C:\Users\ASUS\AppData\Local\Programs\Python\Python311\Lib\encodings\cp1252.py", line 23, in decode 
    return codecs.charmap_decode(input,self.errors,decoding_table)[0] 
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
    UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 79: character maps to <undefined> 
    WARNING:plua.cli:Could not fully clean up port 8080, but continuing... 

     

    Then 2 info lines are displayed as below:

     

    [11.09.2025][19:57:09][INFO   ][PLUA]: Starting helper server on 192.168.1.21 8082
    [11.09.2025][19:57:09][INFO   ][PLUA]: Existing Proxy found: 703 Manual Heating Override_Proxy
    Fibaro SDK, online, (1.2997s)

     

    Following lines are control of my onInit() function which is processed correctly and is updating the UI view of the Proxy 703 but at the nad of the onInit process, I have:

    [11.09.2025][19:57:15][DEBUG  ][MANUAL HEATING OVERRIDE_PROXY703]: ----- fun onInit() end -----
    [11.09.2025][19:57:15][DEBUG  ][PLUA]: GET /devices?parentId=703
    [11.09.2025][19:57:16][INFO   ][PLUA]: Helper connected
    Process exit with code: 0 signal: null
    Process on close code: 0 args: null

     

    Just note that at the first F5 with this lua file, a new QA has been created in my HC3 as below  or it may be when I used the command >plua  --init-qa (do not remember)

    Please login or register to see this image.

    /monthly_2025_09/image.png.118c359c5233024f5fd759a0c2693932.png" />

    Uusing the console of 704, I have regular message like (every time I press F5):

    [11.09.2025] [19:57:15] [TRACE] [QUICKAPP704]: onAction: {"deviceId":704,"actionName":"connect","args":["ws:\/\/192.168.1.21:8082"],"manual":true}

    [11.09.2025] [19:57:15] [DEBUG] [QUICKAPP704]: ws://192.168.1.21:8082 :

    [11.09.2025] [19:57:15] [DEBUG] [QUICKAPP704]: Connection from ws://192.168.1.21:8082

    [11.09.2025] [19:57:16] [DEBUG] [QUICKAPP704]: Disconnected ws://192.168.1.21:8082

     

    Using the console of 703 I see:

    [11.09.2025] [19:56:09] [DEBUG] [QUICKAPP703]: Started Manual Heating Override_Proxy 703

    [11.09.2025] [19:57:09] [TRACE] [QUICKAPP703]: onAction: {"args":[{"port":8080,"ip":"192.168.1.21"}],"manual":true,"deviceId":703,"actionName":"CONNECT"}

    [11.09.2025] [19:57:09] [DEBUG] [QUICKAPP703]: CONNECT

    [11.09.2025] [19:57:09] [DEBUG] [QUICKAPP703]: Connected

    [11.09.2025] [20:00:50] [TRACE] [QUICKAPP703]: UIEvent: {"eventType":"onReleased","deviceId":703,"elementName":"b19","values":[]}

    [11.09.2025] [20:00:50] [DEBUG] [QUICKAPP703]: Starting

    [11.09.2025] [20:00:50] [DEBUG] [QUICKAPP703]: Connecting...

    [11.09.2025] [20:01:04] [TRACE] [QUICKAPP703]: UIEvent: {"eventType":"onReleased","deviceId":703,"elementName":"b1","values":[]}

    [11.09.2025] [20:03:01] [DEBUG] [QUICKAPP703]: Connecting...

    [11.09.2025] [20:05:12] [DEBUG] [QUICKAPP703]: Connecting...

    [11.09.2025] [20:07:23] [DEBUG] [QUICKAPP703]: Connecting...

    [11.09.2025] [20:09:34] [DEBUG] [QUICKAPP703]: Connecting...

    [11.09.2025] [20:11:45] [DEBUG] [QUICKAPP703]: Connecting...

    [11.09.2025] [20:13:56] [DEBUG] [QUICKAPP703]: Connecting...

    [11.09.2025] [20:16:07] [DEBUG] [QUICKAPP703]: Connecting...

    [11.09.2025] [20:18:19] [DEBUG] [QUICKAPP703]: Connecting...

    [11.09.2025] [20:20:30] [DEBUG] [QUICKAPP703]: Connecting...

    [11.09.2025] [20:22:41] [DEBUG] [QUICKAPP703]: Connecting...

    [11.09.2025] [20:24:52] [DEBUG] [QUICKAPP703]: Connecting...

    [11.09.2025] [20:26:15] [TRACE] [QUICKAPP703]: onAction: {"args":[{"port":8080,"ip":"192.168.1.21"}],"manual":true,"deviceId":703,"actionName":"CONNECT"}

    [11.09.2025] [20:26:15] [DEBUG] [QUICKAPP703]: CONNECT

    [11.09.2025] [20:26:15] [DEBUG] [QUICKAPP703]: Connected

    [11.09.2025] [20:27:03] [DEBUG] [QUICKAPP703]: Connecting...

    [11.09.2025] [20:29:14] [DEBUG] [QUICKAPP703]: Connecting...

    [11.09.2025] [20:29:50] [TRACE] [QUICKAPP703]: UIEvent: {"eventType":"onReleased","deviceId":703,"elementName":"b1","values":[]}

    [11.09.2025] [20:31:25] [DEBUG] [QUICKAPP703]: Connecting....

    and nothing more, any button release of the Proxy does not launch the associated function

     

    Questions:

    1. Is using the Python version 3.11.7 an issue?
    2. What is the reason of Exception: Python version or again a path isue?
    3. For the last crash, is it comming :

    3.1.1 from a conflict between ProxyQA 703 and Puahelper 704 even if they are not using the same port?

    3.1.1.1 if not then can I suppress QA 704?

    3.1.2 the Proxy is using port 8080 but server is enabled on 8082

    3.2 from a locked port 8080 and it needs to be killed?

  • Topic Author
  • Posted

    Ok, I think I fixed the python exception you see, v1.2.38

    Yes, the helper will connect and then disconnect if no commands are sent to it (and wake up again if needed)
    The proxy gets a disconnect every time you stop Plua, and reconnects when you start the debugger again, so that logs look normal.
    So, Plua will terminate when there is no timers running anymore. 
    In the launch.json, set --run-for to 0 to make it run until you stop it.

    Which version of Windows are you running now?

    Posted
    13 hours ago, jgab said:

    In the launch.json, set --run-for to 0 to make it run until you stop i

    Below my launch.json:

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "plua: Run Current Lua File with Debugger",
                "type": "luaMobDebug",
                "request": "launch",
                "workingDirectory": "${workspaceFolder}",
                "sourceBasePath": "${workspaceFolder}",
                "listenPort": 8172,
                "listenPublicly": false,
                "stopOnEntry": false,
                "sourceEncoding": "UTF-8",
                "interpreter": "plua",
                "arguments": [
                    "${file}"
                ]
            },
            {
                "name": "plua: Run Current Fibaro File with Debugger",
                "type":"luaMobDebug",
                "request": "launch",
                "workingDirectory": "${workspaceFolder}",
                "sourceBasePath": "${workspaceFolder}",
                "listenPort": 8172,
                "stopOnEntry": false,
                "sourceEncoding": "UTF-8",
                "interpreter": "plua",
                "arguments": [
                    "--fibaro",
                    "--run-for",
                    "0",
                    "${relativeFile}"
                ],
                "listenPublicly": false
            }
        ]
    }

    13 hours ago, jgab said:

    Which version of Windows are you running now?

    I am still with Windows 10

    I intend to upgrade to Windows 11 when I will have checked that my computer is compatible: Microsoft said 'No' few month ago but now it is 'Maybe' if somme starting modules are activated or added

    Posted (edited)

     Dear @jgab,

    God news, the structure of my launch.json was ok but the file was not in \lua-dev\.vscode; move done and now my QA is working as with hc3emu2 with directive --%%proxy=false😁

    I had also to add the directive --%%desktop=true to get the web UI view on page 

    Please login or register to see this link.

    All buttons and labels are correctly behaving and refresh time seems to be around 1s but not a big deal. 

     

    I have still an issue when changing --%%proxy to true:

    I have the info line  "Existing Poxy found:ID 703 Manual Heating Overide_Proxy" 

    The QA start well as before and now I have the following lines at the end of the onInit function:

    [13.09.2025][15:06:19][DEBUG  ][MANUAL HEATING OVERRIDE_PROXY703]: ----- fun onInit() end -----

    [13.09.2025][15:06:19][DEBUG  ][PLUA]: GET /devices?parentId=703
    [13.09.2025][15:06:19][DEBUG  ][PLUA]: Looking for QuickApp with ID: 703
    [13.09.2025][15:06:19][DEBUG  ][PLUA]: Found QuickApp with ID 703
    [13.09.2025][15:06:20][DEBUG  ][PLUA]: Looking for QuickApp with ID: 703
    [13.09.2025][15:06:20][DEBUG  ][PLUA]: Found QuickApp with ID 703
    [13.09.2025][15:06:21][INFO   ][PLUA]: Helper connected

    The web UI emulator is still working (Buttons and labels) with id 703 but the Proxy 703 in HC3 has only its labels updated but none of the buttons are giving a reaction of the QA.

    If I suppress the directive --%%desktop=true then at the end of onInit(), I have only:

    [13.09.2025][15:21:50][DEBUG  ][MANUAL HEATING OVERRIDE_PROXY703]: ----- fun onInit() end -----
    [13.09.2025][15:21:50][DEBUG  ][PLUA]: GET /devices?parentId=703
    [13.09.2025][15:21:50][INFO   ][PLUA]: Helper connected

    and the HC3 Proxi 703 UI is updated but still none of the buttons are not making a reaction.😥

    The log console of the Proxy 703 is like:

    [13.09.2025] [15:21:31] [TRACE] [QUICKAPP703]: onAction: {"args":[{"port":8080,"ip":"192.168.1.24"}],"manual":true,"deviceId":703,"actionName":"CONNECT"}

    [13.09.2025] [15:21:31] [DEBUG] [QUICKAPP703]: CONNECT

    [13.09.2025] [15:21:31] [DEBUG] [QUICKAPP703]: Connected

    [13.09.2025] [15:22:05] [TRACE] [QUICKAPP703]: UIEvent: {"eventType":"onReleased","deviceId":703,"elementName":"b2","values":[]}

    [13.09.2025] [15:23:16] [DEBUG] [QUICKAPP703]: Connecting...

    [13.09.2025] [15:25:27] [DEBUG] [QUICKAPP703]: Connecting...

     

    For information, the Proxy 703 have been created with hc3emu2.

    Do you have changed something in how you create and manage the HC3 Proxy using Plua ?.

    Edited by Christb
  • Topic Author
  • Posted

    Yes, you need to "recreate" the proxy. Remove it on the HC3 and rerun to recreate. They have a slightly different protocol.

     

    The

    [13.09.2025][15:06:19][DEBUG  ][PLUA]: Looking for QuickApp with ID: 703
    [13.09.2025][15:06:19][DEBUG  ][PLUA]: Found QuickApp with ID 703
    [13.09.2025][15:06:20][DEBUG  ][PLUA]: Looking for QuickApp with ID: 703
    [13.09.2025][15:06:20][DEBUG  ][PLUA]: Found QuickApp with ID 703

    are because you set the debugFlag to true - it's the webUI looking up the QA it should render (getting the UI elements etc)

    Posted

    Tank for thte confirmation.

    I suppressed the 703 Proxy, and PluaHelper id 704, relaunch vs code lua file then 2 new Proxy created:

    PluaHelper id 705

    Manual Heating Override_Proxy id 706

    QuickApp UI is launched with the same id 706  and fully working as before

    The Proxy 706 has the right UI view and label are updated but it has stii not button working and I have in the HC3 console:

    [13.09.2025] [18:26:18] [DEBUG] [QUICKAPP706]: Started Manual Heating Override_Proxy 706

    [13.09.2025] [18:26:18] [DEBUG] [QUICKAPP706]:

    [13.09.2025] [18:26:18] [DEBUG] [QUICKAPP706]:

    [13.09.2025] [18:26:57] [TRACE] [QUICKAPP706]: UIEvent: {"elementName":"b2","deviceId":706,"values":[],"eventType":"onReleased"}

    [13.09.2025] [18:26:57] [ERROR] [QUICKAPP706]: QuickApp crashed

    [13.09.2025] [18:26:57] [ERROR] [QUICKAPP706]: std::runtime_error: 'Invalid argument'

    [13.09.2025] [18:27:37] [TRACE] [QUICKAPP706]: UIEvent: {"elementName":"b2","deviceId":706,"values":[],"eventType":"onReleased"}

    [13.09.2025] [18:27:37] [ERROR] [QUICKAPP706]: QuickApp crashed

    [13.09.2025] [18:27:38] [ERROR] [QUICKAPP706]: std::runtime_error: 'Invalid argument'

    Worse because the Proxi QA now is crashing

     

    Other question: What is the usage of the PluaHelper id 705? is it just to reply to the ping from QA 706?

     

    Posted (edited)

    I'm trying to run Plua in ZB - first run is not working, second press start buton is ok with this result:

     

    Please login or register to see this attachment.

     

    but still with 1 error in init.lua

    I'm not sure that this is ok ....

     

     

     

    Edited by petrkl12
    Posted (edited)

    this help to cancel error in init.lua for PLua in ZeroBrain

     

    language='en'
    debugger.runonstart=true
    path.lua54 = "plua"
    interpreter = "lua54"
     

    Edited by petrkl12

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