Jump to content

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


Recommended Posts

1 minute ago, codowd said:

 

I can confirm that the code in the first post will not work if the name of any device or room contains an apostrophe (') even though it encloses the apostrophe in quotes (").  You can see this if you just type the following line into the HC2 LUA editor:

 

local jT = '{"Boy's Room"}'

 

The syntax colour changes after the second apostrophe, indicating the quote finishes there, understandably.

 

Anyone know how to overcome this in LUA?

 

@codowd

Thanks for confirming.

 

About 9 months ago I went through my HC2 and worked to simplify all the names I used for scenes names, vd  names, device names as well  as any variables or constants I use within the code.  I got rid of all non-alphanumeric characters so at this stage I just use A...Z and 0...9. I also use camelcase (outsideLight) or an underscore (kitchen_Motion) to make some things easier to read. Since I did this I have eliminated all these types of issues. It was a bit of work but well worth it for me.

 

Over the last week or so I also went through my scenes and vd ( ~ 60 in total) and removed all excess code (debug lines I used to troubleshoot issues and a event logger I added and generally cleaned up and simplified the code and have found that the trigger events happen much faster and the system is using far less resources.

 

 

 

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

@riemers

Sorry I have edited my post.

 

@AutoFrank

Thanks, good to know - but that's not really an acceptable option for me. For other users (read WAF) it pays to have the names of rooms and devices in friendly format.  Plus I have no control over what my daughter calls her iPhone (also a Fibaro HC2 device).

 

@All

I have edited my previous post to include the code changes that *should* work.  However my iDevices still come through with the apostrophes intact... the "gsub" call doesn't seem to work. The rogue character is "’", in an iOs device name, which is an alternative apostrophe character of some kind.

 

Strikes me, there is no control over the names of iOs devices from HC2, and all sorts of illegal characters could possible be added.  Anyway, for me an additional nested gsub now has the code working.

Edited by codowd
Link to post
Share on other sites
1 minute ago, codowd said:

@riemers

Sorry I have edited my post.

 

@AutoFrank

Thanks, good to know - but that's not really an acceptable option for me. For other users (read WAF) it pays to have the names of rooms and devices in friendly format.  Plus I have no control over what my daughter calls her iPhone (also a Fibaro HC2 device).

 

@All

I have edited my previous post to include the code changes that *should* work.  However my iDevices still come through with the apostrophes intact... the "gsub" call doesn't seem to work.

 

Hi @codowd

 

Another option may be to use @ReneNL code to generate an initial table and then sanitize it to what will work. This way you don't need to change the room , etc names from what you want. You could then put this table into a scene and keep a copy in your source code control. The scene could %%autostart on a reboot. (btw, I don't reload the table on every reboot, I check 5 or 6 items in the table and this give me a sense if the table is corrupt and if it's okay I don't reload). I also don't use the Save button in the variables panel and this also helps keep the variables and their contents intact. I also find that having a copy in Notepad++ is that I can reference it when I am creating new scenes or vd is very convenient

 --This has been my approach and has worked well for me

 

As I said earlier in the post ReneNL code is fantastic for generating the table for the very first pass but I'm not sure it the best approach to keep the table aligned for reboots. I think you could find it very onerous in trying to manage all this through smart naming/character substitution of everything in your HC2. In my case I also don't need all the data that is generated as many of my scenes and vd are triggered automatically by conditions and not manually (by either myself or other code segments)  and don't need to be in my HomeTable. The hometable provides a nice layer of abstraction and even though my primary goal for my system is close to full automation there are something I don't want automated or are not worth the effort.

 

I know I'm not providing a solution and I'm not suggesting that you don't take this approach but it might be taking a moment and seeing if this will really reap the benefits you want.

I can take a look this evening and see if I can solve the substitution issue but be warned :-) this is not my specialty...

 

-f

 

 

 

 

 

Link to post
Share on other sites

Thanks for your reply. You are right in what you say.  I think the scene would need a function called (say) "TrimIllegals" which cotains the gsub calls and this is getting to be too much work.

 

BUT what I wanted to use the code for was to make easier the task of (say) switching off all the lights downstairs, or linking motion sensors with lights in a given room.  The next step was obviously to loop through each room and make the associations, if that is possible.

 

Otherwise I can see I will simply have to code every little thing in LUA - that is not why I bought a HC2!!  I am happy to LUA startup code but want to block scene the majority of my activated scenes.  If I want to code everything I'll use OpenHAB!  Much cheaper...

 

