Jump to content

Tutorial - Using a Hometable to store device and scene ID's


Recommended Posts

2 hours ago, robw said:

I'm sorry to hear you have issues with it. Personally, the only issue I've had was the broken motherboard. I almost always also run the beta build of the software, and that have been stable, too. All I can think of is that you have some scenes/code that makes the system unstable, or a faulty unit. I have a some simple block scenes, and then I run a lot of UHAS scenes and VD's to drive the majority. I have a mix of Hue lights, Fibaro sensors (door sensors, fire sensors, eye sensors, water sensor, power switches) and also a power switch from another brand, an outdoor type. The HC2 covers 3 stories in the house and also outdoors. It runs very good and stable for me.

 

Send as much logs as you can to Fibaro first. If that does not work, hear with them if it is a chance that the unit itself could be malfunctioning.

 

Hope it all gets resolved!

 

Perhaps I wasn't clear enough.

 

I have many scenes that rely on tables of device IDs to function.

 

The scenes loop through the tables to perform tasks e.g. change the entire heating profile to hotter or colder and then report on current temp / target temp etc of every zone in the house. 

 

I want to implement home table, however I need to be able to reference the home table descriptions in a table to replace all of the id's e.g. replacing the last 5x columns in the table below with references to home table descriptions:

 

--                                                                                            Rad1-Rad2 / Temp1-Temp2 / Zone_ID
    local Heating_Zone_Table = 
            {
            a1                =    {"TV",                            "Label43",         567,"",        488,"",          4},
            a2                =    {"Rear_Bed",                "Label12",        560,"",        640,"",           6},
            a3                =    {"Library",                     "Label44",        873,"",        492,"",           4},
            a4                 =     {"Loft_Bed",               "Label14",        557,"",        380,"",            8},
            a5                =   {"Front Bed",                 "Label13",        568,"",        579,"",          13},
            a6                =    {"Family_Bath",           "Label18",        562,"",        787,"",            7},
            a7                =    {"Loft_Bath",                "Label19",        558,"",        606,"",        670},
            a8                 =     {"Family_Bath_UF",   "Label8",         548,"",         877,876,      11},
            a9                =    {"Loft_Bath_UF",         "Label7",          404,"",        411,412,       12},
            a10             =     {"1st_Corr",                  "Label42",        561,"",        573,"",            5},
            a11             =     {"Mast_Bed",               "Label11",        870,"",        637,"",        860},
            a12             =     {"Garden_Bath",          "Label27",        563,"",        922,"",        861},
            a13             =     {"Master_Bath",          "Label17",        871,"",        637,"",        860},        
            a14             =     {"Kit_Din_UF",             "Label5",          566,"",        880,881,    858},
            a15             =     {"Kit_Din",                    "Label30",        566,"",        514,"",        858},
            a16             =     {"Kit_Liv_UF",              "Label28",        874,"",        880,881,    858},
            a17             =     {"Kit_Liv",                     "Label31",        874,"",        779,"",        858},
            a18             =     {"Garden Room",        "Label15",        563,"",        579,"",        861},
            a19             =     {"Kit_WC_UF",             "Label29",        565,"",        878,879,    858},
            a20             =     {"Kit_Corr",                  "Label26",        565,"",        767,"",            5},
            a21             =     {"Loft AV",                   "Label25",        559,"",        380,"",            9}
            }

    Heating_Zones = function (trigger) 
    local returnString = Heating_Zone_Table[trigger] 
    returnString = returnString[icolumn]
    return returnString 
    end

 

 

Edited by amilanov
Link to post
Share on other sites
  • Replies 154
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular 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

Wow, nice to see so much traction on this post/thread! @Momos, sorry have been away/busy, but your question to add section info triggered some more elaborate thoughts and suggestions, in additi

Here's another version that automatically adds users and scenes too. All room/device/scene/etc names are converted to lowercase (except the mobile device name so it can be copy/pasted from the Access

Posted Images

Ok, I think I understand. 

Yes, you need to use som "HT string" to store the reference to deviceIDs in other tables. 

