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


Function Library for Rookies


HH5050

Recommended Posts

Hi Fibaro/Community, 

 

Before buying fibaro and 90+ devices to set up the house, I did some basic programming on the HC2. I liked the ability of making a small function library and using my functions in scenes and triggers. I am not a great programmer but the great help of the community and code snippets available make a central function library VERY useful to a novice like me and makes it easy to write a function once and then use it successfully later.

 

However I ended up buying HC3 and here EVERYTHING is different. As many have written. For the great programmers this seems to be no problem, you guys are deep into QuickApps and OO classes and the loss of the HomeTable is not a problem for you, and the amazing EventRunner class in HC2 seems to have found a home in Quickapps - BUT - this is pretty hard for the novice like me to follow. 

 

It is like Fibaro has decided to provide a super complex API but no path to learn in steps for the novice. Like playing Donkey Kong without ramps up. 

 

Fibaro if you are listening : What is the way for a novice to make a function library with simple small functions to reuse in scenes? Like a small function to turn on a given ID of a light, then turn it off 60 seconds later. Trivial I know, but why copy this 100 times in each scene when a function would do? 

 

Fibaro, also, how to create a table of all the IDs of my motion sensors and a column with light IDs to turn on, and the time delay until turn off? The hometable concept in HC2 could have done that. But in HC3?

 

I know it is super advanced somewhere up there but for basic programmers like me who have googled and read the forums and only found the super stuff like Quickapps, what do we do? It seems to me there are only 20 people in the world who understand HC3. Like Quantum Mechanics. 

 

You need please to help the people below that.. 

Link to comment
Share on other sites

19 minutes ago, HH5050 said:

Hi Fibaro/Community, 

 

Before buying fibaro and 90+ devices to set up the house, I did some basic programming on the HC2. I liked the ability of making a small function library and using my functions in scenes and triggers. I am not a great programmer but the great help of the community and code snippets available make a central function library VERY useful to a novice like me and makes it easy to write a function once and then use it successfully later.

 

However I ended up buying HC3 and here EVERYTHING is different. As many have written. For the great programmers this seems to be no problem, you guys are deep into QuickApps and OO classes and the loss of the HomeTable is not a problem for you, and the amazing EventRunner class in HC2 seems to have found a home in Quickapps - BUT - this is pretty hard for the novice like me to follow. 

 

It is like Fibaro has decided to provide a super complex API but no path to learn in steps for the novice. Like playing Donkey Kong without ramps up. 

 

Fibaro if you are listening : What is the way for a novice to make a function library with simple small functions to reuse in scenes? Like a small function to turn on a given ID of a light, then turn it off 60 seconds later. Trivial I know, but why copy this 100 times in each scene when a function would do? 

 

Fibaro, also, how to create a table of all the IDs of my motion sensors and a column with light IDs to turn on, and the time delay until turn off? The hometable concept in HC2 could have done that. But in HC3?

 

I know it is super advanced somewhere up there but for basic programmers like me who have googled and read the forums and only found the super stuff like Quickapps, what do we do? It seems to me there are only 20 people in the world who understand HC3. Like Quantum Mechanics. 

 

You need please to help the people below that.. 

HomeTable is still working in HC3.

For easy programming use Eventrunner3 see else in this forum

Around 4-8 QA's for automatization off the whole house

Succes

Link to comment
Share on other sites

Welcome to the forum @HH5050

 

You are addressing Fibaro in your questions, I don't know if Fibaro will answer you via this Forum. But there are a lot of users on this forum.

 

Generally, you are asking for a library, this forum is actually some kind of library. There are quickapps, scenes, etc available, just use the search button and perhaps in first you will get overwhelmed by the information. 

 

There is a HomeTable for the HC3 available.

There also is a great (quickapp) function library from Jgab. 

There are also manual with nice examples: 

Please login or register to see this link.

 

Ask questions, give it some time to absorb the answers and info and have fun. 

 

Link to comment
Share on other sites

56 minutes ago, HH5050 said:

Like a small function to turn on a given ID of a light, then turn it off 60 seconds later.

 

You can make it in a block scene and convert this to Lua. This shows you the code.

Working with tables is Lua knowledge, not specific HC3. In HC3 a lot of api calls are wrapped in functions like:

 

  • hub:getRoomID(deviceID)
  • hub:getSectionID(deviceID)
  • hub:getDeviceIDByName(deviceName)
  • hub.getValue()

I know the feeling. When starting with the HC3 it can be overwhelming. Give yourself some time. 😀

  • Like 1