Link to post
Share on other sites
41 minutes ago, codowd said:

BUT what I wanted to use the code for was to make easier the task of (say) switching off all the lights downstairs, or linking motion sensors with lights in a given room.  The next step was obviously to loop through each room and make the associations, if that is possible.

 

Post 28 on this topic has some discussion on this

Personally I created a VD that has multiple lighting sequences (All Lights Up off, All Lamps Up off, All Lights Down off, All Lamps Down Off, All Garage Lights off, All Outside Lights off, All Security Lights On,) I have a similar vd for music ( All Sonos Up Off, All Sonos down off) ), TTS announcements, AV equipment and some others

Once I had my hometable sorted it took me about 5 mins to create each vd

 

-- I then just use pressbutton on the appropriate vd  within the relevent scene/VD to execute the required sequence such as my good morning, good night, leaving home, kids to bed, etc. sequence

 

 

Link to post
Share on other sites
On 1/18/2017 at 2:57 PM, riemers said:

bw Going bit offtopic, but might i suggest you use docker for that. Some nas systems include docker too (synology) from the gui. Using docker is easy and simple to give to someone else too, work on Pi3 too. For node-sonos-api there is a docker image https://github.com/chrisns/docker-node-sonos-http-api saves you the hassle of installing all dependency's, assuming you have some knowledge with linux.

 

Hi @riemers

I hope you dont mind but I added your docker information above to the frst post of the sonos api thread at https://forum.fibaro.com/index.php?/topic/21797-tutorial-alternative-sonos-vd-using-node-sonos-api/&page=1

Link to post
Share on other sites

@codowd, next to the suggestion of AutoFrank two posts up, you also might want to check on my post 53, see below. Here I also added a changed script where the HomeTable structure is section-->devicetype-->deviceName-->deviceID. This allows you to e.g. select all lights in a section in one go (deviceIDs = jT.FirstFloor.dimmer).

Best, Rene.

Link to post
Share on other sites
On ‎1‎/‎24‎/‎2017 at 10:34 AM, codowd said:

@riemers

Sorry I have edited my post.

 

@AutoFrank

Thanks, good to know - but that's not really an acceptable option for me. For other users (read WAF) it pays to have the names of rooms and devices in friendly format.  Plus I have no control over what my daughter calls her iPhone (also a Fibaro HC2 device).

 

@All

I have edited my previous post to include the code changes that *should* work.  However my iDevices still come through with the apostrophes intact... the "gsub" call doesn't seem to work. The rogue character is "’", in an iOs device name, which is an alternative apostrophe character of some kind.

 

Strikes me, there is no control over the names of iOs devices from HC2, and all sorts of illegal characters could possible be added.  Anyway, for me an additional nested gsub now has the code working.

 @codowd, One other suggestion is to automatically change/remove all non-alphanumeric characters from the devicenames and roomnames in the HomeTable. That can easily be done by changing the line

 

deviceName=string.gsub(fibaro:getName(i), "%s+", "") -- eliminate spaces in devicename

to

deviceName=string.gsub(fibaro:getName(i), "%W", "") -- eliminate all non-alphanumeric characters in devicename

Same for the line further down in the script for the rooms. Change

roomname=string.gsub(fibaro:getRoomName(roomID), "%s+", "") -- eliminate spaces in roomname

to

roomname=string.gsub(fibaro:getRoomName(roomID), "%W", "") -- eliminate all non-alphanumeric characters in roomname

Best, Rene.

Link to post
Share on other sites
17 hours ago, ReneNL said:

 @codowd, One other suggestion is to automatically change/remove all non-alphanumeric characters from the devicenames and roomnames in the HomeTable. That can easily be done by changing the line

 

deviceName=string.gsub(fibaro:getName(i), "%s+", "") -- eliminate spaces in devicename

to

deviceName=string.gsub(fibaro:getName(i), "%W", "") -- eliminate all non-alphanumeric characters in devicename

Same for the line further down in the script for the rooms. Change

roomname=string.gsub(fibaro:getRoomName(roomID), "%s+", "") -- eliminate spaces in roomname

to

roomname=string.gsub(fibaro:getRoomName(roomID), "%W", "") -- eliminate all non-alphanumeric characters in roomname

Best, Rene.

Thanks, that is exactly what is required!  It gives me valid json and I can read the jHomeTbale variables successfully (i.e log(iOS.MyiPad2) = 288 for example).

 

Edited by codowd
Link to post
Share on other sites

Cool, good to hear that this worked for you! 

 