It's doable.

 

 local HT =  -- Example of "home table"
{ 
  bedroom = {lamp = 88,motion = 99},
  phones = {bob = 121},
  kitchen = {lamp = 66, motion = 77},
  tvroom = { heating = 123}
}

-- First approach
-- A small cost every time we need to lookup a "HT string"
-- It's ok if we do a moderate amount of lookups

 function HTget(HT,path)
    local h,p,i=HT,split(path,"."),1
    while h and p[i] do h=h[p[i]] i=i+1 end
    return h
  end
  
  fibaro:debug(HTget(HT,"tvroom.heating"))

-- Second approach
-- Create a reverse lookuptable
-- Takes a little time to buildup but makes lookups very fast

local function mapHT(HT,res,k1)
    res,k1 = res or {}, k1 or ""
    if type(HT) == 'table' then
      for k,v in pairs(HT) do
        mapHT(v,res,k1..(k1~="" and "." or "")..k)
      end
      return res
    else res[k1]=HT end
end
HTMAP = mapHT(HT)
  
fibaro:debug(HTMAP["tvroom.heating"])

So, then you can store "tvroom.heating" in your  Heating_Zone_Table 

 

Ex.

local Heating_Zone_Table = 
{
a1 = {"TV", "Label43", 567,"", 488,"", "tvroom.heating"},

and then do

fibaro:call(HTMAP[Heating_Zone_Table.a1[7]],"on")

-- or

fibaro:call(HTget(HT,Heating_Zone_Table.a1[7]),"on")

I noticed that my example use tvroom.heating and not heating.tvroom as in your example... I just prefer putting things in rooms and not rooms in things ;-)

Edited by jgab
Link to post
Share on other sites
11 hours ago, jgab said:

Ok, I think I understand. 

Yes, you need to use som "HT string" to store the reference to deviceIDs in other tables. 

It's doable.

 

 local HT =  -- Example of "home table"
{ 
  bedroom = {lamp = 88,motion = 99},
  phones = {bob = 121},
  kitchen = {lamp = 66, motion = 77},
  tvroom = { heating = 123}
}

-- First approach
-- A small cost every time we need to lookup a "HT string"
-- It's ok if we do a moderate amount of lookups

 function HTget(HT,path)
    local h,p,i=HT,split(path,"."),1
    while h and p[i] do h=h[p[i]] i=i+1 end
    return h
  end
  
  fibaro:debug(HTget(HT,"tvroom.heating"))

-- Second approach
-- Create a reverse lookuptable
-- Takes a little time to buildup but makes lookups very fast

local function mapHT(HT,res,k1)
    res,k1 = res or {}, k1 or ""
    if type(HT) == 'table' then
      for k,v in pairs(HT) do
        mapHT(v,res,k1..(k1~="" and "." or "")..k)
      end
      return res
    else res[k1]=HT end
end
HTMAP = mapHT(HT)
  
fibaro:debug(HTMAP["tvroom.heating"])

So, then you can store "tvroom.heating" in your  Heating_Zone_Table 

 

Ex.

local Heating_Zone_Table = 
{
a1 = {"TV", "Label43", 567,"", 488,"", "tvroom.heating"},

and then do

fibaro:call(HTMAP[Heating_Zone_Table.a1[7]],"on")

-- or

fibaro:call(HTget(HT,Heating_Zone_Table.a1[7]),"on")

I noticed that my example use tvroom.heating and not heating.tvroom as in your example... I just prefer putting things in rooms and not rooms in things ;-)

 

OMG!!!

 

Thank you for taking the time to explain that in such detail.

 

I tested the HTMAP option as I am calling a fair amount of devices (subjectively).. not sure what defines small/large in this case.

 

PS: I agree that you should put things in a room. The "heating" room is a plumbing room with actuators and fibaro relays for each heating zone, hence "heating.tv_room" makes sense  in this case :)

 

I owe you a beer for that!

 

Regards

Aleks

 

 

 

 

 

 

Link to post
Share on other sites

I've seen some automated HomeTable scenes, you could also look for them. An example here: 

Thank's to jgab for helping out!

Edited by robw
New link.
Link to post
Share on other sites

Am I right in saying that the ID of the heating panels is not picked up automatically through the code that AutoFrank @ wrote?

 

