Jump to content
Guides for the Forum Read more... ×
Poradniki na Forum Read more... ×
FIBARO Home Center App 1.0.0 - release Read more... ×
FIBARO Home Center App 1.0.0 - wydanie Read more... ×
AutoFrank

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

Recommended Posts

1 hour ago, Sankotronic said:

 

Hi @andyhud ,

 

  1. Scene should be set to "Automatic"
  2. Default setting for instances is OK
  3. Table should be generated only if some changes where made with devices (added, deleted or reconfigured), best time is after reboot.
  4. That is possible to achieve, but why you need that?

 

Thanks for your reply @Sankotronic good to know.

 

RE Point 3 - I guess it wont ever change by itself, but it was more a passing thought if it seemed a better idea.

Re Point 4 - My theory behind it was it could email you a nice format of the output so you can reference while doing LUA coding. I know @AutoFrank has suggested taking a copy manually to keeping separate (which I totally understand) but I just though about automating that process, thats all.

 

On a side note, I tried to manually add my scenes into the HomeTable by adding them manually as per below but in the Debug window it fails.

 

Please login or register to see this code.

I had assumed that if my scenes had spaces in their names but I wrapped it in quotes (") then it would be ok, but I dont think it is?

 

I get below.

 

any thoughts appreciated as ever

 

Thanks

 

Andy

 

 

 

 

 

Please login or register to see this attachment.

Edited by andyhud

Share this post


Link to post
Share on other sites

Here is example of HomeTable:

Please login or register to see this code.

 

Here is example how to use above table:

Please login or register to see this code.

If you use quotes in table then you get different results and I don't recommend it because it complicates programming. Also spaces can't be used in table as a part of the value, but you can use underscore for that like in above example.

 

Edited by Sankotronic

Share this post


Link to post
Share on other sites

It's possible to use spaces in table keys. It's a bit verbose but some people like the 'HomeTable[<key>]' style instead of the dot notation.

Please login or register to see this code.

 

  • Like 2

Share this post


Link to post
Share on other sites

Thankyou @Sankotronic and @jgab

 

I ended up renaming everything in my HC2 to camelCase with no spaces and now it works ok and the scenese are being recorded in the hometable

 

I saw a post or two about auto populating the hometable with scenes, but I decided to stick to adding the scenes manually at the top. It works better for me

 

Cheers

 

Andy

 

Share this post


Link to post
Share on other sites

Hi all

I created below group in the standard hometable lua scene:


LightsDelayedOffAtNight = {
    Tuinpad=208,Tuinlampen=207,MainTuinLampen=205, Tuinlampen_Schakelaa=210, MainTuinSchakelaar=209
    },

 

I noticed that the final table is created in a random order of the above devices. It's not created in the above order, neither alphabeltical or numericable.


This is the output of the json decode after creating the table:

"LightsDelayedOffAtNight": {
    "MainTuinLampen": 205,
    "Tuinpad": 208,
    "Tuinlampen": 207,
    "Tuinlampen_Schakelaa": 210,
    "MainTuinSchakelaar": 209
  }

 

What's the solution in case I want to loop through these devices in a specific order (not based upon ID neither alphabetical)?

Share this post


Link to post
Share on other sites
40 minutes ago, wpeeters said:

What's the solution in case I want to loop through these devices in a specific order (not based upon ID neither alphabetical)?

The order of a key/value table is always undefined - think of it as a unordered key/value set

Share this post


Link to post
Share on other sites

@jgab, ok I see.
Isn't there a way to add an additional field (integer) in order to sort while or after decoding?

 

Share this post


Link to post
Share on other sites
6 minutes ago, wpeeters said:

@jgab, ok I see.
Isn't there a way to add an additional field (integer) in order to sort while or after decoding?

 

 

If you want to treat those devices differently per device, I should not put them in the same group.

 

Maybe you can share some details what you want to do with the devices grouped here?

 

 

Share this post


Link to post
Share on other sites
Posted (edited)

@jgab,

Ok, here comes the background.
For my garden lights i use 3 fibaro relais each connected to a 'real' relais (I don't know how say that in english - it's a relais which is handling the load of the lights while the fibaro relais is only triggering the relais) and 2 switches.
Already since the beginning, I have very strange electrical behavior if I switch the lights off using the switch (all 3 circuits the same time), the lights dare to switch on again. Nobody could give me a solution already.
I think @petergebruers ever mentioned a hint but I don't remember.

Nevertheless, it's already working for years like this. In order to solve this, I added a double check in the lua scene and check for the load. If the wattage is still < 0 after switching off, I switch them off again (after some delay).

Now I want to rewrite the scene and acutally noticed that while switching off the lights, one by one instead of turning off the switch that it is working better.
But only if done in a specific order. That's the reason for my question.

But I think I was able to find a solution that will work for me:

 

--Tuinpad=208,Tuinlampen=207,MainTuinLampen=205, Tuinlampen_Schakelaa=210, MainTuinSchakelaar=209
      LightsDelayedOffAtNight = {
    [1]=208,[2]=207,[3]=205, [4]=210, [5]=209
    },


With ipairs, the result will always be in the same order. If created on the hometable, I can just document which ID is the equivalent for which device and I still have the advantage to maintain those in only 1 scene (hometable).
So, I can live with this workaround.

 

Edit : this is actually how I want to loop through it:

function TurnOffLightsDelayed() 
      info("white", "--- Start looping through devices to turn off with delay in between ...")
    for k,i in ipairs(jT.LightsDelayedOffAtNight) do -- loop through all devices in the section of the HomeTable.
          log("grey", k)     
            if (( tonumber(fibaro:getValue(i, "value")) > 0 )) then -- if the device is on then ....
              log("orange", "The device "..k.." is on, start switching it off.")
            fibaro:call(i, "turnOff"); -- turn the device off
              fibaro:sleep(1500)
              end
      end -- for k,i in pairs(jT.LightsOffAtNight)
end -- function TurnOffLightsDelayed

Edited by wpeeters

Share this post


Link to post
Share on other sites
Posted (edited)
17 minutes ago, wpeeters said:

@jgab,

Ok, here comes the background.
For my garden lights i use 3 fibaro relais each connected to a 'real' relais (I don't know how say that in english - it's a relais which is handling the load of the lights while the fibaro relais is only triggering the relais) and 2 switches.
Already since the beginning, I have very strange electrical behavior if I switch the lights off using the switch (all 3 circuits the same time), the lights dare to switch on again. Nobody could give me a solution already.
I think @petergebruers ever mentioned a hint but I don't remember.

Nevertheless, it's already working for years like this. In order to solve this, I added a double check in the lua scene and check for the load. If the wattage is still < 0 after switching off, I switch them off again (after some delay).

Now I want to rewrite the scene and acutally noticed that while switching off the lights, one by one instead of turning off the switch that it is working better.
But only if done in a specific order. That's the reason for my question.

But I think I was able to find a solution that will work for me:

 

--Tuinpad=208,Tuinlampen=207,MainTuinLampen=205, Tuinlampen_Schakelaa=210, MainTuinSchakelaar=209
      LightsDelayedOffAtNight = {
    [1]=208,[2]=207,[3]=205, [4]=210, [5]=209
    },


With ipairs, the result will always be in the same order. If created on the hometable, I can just document which ID is the equivalent for which device and I still have the advantage to maintain those in only 1 scene (hometable).
So, I can live with this workaround.

Yes, that's probably the easiest.

Btw,   {[1]=208,[2]=207,[3]=205, [4]=210, [5]=209} is the same as {208,207,205,210,209}

 

..or alternatively as below, which is a bit easier to read if you want to change the order

Please login or register to see this code.

 

Edited by jgab

Share this post


Link to post
Share on other sites

The issue with your solution is that when the device id changes, the implementation breaks. I understand the idea of the hometable is based to get rid of dealing with device ids.

 

Why is it necessary to have a table to cycle through? Another suggestion is to call out the device names explicitly in the scene in the correct order, like

 

Please login or register to see this code.

In the above example I assumed jT is the home table. In absence of a room name I just used "Room".

Share this post


Link to post
Share on other sites

@jgab , ok thanks. I'll see what's best to use.

@jayrock, You never can't get rid of the device id's. I prefer to create those kind of groups of devices in hometable so I can manage them one place.
In case I add one additional device, I only need to change the hometable scene.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×