@AutoFrank, we could add this line to the script, maybe out-comment it so people can select as needed.

 

Rene.

Link to post
Share on other sites
21 minutes ago, ReneNL said:

Cool, good to hear that this worked for you! 

 

@AutoFrank, we could add this line to the script, maybe out-comment it so people can select as needed.

 

Rene.

 

All & @ReneNL

script in first post updated include these two options to remove all non-alphanumeric characters from all devicename and roomname

un-comment as required at lines 36 and 57 respectively.

 

-f

 

 

 

Link to post
Share on other sites
jHomeTable = '{"BottomStairs":{"MotionR":250,"TempR":251,"LightR":255,"EntranceDoor":181},"iOS":{"iPhone":67,"iPad2":288,"iPhone7":304,"iPadAir":17}}'
jsonHome = json.decode(jHomeTable)				-- ENCODES THE DATA IN JSON FORMAT BEFORE STORING
log(jsonHome.iOS.iPad2)							-- DISPLAY ONE VARIALE

log('HomeTable = '..jHomeTable)
fibaro:setGlobal("HomeTable", jHomeTable) 		-- THIS STORES THE DATA IN THE VARIABLE

Can anyone see what is wrong with the setglobal statement in this code?

 

The json is correct and the log statement produces the right value (288).. But the global is still not created...

Link to post
Share on other sites
22 minutes ago, AutoFrank said:

 

All & @ReneNL

script in first post updated include these two options to remove all non-alphanumeric characters from all devicename and roomname

un-comment as required at lines 36 and 57 respectively.

 

-f

 

 

 

I don't think the %W option deletes any additional characters except of course the problem ones, so it can probably be used instead of the %s+ option.

Link to post
Share on other sites
10 minutes ago, codowd said:
jHomeTable = '{"BottomStairs":{"MotionR":250,"TempR":251,"LightR":255,"EntranceDoor":181},"iOS":{"iPhone":67,"iPad2":288,"iPhone7":304,"iPadAir":17}}'
jsonHome = json.decode(jHomeTable)				-- ENCODES THE DATA IN JSON FORMAT BEFORE STORING
log(jsonHome.iOS.iPad2)							-- DISPLAY ONE VARIALE

log('HomeTable = '..jHomeTable)
fibaro:setGlobal("HomeTable", jHomeTable) 		-- THIS STORES THE DATA IN THE VARIABLE

Can anyone see what is wrong with the setglobal statement in this code?

 

The json is correct and the log statement produces the right value (288).. But the global is still not created...

 

HI @codowd

 

There would appear to be a few small things mixed up

Better to save first and then read back later

Try this - I haven't tested it but it should work

 

jsonHome = '{"BottomStairs":{"MotionR":250,"TempR":251,"LightR":255,"EntranceDoor":181},"iOS":{"iPhone":67,"iPad2":288,"iPhone7":304,"iPadAir":17}}'

fibaro:log("HomeTable = "..jsonHome..)        -- Display the string above

jHomeTable = json.encode(jsonHome)				    -- ENCODES THE DATA IN JSON FORMAT BEFORE STORING
fibaro:setGlobal("HomeTable", jHomeTable) 		-- THIS STORES THE DATA IN THE VARIABLE

-- Read back
local jT = json.decode(fibaro:getGlobalValue("HomeTable")) 	-- REFERENCE TO DECODE TABLE
fibaro:log("Read variable from table: "..jT.iOS.iPad2..)	  -- Read back one variable

 

Link to post
Share on other sites
49 minutes ago, AutoFrank said:

 

HI @codowd

 

There would appear to be a few small things mixed up

Better to save first and then read back later

Try this - I haven't tested it but it should work

 

jsonHome = '{"BottomStairs":{"MotionR":250,"TempR":251,"LightR":255,"EntranceDoor":181},"iOS":{"iPhone":67,"iPad2":288,"iPhone7":304,"iPadAir":17}}'

fibaro:log("HomeTable = "..jsonHome..)        -- Display the string above

jHomeTable = json.encode(jsonHome)				    -- ENCODES THE DATA IN JSON FORMAT BEFORE STORING
fibaro:setGlobal("HomeTable", jHomeTable) 		-- THIS STORES THE DATA IN THE VARIABLE

-- Read back
local jT = json.decode(fibaro:getGlobalValue("HomeTable")) 	-- REFERENCE TO DECODE TABLE
fibaro:log("Read variable from table: "..jT.iOS.iPad2..)	  -- Read back one variable

 

 

