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


[TUTORIAL] - Using a Hometable to store device and scene ID's


Recommended Posts

hi,

This tutorial is based on an idea that i believe originated to @cag014 some time back and has been adopted by many.

So well deserved kudos to @cag014 and others that helped originate and develop the concept. I am merely a scribe that has benefited from this.

 

I decided to write a quick tutorial for two reasons...

  1. I implemented this over christmas and and found it very useful and much easier than I thought
  2. It would appear that we have some new forum members that got HC2 devices from Santa :-)

 

The core of this approach is to store all the reference ID's to your devices, virtual devices, scenes, etc in a json encoded table. The references like jT.kitchen.light are used in the scene or vd and device ID can easily be changed in the table. One important benefit is that it you need to exclude/include a device the device ID will change. With this approach you simple change the reference in the Home table and your done. Without this approach you wll need to go through your code and change the device ID where appropriate.

 

** This doesn't get over the need to enter ID as triggers in the scene headers as fibaro doesn't allow variable in the header **

 

The solution has two parts to it.

  1. The home table itself where the data is stored. - this is held in a predefined variable (lower part of variables panel)
  2. The references in your scenes and virtual devices use this table 

 

HOME TABLE
This can be created and maintained through either a scene or a virtual device. I chose a VD but there is no advantage I can thing of using one way or the other.

 

Go to Panel, Variables Panel and create a new predefined variable (lower part of panel) called HomeTable. When you create a predefined variable it has two values. Name the variable and save. Edit the variable and simply delete the second value.

Please login or register to see this attachment.

 

Using either a scene or a vd create your table and store it.

This is lua from my VD. I create one button and enter the code below.

The top part shows the format of the table. I opted to place each element I am looking to store into rooms and/or other natural groupings but you can choose any way to structure. I'll attached a copy of my full table at the end of this to show what I use it for.

The next part encodes and stores the data

The last part is where I read back one entry to show the table stored okay.

 

Please login or register to see this code.

the output of this when I click the button (or run the scene is as follows)

Please login or register to see this attachment.

 

It is reading back the ID (1548) stored for Motion under the kitchen grouping

 

I would recommend using an external editor like Notepad++ or Zerobrane to edit/manage the code in the vd and then copy back to the vd when ready to update as the HC2 lua editor is very small

 

At this stage you now have your table

 

REFERENCING THE TABLE CONTENTS IN YOUR SCENES AND VIRTUAL DEVICES 

For this you need to place the following line of code in each scene or vd

Please login or register to see this code.

and then use references instead of device ID's in the scene code.

The easiest way to explain this is with an example. This scene switches on a light in my kitchen if it is dark, motion is detected and no light is on already

 

Please login or register to see this code.

It's easy enough to see how the references are built up if you examine the scene v the table at the top of this post

and that it !!

 

Addition:

If you need to adjust a single parameter in the table you can use the following. This can be useful if you don't want to adjust one value and then copy the whole table back into the vd and update or more useful if you want to adjust the value in the fly in a script.

 

Please login or register to see this code.

Hopefully this will help some users

If you have any suggestions as to how to improve this please let me know and I'll edit

 

-frank

 

++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Copy of my table to show how flexible this approach can be

 

Please login or register to see this code.

 

 

 

 

 

 

 

 

Edited by AutoFrank
Link to post
Share on other sites
  • 3 weeks later...

Hi!

as far as I understood, you have to manually find your devices/Ids and enter them in the above json strukture, right? I guess for people with a lot of devices, this might be really time consuming.

Could there be a way to automatically get the device infos read-out to a json structure?

 

cheers

joystick

Link to post
Share on other sites
  • Topic Author
  • 38 minutes ago, Joystick said:

    Hi!

    as far as I understood, you have to manually find your devices/Ids and enter them in the above json strukture, right? I guess for people with a lot of devices, this might be really time consuming.

    Could there be a way to automatically get the device infos read-out to a json structure?

     

    cheers

    joystick

     

    Hi @Joystick

     

    There is a way to scan the HC device and create a json table

    If you take a look in the first post (

    Please login or register to see this link.

     ) and look for a reference to @ReneNL code to search the HC2. It works very well :-)

     

    Link to post
    Share on other sites
    • 1 year later...

    The topic has been moved from "

    Please login or register to see this link.

    " to "

    Please login or register to see this link.

    ".

     

    Temat został przeniesiony z "

    Please login or register to see this link.

    " do "

    Please login or register to see this link.

    ".

    Link to post
    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...