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
  • Posted (edited)

    This is how to "disable" a QuickApp

    Please login or register to see this code.

    When we enable/disable a QuickApp it will restart (destroying all ev. timers)

    When disabled we trap onAction and UIevents so the QA can not be called with fibaro.call or any buttons being pressed.

    One exception here is that our UIHandler checks if we press the 'enable' button and in that case handle it - allowing users to enable the QA again.

    The QA can also be enabled/disabled in the Web UI under Advanced -> Device disabled box....

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

    • 2 weeks later...
  • Topic Author
  • Posted (edited)

    Here is "library file" to deal with UI elements.

    The idea is that we create a lua table with all the id's of the UI elements, buttons, labels, sliders, and we can manipulate them directly by assigning the table keys with values. Like setting the "text" property of a button or "value" property of a slider.

    I'm a big fan of abstractions that reduce the amount of code and/or makes it easier to code. If this hack reaches that goal I guess is a matter of taste. 

    The code is also an example of classes on the HC3 and the 'property' values that can be assigned to classes and let us do thing like x.y = 55 that calls a function to assign x.y the value 55 so we can control how it's done. In our case when we assign myButton.text = "Foo" it will result in a call to self:updateView('myButton','text',"Foo").

     

    Ex.

    If we have a slider with ID 'mySlider' and a button with ID 'myButton' and have stored our UI elements in self.ui, we can do

    Please login or register to see this code.

    We can also get the current value of a element

    Please login or register to see this code.

     

    When setting string values we can give a table as value that serves as the arguments to string.format

    Please login or register to see this code.

    and the assigned value will be formatted "Temperature is 10.88"

     

    We also assign the UI callbacks in this table. (the advantage is that we don't pollute the QuickApp name space and expose the handlers as remote functions).

    1. If the table is already setup we can declare them as

    Please login or register to see this code.

    2. If we want to declare the callbacks before we have setup the table we can declare them in a temporary table

    Please login or register to see this code.

    and when we setup the table we send the temporary table as an argument

    Please login or register to see this code.

    self:setUpUIelements(UI,true) is the method to setup the table and should be called in QuickApp:onInit()

    The second argument, 'true', will print out a template for setting up a temporary table with all the UI callbacks. This can then be copied from the log and into the code to set things up.

     

    Here we assigned the table to self.ui but it can be stored anywhere, also in a global variable. Ex

    Please login or register to see this code.

     

    So, an example of a QuickApp:onInit

    Please login or register to see this code.

     

    Here is the "library" with 'setUpUIelements

    Please login or register to see this code.

     

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

    4 hours ago, jgab said:

    Here is "library file" to deal with UI elements.

    The idea is that we create a lua table with all the id's of the UI elements, buttons, labels, sliders, and we can manipulate them directly by assigning the table keys with values. Like setting the "text" property of a button or "value" property of a slider.

    I'm a big fan of abstractions that reduce the amount of code and/or makes it easier to code. If this hack reaches that goal I guess is a matter of taste. 

    The code is also an example of classes on the HC3 and the 'property' values that can be assigned to classes and let us do thing like x.y = 55 that calls a function to assign x.y the value 55 so we can control how it's done. In our case when we assign myButton.text = "Foo" it will result in a call to self:updateView('myButton','text',"Foo").

     

    Ex.

    If we have a slider with ID 'mySlider' and a button with ID 'myButton' and have stored our UI elements in self.ui, we can do

    Please login or register to see this code.

    We can also get the current value of a element

    Please login or register to see this code.

     

    When setting string values we can give a table as value that serves as the arguments to string.format

    Please login or register to see this code.

    and the assigned value will be formatted "Temperature is 10.88"

     

    We also assign the UI callbacks in this table. (the advantage is that we don't pollute the QuickApp name space and expose the handlers as remote functions).

    1. If the table is already setup we can declare them as

    Please login or register to see this code.

    2. If we want to declare the callbacks before we have setup the table we can declare them in a temporary table

    Please login or register to see this code.

    and when we setup the table we send the temporary table as an argument

    Please login or register to see this code.

    self:setUpUIelements(UI,true) is the method to setup the table and should be called in QuickApp:onInit()

    The second argument, 'true', will print out a template for setting up a temporary table with all the UI callbacks. This can then be copied from the log and into the code to set things up.

     

    Here we assigned the table to self.ui but it can be stored anywhere, also in a global variable. Ex

    Please login or register to see this code.

     

    So, an example of a QuickApp:onInit

    Please login or register to see this code.

     

    Here is the "library" with 'setUpUIelements

    Please login or register to see this code.

     

    Really helpfull.. Just a side question. If we can manipulate with UI elements behaviour, and even we can use some CSS styling commands either, why can't we apply any CSS to them?

    Like we can use <b> html tag, but can't use button text color.

    Link to comment
    Share on other sites

  • Topic Author
  • 1 hour ago, Neo Andersson said:

    Really helpfull.. Just a side question. If we can manipulate with UI elements behaviour, and even we can use some CSS styling commands either, why can't we apply any CSS to them?

    Like we can use <b> html tag, but can't use button text color.

    I believe that they filter the strings. It's a similar thing with the log console - it accepts some tags but not others.

    Link to comment
    Share on other sites

  • Topic Author
  • Posted (edited)

    If you live in the Apple ecosystem this is a way to get location data for your devices. If you have FamilyShare you can track the whole family.

    A precondition is that you have a Mac of some sort that can run the "FindMy" app 24x7.

    The FindMy app logs all data to a file in the system so that we can read and push it to the HC3.

    Here is a script that does that and needs to be run in a Terminal window.

     

    It's kind of nice as we don't have to poll the iCloud service ourselves (Apple is better at that) and we also get the new items, like AirTags, positions.

    A simple receiving QA looks like below

    Please login or register to see this code.

    (will make my iOSLocator QA have support for this)

     

    The data is a lua table with the items/devices that have changed. The format of an item/device is

    Please login or register to see this code.

     

    Here is the script:

    Please login or register to see this code.

     

    Edited by jgab
    Link to comment
    Share on other sites

    Jan, sounds excellent

    Quote

     

     

    Edited by Sjakie
    Link to comment
    Share on other sites

    Jan, have patience its a kind of difficult for a ex Windows user.

    Installed Brew

    Installed LUA version 5.4.4.1

    did>>> ln -s ~/Documents/LUA /opt/homebrew/bin/lua>>>>ln: /opt/homebrew/bin/lua: No such file or directory{removed space after Lua }  no error

    Did it all(I hope) terminal window ended after past your file in Macbook with>>dquote

    To give full disk acces I have a problem, LUA is't showing.

    I can click + but I have no clue where to go???

    Please advice

    Edited by Sjakie
    edit
    Link to comment
    Share on other sites

  • Topic Author
  • Posted (edited)
    1 hour ago, Sjakie said:

    Jan, have patience its a kind of difficult for a ex Windows user.

    Installed Brew

    Installed LUA version 5.4.4.1

    did>>> ln -s ~/Documents/LUA /opt/homebrew/bin/lua>>>>ln: /opt/homebrew/bin/lua: No such file or directory{removed space after Lua }  no error

    Did it all(I hope) terminal window ended after past your file in Macbook with>>dquote

    To give full disk acces I have a problem, LUA is't showing.

    I can click + but I have no clue where to go???

    Please advice

    Sorry, the arguments should be switched for the ln  command 

    Please login or register to see this code.

    then you end up with a file 'LUA' in the Documents folder.

    That file you can open when giving full disk access.

     

    Oh, it's not sure it's /opt/homebrew/bin/lua.

    Run

    Please login or register to see this code.

    to find out where the lua you have is installed.

    Edited by jgab
    Link to comment
    Share on other sites

    Ok /opt/homebrew/bin/lua is the path. >>usr/local

    How to add in Privacy full acces?

    if I open Full permission, open lock, shift-cmd-g it open the folder with Folder/ file to click?

    Please advice

    Link to comment
    Share on other sites

  • Topic Author
  • Posted (edited)
    1 hour ago, Sjakie said:

    Ok /opt/homebrew/bin/lua is the path. >>usr/local

    How to add in Privacy full acces?

    if I open Full permission, open lock, shift-cmd-g it open the folder with Folder/ file to click?

    Please advice

    Ok, so you managed to create a shortcut in your document folder named LUA

    Open a terminal window and go to the Documents folder where the shortcut is and try

    >LUA

    just to see if it runs the "real" lua program

    Then in the in "System Preferences" open "Security & Privacy"

    Click tab "Security"

    Unlock the lock in the lower left corner (entering password)

    Scroll down to "Full disk access" in the left column and select it.

    Click on the '+' under the rightmost column, in open dialog choose the Documents/LUA file.

    "Lock" the lock again.

    Edited by jgab
    Link to comment
    Share on other sites

    Jan, no I don't have it in Documents!

    I can go to usr/local but I don't know which file to choose.

    If I open LUA it show me a black screen with Exec in green letters or it show

    LUA.h if opens

    Please login or register to see this code.

    and a lot of text more

    Link to comment
    Share on other sites

  • Topic Author
  • If you did

    Please login or register to see this code.

    where you "/opt/homebrew/bin/lua" replace with whatever path you get when you run "which lua"

    you will have a file named LUA in your documents folder.

    Link to comment
    Share on other sites

    Jan, thanks I guess it's done finished your guidance an ddi't receive any error.

    Will wait on your adapted QA?

    How I can see if it's working.

    Debug logTekst is empty orders it need some time?

     

    Link to comment
    Share on other sites

  • Topic Author
  • In the script you need to list the IDs of the devices you want notifications for (all devices with IDs are listed when the script starts up)

    Then on the HC3 install 

    Please login or register to see this code.

    and set the QAname in the script to the id or name of the QA you installed on the HC3.

    When the script starts up it should send the positions of all the devices to the QA.

    Link to comment
    Share on other sites

    Sorry Jan one step back.

    Created QA testLock with the exact text you posted.

    Create whith script editor script file my data include, file named pushFmipcore.lua

    Stored in Library/Script Editor

    If execute lua pushFmipcore.lua  in terminal window >>>>can't find the file.

    Please advice

    Link to comment
    Share on other sites

  • Topic Author
  • Ehh, Script Editor on the Mac is not a general purpose editor. It's used to create Apple scripts. Did you even manage to save as it checks the syntax and will most likely not accept Lua.

    Please use something like TextEdit app. Make the format plain text and save as Unicode (UTF-8)

    Save the script in your Documents folder somewhere. Ex Documents/luascripts/  (Library/Script Editor is probably only for apple scripts)

    Then open a terminal window

    Move to the directory where you saved the script . Ex

    >cd ~/Documents/luascripts/

    and try to run it

    >lua  pushFmipcore.lua

     

    Just now, jgab said:

    Ehh, Script Editor on the Mac is not a general purpose editor. It's used to create Apple scripts. Did you even manage to save as it checks the syntax and will most likely not accept Lua.

    Please use something like TextEdit app. Make the format plain text and save as Unicode (UTF-8)

    Save the script in your Documents folder somewhere. Ex Documents/luascripts/  (Library/Script Editor is probably only for apple scripts)

    Then open a terminal window

    Move to the directory where you saved the script . Ex

    >cd ~/Documents/luascripts/

    and try to run it

    >lua  pushFmipcore.lua

    It can also be the time to install ZeroBrane, the lua development environment. It comes with an excellent editor for Lua files.

    Link to comment
    Share on other sites

    Please login or register to see this code.

    Jan, you are right!

    Texteditor add .txt but does'show it.

    Zerobrane installed and save  did the trick, chapeau!

    Now I feel myself obliged to start also with ZB to test QA's>> will become a long way.

    In terminal I get this, must I do something more because its a list:

    Link to comment
    Share on other sites

  • Topic Author
  • Have you installed luajson?

    Please login or register to see this code.

    Which requires that you have installed HomeBrew and luarocks

    Please login or register to see this link.

    and then install luarocks

    Please login or register to see this code.

     

    Unfortunately you can't run the script from within ZeroBrane as it seems to be complicated to give ZeroBrane the "full disk access" needed.

    THat's why we need to run in a terminal window. You wouldn't want to run/occupy this script 24x7 with ZeroBrane anyway

    Link to comment
    Share on other sites

    Jan from the previous list is only the Jason gone all others are still there.

    homebrew >>was already installed

    luarocks also

    new was >>>luarock install luajson>>>>done

    lua 5.4.4.1 all ready installed

    I don't know what to do more

    Link to comment
    Share on other sites

  • Topic Author
  • In the documentation in the header of the script it also says

    Please login or register to see this code.

     

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