Yes I know I probably am being a klutz with this JSON stuff, but I don't understand how your code above works.  I assumed that what is stored in the global is a string representation of the data structure, which needs to be decoded (back to a data structure) on read and encoded back to a string on write.

 

That seems to be the way the original code (in the first post) works.  jsonHome (and jT) are the data structures. jHomeTable is the string that's read and written. 

 

But in the above code jsonHome refers to a string, not a JSON structure. But if a string then the log statement log(jsonHome.iOS.iPad2) wouldn't work (yet it does). Is LUA creating a data structure on the fly?

 

Note: I cannot successfully setglobal using either my code or yours, so that is the reason I am playing around with all the options :/.

Edited by codowd
Link to post
Share on other sites
21 minutes ago, codowd said:

 

Yes I know I probably am being a klutz with this JSON stuff, but I don't understand how your code above works.  I assumed that what is stored in the global is a string representation of the data structure, which needs to be decoded (back to a data structure) on read and encoded back to a string on write.

 

That seems to be the way the original code (in the first post) works.  jsonHome (and jT) are the data structures. jHomeTable is the string that's read and written. 

 

But in the above code jsonHome refers to a string, not a JSON structure. But if a string then the log statement log(jsonHome.iOS.iPad2) wouldn't work (yet it does). Is LUA creating a data structure on the fly?

 

Note: I cannot successfully setglobal using either my code or yours, so that is the reason I am playing around with all the options :/.

 

Hi @codowd

 

No worries and I'm still reasonable new to working with json as well. :-) and still get a lot wrong...

You're correct in when you said that your code was similar to what I sent back. I just changed it to what I use as it's a bit easier for me to understand.

The main issue I saw was that you weren't encoding the data before you saved it and at line 2 you were trying to decode something that was not encoded.

 

I'll step through it with my understanding and apologies if this is not what you asked or if i have simplified it too much

 

-- This assigns the string, (which has an array structure) to the variable jsoneHome 
jsonHome = '{"BottomStairs":{"MotionR":250,"TempR":251,"LightR":255,"EntranceDoor":181},"iOS":{"iPhone":67,"iPad2":288,"iPhone7":304,"iPadAir":17}}'

-- this just displays the jsonHome string (not really needed)
fibaro:log("HomeTable = "..jsonHome..) 

-- This encodes the string jsonHome in json format and assigns it as the variable jHomeTable 
jHomeTable = json.encode(jsonHome)

-- This takes the json encoded table/array called jHomeTable and stores it in the global variable HomeTable
fibaro:setGlobal("HomeTable", jHomeTable) 

-- **At this stage you have a json encoded string array that is stored in a global variable**

-- This decodes what is stored in the global value that is in a json format and assins it to jT
local jT = json.decode(fibaro:getGlobalValue("HomeTable"))

-- jT then allows you to navigate through the table/array structure and read back part of it
fibaro:log("Read variable from table: "..jT.iOS.iPad2..)

Hope this help a bit

-f

 

 

 

 

 

 

 

 

 

 

 

 

Link to post
Share on other sites

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 Control settings page on HC2).

ID's are available using the following format:

HC2["zwave devices"]["room name"]["device name"]

HC2["virtual devices"]["room name"]["device name"]

HC2["mobile devices"]["device name"]

HC2["scenes"]["room name"]["scene name"]

HC2["users"]["user name"]

--[[
%% autostart
%% properties
%% events
%% globals
--]]

local global = "HC2" -- set to name of global variable to store table
local debug = false -- Debug Output: true = enabled / false = disabled

-- DO NOT EDIT BELOW THIS LINE
function log(msg)
  if debug and msg then fibaro:debug(tostring(msg)) end
end

local http = {
  client = net.HTTPClient(),
  baseUrl = "http://127.0.0.1:11111/api/",
}

function http:new (parent)
  self.parent = parent
  return self
end

function http:failure (params)
  log("Failed loading " .. tostring(params.category) .. " (" .. tostring(params.error) .. ")")
end

function http:success (params)
  if params.response.status == 200 then
    log(params.category .. " information retreived")
    for n, data in pairs(json.decode(params.response.data)) do self.parent:add(params.category, data) end
    self.parent:save(params.category)
  else
    self:failure({category = params.category, error = params.response.status})
  end     
end

function http:get (category)
  if type(category) == "table" then
    for k, v in pairs(category) do self:get(v) end
  elseif category then -- validate category
    log("\r\nLOADING " .. category:upper() .. "...")
    self.parent.complete[category] = false
    self.client:request(
      self.baseUrl .. category,
      {
        success = function(status)
          self:success({category = category, response = status})
        end,
        error = function(error)
          self:failure({category = category, error = error})
        end
      }
    )
  end
