We have moved at community.getvera.com

Author Topic: find device id by search pattern  (Read 741 times)

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: find device id by search pattern
« Reply #15 on: January 27, 2019, 11:42:15 am »
... Ah.  Posted at (nearly)  the same time.

At least our answers were consistent!
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline DesT

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +5/-1
Re: find device id by search pattern
« Reply #16 on: January 27, 2019, 11:43:00 am »
Thanks guys!

So for the room "name" I can declare some global variable for them? ;)
Vera Edge-UI7/Plus-UI7 (2), DSC Partition (5 ) + Zones Sensors(31), Nest thermostat (1) & Protect Fire/CO (3), GE Sw (8 ), GE Dimr (14), FGMS-001 (2), ZW100 (2), RZCS4 (1), AL-DSC11 (1), Aeon HEM 2nd Edition (1), Aeon SSE (5), YRD220-ZW (1), SONOS (6), MyQ Chamberlain (1)
PINE64/openLuup/ALTUI/Rules

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: find device id by search pattern
« Reply #17 on: January 27, 2019, 11:46:52 am »
I check the link from rigpapa and can't find anything about that...

The definitive link for Lua syntax in general, and patterns in particular is:

http://www.lua.org/manual/5.1/manual.html#5.4.1
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: find device id by search pattern
« Reply #18 on: January 27, 2019, 11:52:24 am »
So for the room "name" I can declare some global variable for them? ;)

Don't do that.  Create a lookup table directly from luup.rooms:

Code: [Select]
local room_no = {}

for i,n in pairs (luup.rooms) do
    room_no[n] = i
end
 
print (pretty(room_no))

gives, for one of my machines:

Code: [Select]
{
["MiOS-35104005"] = 2,
["MiOS-35104860"] = 4,
["MiOS-45101161"] = 3,
["MiOS-88800156"] = 8,
["Vera Room A"] = 6,
["Vera Room B"] = 7,
testing = 5
}

But, this could be included in the search.  The problem with names is that there is no guarantee that they are unique, whereas room numbers definitely are.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline DesT

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +5/-1
Re: find device id by search pattern
« Reply #19 on: January 27, 2019, 11:56:18 am »
this is my output....

Code: [Select]
{
Basement = 13,
["Basement - Bathroom"] = 9,
Bathroom = 23,
["Bedroom - Antoine"] = 6,
["Bedroom - Master"] = 20,
["Bedroom - Mathieu"] = 5,
["Bedroom - Twins"] = 4,
["Dining Room"] = 19,
Downstairs = 30,
Garage = 25,
Hallway = 7,
Home = 2,
["IoT Network"] = 27,
["IoT Presence"] = 28,
["IoT SmartSwitch"] = 29,
Kitchen = 21,
["Living Room"] = 10,
["MiOS-50005737"] = 1,
["Office - Nath"] = 18,
["Office - Sebastien"] = 16,
Outside = 26,
["Outside - Basement"] = 15,
["Outside - Front"] = 12,
["Outside - Garage"] = 14,
["Outside - Patio"] = 11,
["Outside - Shed"] = 24,
Upstairs = 17,
["Upstairs - Bathroom"] = 8,
openLuup = 22
}

So it can be a pain 'cause a bunch of rooms start with the same thing...
Vera Edge-UI7/Plus-UI7 (2), DSC Partition (5 ) + Zones Sensors(31), Nest thermostat (1) & Protect Fire/CO (3), GE Sw (8 ), GE Dimr (14), FGMS-001 (2), ZW100 (2), RZCS4 (1), AL-DSC11 (1), Aeon HEM 2nd Edition (1), Aeon SSE (5), YRD220-ZW (1), SONOS (6), MyQ Chamberlain (1)
PINE64/openLuup/ALTUI/Rules

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: find device id by search pattern
« Reply #20 on: January 27, 2019, 11:58:39 am »
...so what's the problem?  I don't quite understand.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline DesT

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +5/-1
Re: find device id by search pattern
« Reply #21 on: January 27, 2019, 12:00:24 pm »
That I will need to make my search pattern very precise.  For example, just the word Basement, can give me 3 rooms and Outside can give me 6 results.
Vera Edge-UI7/Plus-UI7 (2), DSC Partition (5 ) + Zones Sensors(31), Nest thermostat (1) & Protect Fire/CO (3), GE Sw (8 ), GE Dimr (14), FGMS-001 (2), ZW100 (2), RZCS4 (1), AL-DSC11 (1), Aeon HEM 2nd Edition (1), Aeon SSE (5), YRD220-ZW (1), SONOS (6), MyQ Chamberlain (1)
PINE64/openLuup/ALTUI/Rules

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: find device id by search pattern
« Reply #22 on: January 27, 2019, 12:06:28 pm »
That I will need to make my search pattern very precise.  For example, just the word Basement, can give me 3 rooms and Outside can give me 6 results.