In which case I would have to hardcode the IDs into the user defined section at the top?

 

-- HOME TABLE FOR ANYTHING IN ADDITION TO DEVICES, VDs, iOS DEVICES
-- EDIT TO YOUR NEEDS OR KEEP BLANK: jsonHome = {}
jsonHome = {

	scene = {
		MainScene=614,AlarmControl=598,rebootHC2=593,goodMorning=463,goodNight=331,LeavingHome=483,welcomeHome=488,quietMorning=499,kidsToBed=490,plaroomTvOn=580,firstFloorMusicOn=579,firstFloorAllOff=578,
		hallSceneControl=519,StairsLight30=556,GateOpen5=526,GateOpenHold=361,GateOpenClose=425,DumpEventLog=565,PlayroomOff=617
	},

	users = {
		admin=2,frank=1564,sylvia=1565
	},
}

 

 

 

Edited by amilanov
Link to post
Share on other sites
6 hours ago, amilanov said:

Am I right in saying that the ID of the heating panels is not picked up automatically through the code that AutoFrank @ wrote?

 

In which case I would have to hardcode the IDs into the user defined section at the top?

I'm not a big fan of autogenerating the hometable so I haven't tested the code. 

However, it should automatically find all devices that are visible and enabled. Have you hidden the devices?

VDs you need to add yourself, like the scenes in the example.

  • Like 1
Link to post
Share on other sites
1 hour ago, jgab said:

However, it should automatically find all devices that are visible and enabled. Have you hidden the devices?

 

I'm not referring to devices. I'm referring to the heating panel. 

 

Maybe someone else on the forum has used the heating panel before and knows if it is possible to auto generate the IDs?

Link to post
Share on other sites
1 hour ago, amilanov said:

 

I'm not referring to devices. I'm referring to the heating panel. 

 

Maybe someone else on the forum has used the heating panel before and knows if it is possible to auto generate the IDs?

Sorry, I don't have any heating in HC2 so I misunderstood you.

You can access your heating info that is available under panels with Lua

Have a look at  http://<hc2-ip>/docs 

There you have all the APIs (heating is under panels).

Ex api.get("/panels/heating") 

(I'm a bit unsure exactly the syntax but it is shown in the docs)

and you get back the data as a Lua table where you should be able to pick out the IDs

 

Link to post
Share on other sites

Thanks again.


This is how you get the id's in one go: http://IP_ADDRESS/api/panels/heating

 

I was asking about the auto generation of these ids in HomeTable.

Link to post
Share on other sites
  • 3 months later...

[SOLVED] 

Hello

 

I am a newbie with HC2 and in he process of learning LUA

Thank you for the HomeTable concept which is very usefull !

I try to get the defined users ID in the HomeTable but this "type" is not included, how shouldI do to get the iDof a restricted user (Superusere being 2) in the Home table ?

 

Thank you for your help

Edited by Manuc
SOLVED
Link to post
Share on other sites

Hello

Can HomeTable content be used in header %%properties ? Is there a trick ?

Thank you

Edited by Manuc
Link to post
Share on other sites
  • 6 months later...

can homeTable store also only rooms but not like fisical put it in it, but just like the devices with filter

@Manuc dont think so, so i made

valueProperties = function()
    function log(...)
        local buffer={}
        buffer[1]="<pre>"
        for i,v in ipairs{...} do
            buffer[#buffer+1]=v
            buffer[#buffer+1]=" value<br>"
        end
        Debug("green", table.concat(buffer))
    end
    log(doorID,lightID) --put here youre devices
end
if debug then valueProperties() end

 

copy and paste in %%properties

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

Hi all,

 

Some wonderful scene's and VD etc. can be found here. There seem to be a lot of versions for creation of Hometable. Is there a final and comprehensive version for automatic creation of Hometable?

Maybe it should be obvious to me, but isn't.... sorry about that.

Edited by Theo-Fibaro
Link to post
Share on other sites
  • 2 weeks later...

Sorry Newbie .... I use the HT on HC2 is the HomeTable scene compatible with the HC3 ?

 

Thank you

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