Link to comment
Share on other sites

  • Topic Author
  • @Joep thanks for the empathy, the block conversion has taught me a lot. I guess that hard part is that if you want to learn e.g. PHP or Python, there are step-by-step tutorials and documentation. With LUA it is a firehose of stuff and the change in API from HC2 to HC3 is confusing everyone.

     

    For example, above you write : hub:getroomID(deviceID), but it should be . , not, :, no ? I struggled with this for hours before finally found this somewhere. Using : it does not even give a good error response. This is very not user friendly and I think even you pros struggled with this in the HC2->HC3 transition. 

    Link to comment
    Share on other sites

    2 minutes ago, HH5050 said:

    For example, above you write : hub:getroomID(deviceID), but it should be . , not, :, no ? I struggled with this for hours before finally found this somewhere.

     

    This is Lua knowledge. It has to do with object oriented programming. See: 

    Please login or register to see this link.

     and from FIBARO: 

    Please login or register to see this link.

     

     

    Link to comment
    Share on other sites

  • Topic Author
  • thank you, I see the colon is for a different purpose. So hard to find for newbies. Especially since HC2 was :. This is what I mean that Fibaro has made this very hard for us who are used to PHP and Python and Matlab and even C being so much better described... Anyway, I rant...  Another question if I may...: How can I find a ROOM ID in the HC3 either on the UI or by listing all rooms?

     

    To list all rooms, I understand a REST call is required, and I found this code, but it does not seem to work for me (filling the access creds of course)

     

    Please login or register to see this code.

     

    anyone have a function to hit the REST API in a way that works?

    Link to comment
    Share on other sites

    For the HC3 local api in Lua scenes use the function: api.call().
    See my blog about it: 

    Please login or register to see this link.

     

     

    Link to comment
    Share on other sites

    Please login or register to see this code.

     

    Well, the language, Lua, is not changed by Fibaro. Access to standard Lua functions are a bit restricted by Fibaro but that's another story.

    Then Fibaro has their own libs/functions and QA classes that are a bit different from how we developed on the HC2.

    • Like 2
    Link to comment
    Share on other sites

  • Topic Author
  • omg amazing - @jgab  - you just reduced two pages of code which didn't work with http.request panic, to 3 lines. THANK YOU! This is exactly what fibaro should have a tutorial for, just ways to get newbies going with code snippets like this. I have googled for hours and scrolled in panic through the LUA docs and Fibaro API docs and it really is like picking up pieces of a broken glass on the floor. You know it's supposed to fit together but there is no plan.

     

    Fibaro should do better. Its users are awesome to do the job for them.... Thank you. 

    Link to comment
    Share on other sites

    39 minutes ago, HH5050 said:

    Fibaro should do better. Its users are awesome to do the job for them.... Thank you. 


    That is probably the whole idea of this Forum 😃

    Link to comment
    Share on other sites

  • Topic Author
  • Hi again, if I can draw on your guidance again, very appreciated and thank you again and sorry for newbie questions... my fibaro installer made me some scenes using block diagrams and then I converted them to LUA to be more manageable (he did not know LUA at all or programming so I am on my own now..) The code produced was this :

     

    Please login or register to see this code.

     

    The point of this code is to trigger on a CRON event at midnight and turn off most lights (but not all). Obviously the above is impossible to debug, or adjust if I want to add/remove a light here in a given room, etc. - since I have no idea what the IDs above are. 

     

    I have found REST API calls VERY USEFUL and so I thought I might generate the above LUA code from e.g python where I can put the lights in a database and group them nicely and then copy this generated code manually into HC3 for the various 10-20 scenes I want (different light levels depending on time of day, different rooms/on/off etc.) 

     

    Obviously this feels clumsy. I am pretty ok with Matlab/Python but clearly crap in LUA so I am just clutching at straws.

     

    How do you pros manage this sort of situation? How do you group your devices to make calling groups of things easy? How do you maintain this when you add devices or change your mind on how to group things or what to include?

     

    Without a function library it becomes very silly to copy paste various versions of group generated code from Matlab/python to LUA in HC3...

     

    Can I ask for your guidance on this please? 

    Link to comment
    Share on other sites

    I am kind of lost what you actually want to achieve.

     

    Maybe first in logical text write what you want, before already thinking in solutions. Or maybe post a photo of the actual blockscene.

    Don't try to make it more complex with Python, If you know Python, it ain't hard to learn Lua. Focus on the examples in the Fibaro manuals. 

     

    But, to turn group of  lights off, is simply this: 

     

    fibaro.call({51, 52, 53}, "turnOff")

    Link to comment
    Share on other sites

    11 hours ago, HH5050 said:

     

     

    Please login or register to see this code.

     

    The convert from block scenes are a bit "clumsy". This is the same as

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