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

  • Topic Author
  • 8 hours ago, Brors94 said:

    I guess it is a typo, should it be local tempDevices =.... instead of the function? :)

    And thanks once again :D

    But I have too say, I think this picture loading is heavy for the hc3 😅 after I saved 2 rapid times it crashed and recovered from an unexpected error 😅
     But up and going again now :) 

    I don't think it should be that heavy on the HC3 (besides the size of the map) - it's the browser that has to work.

    Are your housemap a png? If you draw an SVG version of your houseman it's probably smaller.

    Now the SVG is embedded in an html <image tag with carries with it some restrictions (can't have url to load external pictures), can't have interactivity (clickable buttons) and can't share code between SVGs on the same page).

    Link to comment
    Share on other sites

    1 hour ago, jgab said:

    I don't think it should be that heavy on the HC3 (besides the size of the map) - it's the browser that has to work.

    Are your housemap a png? If you draw an SVG version of your houseman it's probably smaller.

    Now the SVG is embedded in an html <image tag with carries with it some restrictions (can't have url to load external pictures), can't have interactivity (clickable buttons) and can't share code between SVGs on the same page).

     

    Yea, it was an png converted to base 64, but the whole house insted of a room. 


    But it was hard to place Temp readings inside all rooms and the indicator that i want to use for a motion/presence indication :)

     

     

     

     

    Link to comment
    Share on other sites

    12 hours ago, jgab said:

    Ok, other things to look at - have you set a filter in the debug console of the vscode?

    It is obviously running but you don't get all the logs - there is a filter in the debug console that can block/allow specific log strings.

    I do not rember to have added any filter in the debug console (also not knowing that this was possible).

    I had a look to the vscode settings but I have not seen something specific to the DEBUG CONSOLE.

    Could you help me where I have to look?

    Link to comment
    Share on other sites

  • Topic Author
  • Please login or register to see this attachment.

    If that not it, set a breakpoint in fibemu when it prints to the log and try to figure out what happens.

    Choose the launch ""Fibenv QA file emu files (remote, HC3 access)"

    and set a breakpoint in 

    fibemu/.vscode/emufiles/lua/emu.lua

    on line 165 and step through the logging

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    21 minutes ago, jgab said:

    Choose the launch ""Fibenv QA file emu files (remote, HC3 access)"

    and set a breakpoint in 

    fibemu/.vscode/emufiles/lua/emu.lua

    on line 165 and step through the logging

    Done and get :

    Please login or register to see this attachment.

    and after suppressing the break:

    ERROR: [Errno 10048] error while attempting to bind on address ('0.0.0.0', 5004): une seule utilisation de chaque adresse de socket (protocole/adresse r�seau/port) est habituellement autoris�e (means only a single use of a socket address is normally autorized)

    Which seems to be normal as I have seen that I have again the 5004 port blocked: changing the running QA didn't change the web view and also when stoping the current QA, the bottom message in red "DISCONNECTED" is not displayed any more.

    Link to comment
    Share on other sites

  • Topic Author
  • 6 minutes ago, Christb said:

    Done and get :

    Please login or register to see this attachment.

    and after suppressing the break:

    ERROR: [Errno 10048] error while attempting to bind on address ('0.0.0.0', 5004): une seule utilisation de chaque adresse de socket (protocole/adresse r�seau/port) est habituellement autoris�e (means only a single use of a socket address is normally autorized)

    Which seems to be normal as I have seen that I have again the 5004 port blocked: changing the running QA didn't change the web view and also when stoping the current QA, the bottom message in red "DISCONNECTED" is not displayed any more.

    Yes, the web interface can't start if 5004 is blocked so you have to kill that.

    Are you saying that the powershell script provided don't work? (You need to have rights to run it)

     

    In any case, the blocked 5004 shouldn't stop the emulator to run (I see you break at line 132), what if you break at line 165 where it prints the greeting and step into that - no output?

    Link to comment
    Share on other sites


    I have been trying to get the setpoint from the thermostat shown above the Temp readings too now. 

    and the indicator updating too the sensor in the room. 
    Since i only got 1 indicator it seems to be able to do it like this (but this seems wierd too do a loop for 1 item😅😞

     

    function QuickApp:indic2(ev)
      for i,ind in ipairs(self.indicators) do
        ind.href = "#red"
      end
      self:drawMap()
    end

    I made 2 buttons for test 1 for red and 1 for green, Is it a way to do it without the loop? 😄

     

    Since we know after the creation of the temps labels and the indicators the number will always be the same isnt it?

    I have tried printing the self.temps in the loop, but dont know how to refer too them 😅

     

    so the loop is still making it hard for me 😅


     

     

     

     

     

     

     

    Link to comment
    Share on other sites

    49 minutes ago, jgab said:

    Are you saying that the powershell script provided don't work? (You need to have rights to run it)

     

    In any case, the blocked 5004 shouldn't stop the emulator to run (I see you break at line 132), what if you break at line 165 where it prints the greeting and step into that - no output?

    Yes your script was not accepted starting by authorization not accepted:


    PS C:\Users\ASUS> Set-ExecutionPolicy RemoteSigned

    Modification de la stratégie d'exécution
    La stratégie d’exécution permet de vous prémunir contre les scripts que vous jugez non fiables. En modifiant la
    stratégie d’exécution, vous vous exposez aux risques de sécurité décrits dans la rubrique d’aide
    about_Execution_Policies à l’adresse

    Please login or register to see this link.

    Voulez-vous modifier la stratégie
    d’exécution ?
    [O] Oui  [T] Oui pour tout  [N] Non  [U] Non pour tout  [S] Suspendre  [?] Aide (la valeur par défaut est « N ») : O
    Set-ExecutionPolicy : L'accès à la clé de Registre
    'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' est refusé. Pour modifier la
    stratégie d’exécution pour l’étendue par défaut (LocalMachine), démarrez Windows PowerShell avec l’option Exécuter en
    tant qu’administrateur. Pour modifier la stratégie d’exécution pour l’utilisateur actuel, exécutez «
    Set-ExecutionPolicy -Scope CurrentUser».
    Au caractère Ligne:1 : 1
    + Set-ExecutionPolicy RemoteSigned
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : PermissionDenied: (:) [Set-ExecutionPolicy], UnauthorizedAccessException
        + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand

     

     

    I don't know why the break is shown at line 132 in the print screen as it was at line 165

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

    I have now a new error concernin python (before and after I killed the lock by python of the 5004 port):

    PowerShell killing process:


    PS C:\Users\ASUS> netstat -ano -p TCP | findstr 5004
      TCP    0.0.0.0:5004           0.0.0.0:0              LISTENING       16016
    PS C:\Users\ASUS> Get-Process -ID 16016

    Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
    -------  ------    -----      -----     ------     --  -- -----------
        343      36    54720      47448     208.39  16016   1 python3.11
    PS C:\Users\ASUS> taskkill /PID 16016
    Opération réussie : un signal de fin a été envoyé au processus de PID 16016.

     

    New error:

    File "lupa\lua54.pyx", line 858, in lupa.lua54._LuaObject.__call__

    File "lupa\lua54.pyx", line 1750, in lupa.lua54.call_lua

    File "lupa\lua54.pyx", line 1776, in lupa.lua54.execute_lua_call

    File "lupa\lua54.pyx", line 1665, in lupa.lua54.raise_lua_error

    lupa.lua54.LuaError: .vscode/emufiles/lua/emu.lua:165: attempt to index a nil value (global '_QA') stack traceback:  .vscode/emufiles/lua/emu.lua:165: in main chunk  [string "<python>"]:1: in function <[string "<python>"]:1>

    I think the problem is comming fro python but why?

     

     


     
    Link to comment
    Share on other sites

    I have killed Visual Studio and python 3.11 using the task manager and the error has change: I do not have anymore the errror concerning 5004 port occupation but the following:

    Loaded config from config.json
    Platform is win32
    Web server port 5004 status 10061

    Waiting for debugger to attach...
    Debugger attached

    Exception in thread Thread-1 (runner):
    Traceback (most recent call last):
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2288.0_x64__qbz5n2kfra8p0\Lib\threading.py", line 1045, in _bootstrap_inner
        self.run()
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2288.0_x64__qbz5n2kfra8p0\Lib\threading.py", line 982, in run
        self._target(*self._args, **self._kwargs)
      File "C:\Users\ASUS\Documents\fibemu\.vscode\emufiles\fibenv.py", line 192, in runner
        f(json.dumps(config),self.lua.table_from(hooks),luapath)
      File "lupa\lua54.pyx", line 858, in lupa.lua54._LuaObject.__call__
      File "lupa\lua54.pyx", line 1750, in lupa.lua54.call_lua
      File "lupa\lua54.pyx", line 1776, in lupa.lua54.execute_lua_call
      File "lupa\lua54.pyx", line 1665, in lupa.lua54.raise_lua_error
    lupa.lua54.LuaError: .vscode/emufiles/lua/emu.lua:165: attempt to index a nil value (global '_QA')
    stack traceback:
        .vscode/emufiles/lua/emu.lua:165: in main chunk
        [string "<python>"]:1: in function <[string "<python>"]:1>

     

    If we cannot find where is the issue, I will uninstall vscode & python then  reinstall  them plus git pull. anything else I may do before?

     

    Edited by Christb
    Link to comment
    Share on other sites

    2 hours ago, Christb said:

    Are you saying that the powershell script provided don't work? (You need to have rights to run it)

     

    I fact your script is working if I run PowerShell in administrator mode☺️

    • Like 1
    Link to comment
    Share on other sites

    4 hours ago, Christb said:

    If we cannot find where is the issue, I will uninstall vscode & python then  reinstall  them plus git pull.

    So I did  and I have recovered all normal fibemu web  wiew, correctly refreshed and "disconnected" warning message back! 👍

    Please login or register to see this image.

    /monthly_2024_03/image.png.b1e45c5aa5b9b706dce62ef1dfd00e54.png" />

    I have not a clue of what has cause the issue: may be an issue with vscode or Python software updates...

     

    Link to comment
    Share on other sites

    Now that fibemu is back, I have tested your QA_image.lua and I can see the picture of the dog in the webUI but the image size is not printed:

    02.03.2024] [18:39:02] [SYS   ] [install]: QA 'examples\QA_Image.lua'
    [02.03.2024] [18:39:05] [SYS   ] [refresh]: DeviceCreatedEvent ID:5000
    [02.03.2024] [18:39:06] [SYS   ] [QUICKAPP5000]: Running 'IMAGES'
    [02.03.2024] [18:39:06] [SYS   ] [QUICKAPP5000]: Running 'main'
    [02.03.2024] [18:39:06] [DEBUG ] [QUICKAPP5000]: Image size

    Link to comment
    Share on other sites

    31 minutes ago, Christb said:

    Now that fibemu is back, I have tested your QA_image.lua and I can see the picture of the dog in the webUI but the image size is not printed:

    02.03.2024] [18:39:02] [SYS   ] [install]: QA 'examples\QA_Image.lua'
    [02.03.2024] [18:39:05] [SYS   ] [refresh]: DeviceCreatedEvent ID:5000
    [02.03.2024] [18:39:06] [SYS   ] [QUICKAPP5000]: Running 'IMAGES'
    [02.03.2024] [18:39:06] [SYS   ] [QUICKAPP5000]: Running 'main'
    [02.03.2024] [18:39:06] [DEBUG ] [QUICKAPP5000]: Image size

     I have found why: the line need to be changed for :

    print("Image size",image.w,image.h)

    and it is displaying the values

    • Thanks 1
    Link to comment
    Share on other sites

    Dear JGAB, I am back on changing your SVDTest2 to link indicators that will be lights ON/Off status (in the next step) to each stair image and, as Brors94, I can display room temperature in  the right floor/room.

    Now color and position of indicators are linked with stair as well as read temperature values but I have lost the previuos background rectangle for the temps values.

    I have been able to add such background rectangles (in orange) but then the update of temperature values does not work anymore:  

    self.temps = {}
    local tempPos = {{x=90,y=65},{x=180,y=65},{x=280,y=65},{x=180,y=210},{x=280,y=210}}
    for i=1,5 do -- Add 5 temp labels
    self.temps[#self.temps+1] =
          im:add(Rectangle{x=(tempPos[i].x)-2,y=(tempPos[i].y)-20,width="30",height="30",style="fill:orange"}) -- added by BC
          im:add(Text{x=tempPos[i].x,y=tempPos[i].y,text=fmt('0.%d°',i),style='font-size:80', filter='url(%23rounded-corners)'})
     
    end

    without the line  im:add(Rectangle{x=... the update of temperature values is back.

    Please login or register to see this image.

    /monthly_2024_03/image.png.a9e08c63879e2c3d00992623360814c7.png" />image.png.c1de8f2e3a9ba3945fe425eb6d67102b.png

                     showing real temps after 30s                                                    No refresh of temp values from onInit values

    Adding updateTemps() at the end of each floor button function does not fix the problem.

    Why adding this line is killing the temp update process?

     

    Edited by Christb
    Link to comment
    Share on other sites

  • Topic Author
  • This is strange code

    Please login or register to see this code.

    You are setting self.temps[#self.temps+1] to the Rectangle bt you are throwing away the Text value...

    Link to comment
    Share on other sites

    30 minutes ago, jgab said:

    This is strange code

    Please login or register to see this code.

    You are setting self.temps[#self.temps+1] to the Rectangle bt you are throwing away the Text value...

    Yes, I have suppressed the line now but if I remenber well, your QA had background rounded orange rectangles. I don't think that I have modified the line:

    Please login or register to see this code.

    but the rectangles are no more there. I need them has they help for the visibility on temp values in the image. How I can get them back?

    Link to comment
    Share on other sites

  • Topic Author
  • Posted (edited)

    Please login or register to see this code.

    Could this work?

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

    YES IT IS with few changes to fit the real temperature values:

    Please login or register to see this image.

    /monthly_2024_03/image.png.7a4d54b4d6faef59ef509a7bc83ba77c.png" />

    Is there an attribute for the rectangle in order that the orange boxes are 50% transparent?

    Edited by Christb
    • Like 1
    Link to comment
    Share on other sites

  • Topic Author
  • Posted (edited)

    Haven't tested but try

    Please login or register to see this code.

     

    Edited by jgab
    • Thanks 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...