end

local this = {
  [global] = {}, -- global variable name to store table
  ["complete"] = {},
}

function this:http ()
  return http:new(self)
end

function this:save (category)
  fibaro:debug(category .. " information collated")
  self.complete[category] = nil
  for k, v in pairs(self.complete) do return nil end -- items still waiting completion
  
  fibaro:setGlobal("CreateGlobal", global) -- optional scene trigger to create new global
  fibaro:setGlobal(global, type(self[global]) == "table" and json.encode(self[global]) or self[global])
  if not pcall(
    function()
      local test = json.decode(fibaro:getGlobalValue(global)) -- retrieve saved global
      if type(test) ~= "table" then error() end -- check global is a table
 
      log("\r\nGLOBAL " .. global .. " TABLE CONTENTS")
      log(json.encode(test))      
      fibaro:debug("Global ID's table '" .. global .. "' has been stored successfully")
    end
  ) then
    fibaro:debug("Failed to create global table :(")
  end
end

function this:add (category, data)
  if category == "users" or category:match("mobile") then
    self[global][category] = self[global][category] or {} -- intialise category table
    self[global][category][category:match("mobile") and data.name or data.name:lower()] = data.id
  elseif category == "scenes" or category:match("devices") then
    local room = (data.room or fibaro:getRoomName(data.roomID) and fibaro:getRoomName(data.roomID) or "unassigned"):lower() -- Fibaro bug workaround
    
    self[global][category] = self[global][category] or {} -- intialise category table
    self[global][category][room] = self[global][category][room] or {} -- initialise room table
    self[global][category][room][data.name:lower()] = data.id
  end
end

-- LOAD SCENES & USERS
this:http():get({"scenes", "users"})

-- LOAD DEVICES
local devices = {
  ["mobile devices"] = fibaro:getDevicesId(
    {
      enabled = true,
      type = "iOS_device"
    }
  ),
  ["virtual devices"] = fibaro:getDevicesId(
    {
      enabled = true,
      type = "virtual_device"
    }
  ),
  ["zwave devices"] = fibaro:getDevicesId(
    {
      visible = true,
      enabled = true,
      interfaces = {
        "zwave",
      },
    }
  ),
}

log("\r\nLOADING DEVICES...")
for category, list in pairs(devices) do
  log(category:upper() .. " ID's = " .. json.encode(list))
  this.complete[category] = false
  for n, id in ipairs(list) do
    this:add(
      category,
      {
        id = id,
        name = fibaro:getName(id),
        room = fibaro:getRoomNameByDeviceID(id),
      }
    )
  end
  this:save(category)
end

 

hc2-database.png

Edited by seiq
Pretty database icon for scene ;)
  • Like 2
Link to post
Share on other sites
On 1/19/2017 at 9:24 PM, Momos said:

Rene, I think this is exactly what i was looking for. Thank you.  Will try it and confirm in about 10 days when i get back home.

 

 

Hi Again Rene,

 

Just wanted to share the feedback. I tweaked it a little bit and now it does all:) adds devices per rooms and per sections/devices type like i wanted. I added also a check at the end to verify that it works properly.

 

Thank you again :)

 

