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


  • 1

[TUTORIAL] ZeroBrane Usage (Lua Coding)


riemers

Question

Latest version of Lualibs = 

Please login or register to see this attachment.

 

Changelog for v1.0.1 (thank to @petergebruers

- fix HC user authentication (was: user:password in URL, is now: basic authentication).
- fix chunked responses (was: use only chunk 1, is now: concatenate chunks). Fixes "getDevicesId".
- add error checking and display in the HTTP part, to get sensible error messages.

 

Most of the information came from the french forum which can be found

Please login or register to see this link.

 all credits go to Steven!

 

ZeroBrane is an IDE for development in Lua code. It offers you auto completion and partial support to use the actual fibaro: option in your code too. To get started grab the latest version from 

Please login or register to see this link.

 (1.5.0 as of writing) grab your favorite flavor. It supports Mac, Windows and Linux.

 

To use the Lua Library you have to install it, grab the lua libs (top of page) for fibaro. You need to install these files in your c:\<yourlocation>\ZeroBraneStudio\lualibs (for Mac this would be /Applications/ZeroBraneStudio.app/Contents/ZeroBraneStudio/lualibs) after that a restart of the app is a good thing to do.

Use this always in your code when you start testing your setup. For example:

Please login or register to see this code.

Do keep in mind this is your userid/password on the box itself, do NOT use a fibaro ID since that is only the login to your remote.

 

To change the Colors to be the same as on Fibaro (if you feel really cozy with those colors) edit your user settings at: Edit -> Preferences -> Settings: User

Please login or register to see this code.

And if you want to have auto completion you have to add 

Please login or register to see this attachment.

 to your ZeroBraneStudio/api/lua folder.

Please note that this file is the english file and has some few additions which i didn't see or where incorrect. Looks like:

Please login or register to see this attachment.

 

To activate it, please make sure you add it. Go to Edit -> Preferences -> Settings: System

Add the following string to it:

Please login or register to see this code.

The fibaro:calculateDistance doesn't work and the sourcetrigger needs to be set manually. See below snippet for testing:

Please login or register to see this code.

FAQ:

Q: I get the following error message: lualibs/json/decode.lua:74: bad argument #1 to 'match' (string expected, got nil)

A: It cannot reach Fibaro system correctly. Please make sure you have the right userid/pwd and correct ip number.

 

Q: I don't see any completion on my fibaro: 

A: Make sure you added the completion Edit -> Preferences -> Settings: System (lualib)

 

Q: Where do i get all my values from?

A: You can make use of the excellent tool from @Krikroff found

Please login or register to see this link.

 to grab all the values.

 

Q: Where is this data coming from?

A: Fibaro has an api interface, you can go there via http://192.16.x.x/docs where you can try it out. 

 

Q: I click on play but it does not keep running?

A: Make sure you click the double green arrow. The other one stops untill you press forward. (F6 = Go, F5 = Waits on next itteration)

 

Q: I want to change the width of the tabs

A: Go to Edit -> Preferences -> Settings: User and add "editor.tabwidth = 3"

 

Q: Disable wordwrap for long lines

A: Go to Edit -> Preferences -> Settings: User and add "editor.usewrap = false"

 

Q: How to i debug line by line?

A: See below (credits go to

Please login or register to see this link.

 for below screenshots & explanation)

 

Open Zerobranstudio and display the following windows if you have not already done so

Please login or register to see this link.

 

insert the following code in a new blank window Zerobranstudio (we will revise multiplication ;)

Please login or register to see this code.

To activate dynamic tag tracking, simply select the name of the variable you want to track, then right click on it to bring up a context menu.

You must then select the option Add watch expression as in the image below. In our case, it must be done for the 2 variables i & j.

 

Please login or register to see this link.

 

To switch to debug mode, press the F5 key once, the window should look like this.

The green cursor is positioned on the first instruction, and the Watch window displays the values of i and j (to nil at the moment which is logical)

 

Please login or register to see this link.

 

Now press the F10 key to execute the program step by step, until the first result of the multiplication is displayed, as shown below.

The result of the multiplication is consistent with the values of i and j.

 

Please login or register to see this link.

 

To test now the modification on the fly of a variable, we will re-run the loop a second time by pressing the F10 key several times but without executing the print instruction, as in the image below. The value of the 2 variables has been modified by programming.

 

Please login or register to see this link.

 

To modify dynamically the value of j, click on the Remote console tab, type the line i = 20 then press the Enter key to validate the command, as in the image below. We can then see that the value of ja has been modified in the Watch window.

 

Please login or register to see this link.

 

It is now enough to click on the tab Output (suspended), and to press the key F10 to resume the execution of the program.

It is now that the value of j set by hand has been dynamically taken into account by the program.

 

Please login or register to see this link.

 

Happy Coding! \o/

(feel free to make remarks so i can make it better)

Please login or register to see this attachment.

Edited by riemers
Change to lualibs 1.0.1
  • Thanks 3
Link to comment
Share on other sites

Recommended Posts

  • 0
2 hours ago, Twannie said:

when I run Zerobrane my virus program gives several warnings, does this sound familiar?

No, haven't seen that.

Is it the ZBS installer (.exe) that triggers the warning? It's a good chance that it's a false positive (there have been earlier reports on that, but not the latest)

Are you running the latest version of ZBS (v1.90)?

Link to comment
Share on other sites

  • 0

Lates from website, I noticed my virus program blocked the app because "program is trying to change another program"

Link to comment
Share on other sites

  • 0
Guest JeanOchmann

Hi @riemers,

maybe you can help/support me. Its more or less my first time using ZeroBrane. Like the idea and finally found something to debug my fibaro code.

Currently I am struggling in regrads of using the method net.HTTPClient(). Everytime I am getting the same error, that the global 'net' has a  nil value. 

 

Do I require some extra lib or something like that, so I can use it?

 

Thx for your support.

 

Jean

Link to comment
Share on other sites

  • 0
  • Inquirer
  • 5 years later.. I only use Fibaro as a zware device with home assistant. Fibaro is rock solid for devices and home assistant gives me all the freedom I was missing. So I no longer build in lua (node red these days)

    Link to comment
    Share on other sites

    • 0
    13 hours ago, JeanOchmann said:

    Hi @riemers,

    maybe you can help/support me. Its more or less my first time using ZeroBrane. Like the idea and finally found something to debug my fibaro code.

    Currently I am struggling in regrads of using the method net.HTTPClient(). Everytime I am getting the same error, that the global 'net' has a  nil value. 

     

    Do I require some extra lib or something like that, so I can use it?

     

    Thx for your support.

     

    Jean

     

    You can try 

     

    It has not been updated since 2019, but it supports net.HTTPClient, getting triggers from devices on the HC2,  and even simulating devices...

    Please login or register to see this code.

     

    For HC3 development I recommend 

    Please login or register to see this link.

     

    Edited by jgab
    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
    Answer this question...

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