Well, if you're just doing a simple search, then, yes.  I thought you would be using the exact name?  This is, perhaps, what @rigpapa meant by "a whole new can of worms".

Searches can also be made to look for "ends with ..." or such like, too.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline DesT

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +5/-1
Re: find device id by search pattern
« Reply #23 on: January 27, 2019, 12:19:07 pm »
I think I will stick with the room number ;)

thanks a lot rigpapa and AK for this help this morning. ;)
Vera Edge-UI7/Plus-UI7 (2), DSC Partition (5 ) + Zones Sensors(31), Nest thermostat (1) & Protect Fire/CO (3), GE Sw (8 ), GE Dimr (14), FGMS-001 (2), ZW100 (2), RZCS4 (1), AL-DSC11 (1), Aeon HEM 2nd Edition (1), Aeon SSE (5), YRD220-ZW (1), SONOS (6), MyQ Chamberlain (1)
PINE64/openLuup/ALTUI/Rules

Offline DesT

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +5/-1
Re: find device id by search pattern
« Reply #24 on: January 27, 2019, 02:34:17 pm »
rigpapa, AK,

Possible to convert the room parameter into an array to be able to pass more than one room and act like a OR ;)
Vera Edge-UI7/Plus-UI7 (2), DSC Partition (5 ) + Zones Sensors(31), Nest thermostat (1) & Protect Fire/CO (3), GE Sw (8 ), GE Dimr (14), FGMS-001 (2), ZW100 (2), RZCS4 (1), AL-DSC11 (1), Aeon HEM 2nd Edition (1), Aeon SSE (5), YRD220-ZW (1), SONOS (6), MyQ Chamberlain (1)
PINE64/openLuup/ALTUI/Rules

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: find device id by search pattern
« Reply #25 on: January 27, 2019, 05:26:37 pm »
Code: [Select]
function matchDev ( pattern , rooms)
    local wanted = {}
    for _, r in ipairs ((type(rooms) == "table") and rooms or {rooms}) do wanted[r] = r end
    return function(_, last)
        while true do
            local d
            last,d = next( luup.devices, last )
            if not last or (d.description:match( pattern ) and (not rooms or wanted[d.room_num])) then
                return last,d
            end
        end
    end
end

with this you can write things like...

Code: [Select]
for n,d in matchDev "^D-" do ... end

for n,d in matchDev ("^D-", 3) do ... end

for n,d in matchDev ("^D-", {1,3,5}) do ... end

...now go and learn Lua properly so you can do it yourself!   ;)
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline DesT

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +5/-1
Re: find device id by search pattern
« Reply #26 on: January 27, 2019, 06:23:27 pm »
Thanks AK ;)

It's in my todo list of 2019... learn Python from 0% and dig a little more into LUA!
Vera Edge-UI7/Plus-UI7 (2), DSC Partition (5 ) + Zones Sensors(31), Nest thermostat (1) & Protect Fire/CO (3), GE Sw (8 ), GE Dimr (14), FGMS-001 (2), ZW100 (2), RZCS4 (1), AL-DSC11 (1), Aeon HEM 2nd Edition (1), Aeon SSE (5), YRD220-ZW (1), SONOS (6), MyQ Chamberlain (1)
PINE64/openLuup/ALTUI/Rules

Offline DesT

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +5/-1
Re: find device id by search pattern
« Reply #27 on: January 28, 2019, 02:30:33 pm »
AK,

Do you think it's possible that a FOR loop is running too fast for openLuup and that some "command" can be ignored ?

I'm using a FOR loop to "reset" all my smartswitch devices (from the smartswitch plugin) and having some device that are not also reset correctly and it's not always the "same".

Should I add a "wait/sleep" in the loop ?
Vera Edge-UI7/Plus-UI7 (2), DSC Partition (5 ) + Zones Sensors(31), Nest thermostat (1) & Protect Fire/CO (3), GE Sw (8 ), GE Dimr (14), FGMS-001 (2), ZW100 (2), RZCS4 (1), AL-DSC11 (1), Aeon HEM 2nd Edition (1), Aeon SSE (5), YRD220-ZW (1), SONOS (6), MyQ Chamberlain (1)
PINE64/openLuup/ALTUI/Rules

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: find device id by search pattern
« Reply #28 on: January 28, 2019, 02:59:52 pm »
Would need a bit more info on that like the actual code plus some logs.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.