--[[
%% properties
%% events
%% globals
--]]
local debug = true --set to false to stop debug messages
local sectionMapping = {[4]="Parter", [5]="Etaj", [6]="Curte", [372]="Repeaters", [373]="RemoteControl",[374]="ManualMode"}
-- HOME TABLE FOR ANYTHING IN ADDITION TO DEVICES, VDs, iOS DEVICES
-- EDIT TO YOUR NEEDS OR KEEP BLANK: jsonHome = {}
jsonHome = {}
-- NO USER EDITS NEEDED BELOW
local function log(str) if debug then fibaro:debug(str); end; end 
devices=fibaro:getDevicesId({visible = true, enabled = true}) -- get list of all visible and enabled devices
log("Fill hometable with "..#devices.." devices")
-- FILL THE HOMETABLE WITH ALL VDs, DEVICES AND iOS DEVICES
for k,i in ipairs(devices) do
    deviceName=string.gsub(fibaro:getName(i), "%s+", "") -- eliminate spaces in devicename
    if fibaro:getRoomID(i) ~= 0 then -- only devices that are allocated to a room as otherwise there is no section  
        sectionID = fibaro:getSectionID(i)
        sectionName = sectionMapping[sectionID]
        deviceType = fibaro:getType(i)
     if     deviceType == "com.fibaro.FGRM222" then
        if jsonHome[sectionName] == nil then -- Add section to the table
            jsonHome[sectionName] = {}  
        end
        jsonHome[sectionName][deviceName]=i
        log("i="..i..", name="..deviceName..", section="..sectionName)
     end
    end
    
    if fibaro:getType(i) == "virtual_device" then -- Add VDs to Hometable
        if jsonHome.VD == nil then -- Add VD to the table
            jsonHome.VD = {}  
        end
        jsonHome.VD[deviceName]=i
        log("i="..i..", type="..fibaro:getType(i)..", device="..deviceName)
    elseif fibaro:getType(i) == "iOS_device" then -- Add iOS devices to Hometable
        if jsonHome.iOS == nil then -- Add iOS devices to the table
            jsonHome.iOS = {}  
        end
        jsonHome.iOS[deviceName]=i
        log("i="..i..", type="..fibaro:getType(i)..", device="..deviceName)
    elseif fibaro:getType(i) == "com.fibaro.FGRM222" then -- Add Roller Shutters to Hometable
        if jsonHome.BlindsAll == nil then -- Add Roller Shutters devices to the table
            jsonHome.BlindsAll = {}  
        end
        jsonHome.BlindsAll[deviceName]=i
        log("i="..i..", type="..fibaro:getType(i)..", device="..deviceName)
    else -- Add all other devices to the table
        roomID = fibaro:getRoomID(i)
        if roomID == 0 then
            roomname = "Unallocated"
        else
            roomname=string.gsub(fibaro:getRoomName(roomID), "%s+", "") -- eliminate spaces in roomname
        end
        if jsonHome[roomname] == nil then -- Add room to the table
            jsonHome[roomname] = {}  
        end
        jsonHome[roomname][deviceName]=i
        log("i="..i..", type="..fibaro:getType(i)..", device="..deviceName..", room="..roomname)
    end
end

jHomeTable = json.encode(jsonHome)                -- ENCODES THE DATA IN JSON FORMAT BEFORE STORING
fibaro:setGlobal("HomeTable", jHomeTable)         -- THIS STORES THE DATA IN THE VARIABLE
log("global jTable created:")                    -- STANDARD DEBUG LINE TO DISPLAY A MESSAGE
log(jHomeTable)
-- I then like to read back a entry from the table to show that the table didnt get corrupt in the process.
local jT = json.decode(fibaro:getGlobalValue("HomeTable"))     -- REFERENCE TO DECODE TABLE
xx = 0
for k,i in pairs(jT.BlindsAll) do
fibaro:debug(k.."="..i.."  ")
xx = xx + 1
end 
fibaro:debug("There are "..xx.." blinds. ")
xx = 0
for k,i in pairs(jT.Parter) do
--fibaro:debug(k.."="..i.."  ")
xx = xx + 1
end 
fibaro:debug("There are "..xx.." blinds in Parter. ")
xx = 0
for k,i in pairs(jT.Etaj) do
--fibaro:debug(k.."="..i.."  ")
xx = xx + 1
end 
fibaro:debug("There are "..xx.." blinds in Etaj. ")

 

and the debug obtained through adding the same devices but in 2 different ways in subtables - one subtable with all the devices of one kind, and another two subtables with all the devices of the same kind but per SECTION :) 

 

Capture.JPG

Edited by Momos
Link to post
Share on other sites

Another small note which relate to international characters in device and scene names. 

For sure, you can remove them all, but the names will then be a bit hard to remember. I prefer a solution like this for example:

-- FILL THE HOMETABLE WITH ALL VDs, DEVICES AND iOS DEVICES
function string.replace(str, subsTab)
  local outStr = str
  for k,v in pairs(subsTab) do
    outStr=string.gsub(outStr,tostring(k),tostring(v))
  end
  return(outStr)
end
local replacementTab = {["å"]="a",["ä"]="a",["ö"]="o"}
for k,i in ipairs(devices) do
    deviceName=string.gsub(fibaro:getName(i), "%s+", "") -- eliminate spaces in devicename
    deviceName=string.replace(deviceName,replacementTab)

 

Of course the 'replacementTab' needs to be populated with what is appropriate for the language. The above example is what I use for Swedish.

I prefer using "Rorelsetvattstugan" rather than "Rrelsetvttstugan" which I will never get right.

 

 

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