Tentazione
(Tentazione)
January 24, 2019, 6:28pm
1
Hello together,
i’m looking for a way to get all members of a group. Sorted by then name of the member.
i have a group named gTest. The group has 18 member like Switch test01_Dimmer (gtest)
Now i want to get the member sorted in a rule. The rule looks like this
rule "testlight"
when
Item testlight1 changed to ON
then
gtest.members.sortBy["name"].filter( s | s.name.toString.contains("_Dimmer")).forEach [ item |
logInfo("Debug", item.name )
]
end
but… the output looks like
2019-01-24 19:23:25.953 [INFO ] [eclipse.smarthome.model.script.Debug] - test10_Dimmer
2019-01-24 19:23:25.959 [INFO ] [eclipse.smarthome.model.script.Debug] - test11_Dimmer
2019-01-24 19:23:25.964 [INFO ] [eclipse.smarthome.model.script.Debug] - test12_Dimmer
2019-01-24 19:23:25.968 [INFO ] [eclipse.smarthome.model.script.Debug] - test13_Dimmer
2019-01-24 19:23:25.973 [INFO ] [eclipse.smarthome.model.script.Debug] - test14_Dimmer
2019-01-24 19:23:25.977 [INFO ] [eclipse.smarthome.model.script.Debug] - test15_Dimmer
2019-01-24 19:23:25.981 [INFO ] [eclipse.smarthome.model.script.Debug] - test16_Dimmer
2019-01-24 19:23:25.986 [INFO ] [eclipse.smarthome.model.script.Debug] - test17_Dimmer
2019-01-24 19:23:25.990 [INFO ] [eclipse.smarthome.model.script.Debug] - test18_Dimmer
2019-01-24 19:23:25.994 [INFO ] [eclipse.smarthome.model.script.Debug] - test02_Dimmer
2019-01-24 19:23:25.999 [INFO ] [eclipse.smarthome.model.script.Debug] - test03_Dimmer
2019-01-24 19:23:26.003 [INFO ] [eclipse.smarthome.model.script.Debug] - test04_Dimmer
2019-01-24 19:23:26.007 [INFO ] [eclipse.smarthome.model.script.Debug] - test05_Dimmer
2019-01-24 19:23:26.012 [INFO ] [eclipse.smarthome.model.script.Debug] - test06_Dimmer
2019-01-24 19:23:26.017 [INFO ] [eclipse.smarthome.model.script.Debug] - test07_Dimmer
2019-01-24 19:23:26.021 [INFO ] [eclipse.smarthome.model.script.Debug] - test08_Dimmer
2019-01-24 19:23:26.025 [INFO ] [eclipse.smarthome.model.script.Debug] - test09_Dimmer
2019-01-24 19:23:26.030 [INFO ] [eclipse.smarthome.model.script.Debug] - test00_Dimmer
2019-01-24 19:23:26.034 [INFO ] [eclipse.smarthome.model.script.Debug] - test01_Dimmer
How can i get the members sorted by the name of the member?
thx
CDriver
(CDriver)
January 24, 2019, 6:54pm
2
I wonder if the foreach creates another, unsorted copy?
If you printed head instead of foreach do you see 01?
rlkoshak
(Rich Koshak)
January 24, 2019, 7:33pm
3
You definitely want to save the sortby to the last possible step. In this case, just before the forEach.
Tentazione
(Tentazione)
January 24, 2019, 7:49pm
4
What do you mean with “save the sortby”? The items defined in an file.items…and saved…
rlkoshak
(Rich Koshak)
January 24, 2019, 8:07pm
5
Don’t perform the sortBy until the last possible moment, which in this case is right before the forEach but after the filter.
Tentazione
(Tentazione)
January 24, 2019, 8:36pm
6
ok… thx.
i tried now
gtest.members.filter( s | s.name.toString.contains("_Dimmer")).sortBy[“name”].forEach [ item |
logInfo(“Debug”, item.name )
but… looks for me like before
2019-01-24 21:33:46.308 [INFO ] [eclipse.smarthome.model.script.Debug] - test10_Dimmer
2019-01-24 21:33:46.311 [INFO ] [eclipse.smarthome.model.script.Debug] - test11_Dimmer
2019-01-24 21:33:46.315 [INFO ] [eclipse.smarthome.model.script.Debug] - test12_Dimmer
2019-01-24 21:33:46.319 [INFO ] [eclipse.smarthome.model.script.Debug] - test13_Dimmer
2019-01-24 21:33:46.322 [INFO ] [eclipse.smarthome.model.script.Debug] - test14_Dimmer
2019-01-24 21:33:46.326 [INFO ] [eclipse.smarthome.model.script.Debug] - test15_Dimmer
2019-01-24 21:33:46.329 [INFO ] [eclipse.smarthome.model.script.Debug] - test16_Dimmer
2019-01-24 21:33:46.333 [INFO ] [eclipse.smarthome.model.script.Debug] - test17_Dimmer
2019-01-24 21:33:46.336 [INFO ] [eclipse.smarthome.model.script.Debug] - test18_Dimmer
2019-01-24 21:33:46.340 [INFO ] [eclipse.smarthome.model.script.Debug] - test02_Dimmer
2019-01-24 21:33:46.343 [INFO ] [eclipse.smarthome.model.script.Debug] - test03_Dimmer
2019-01-24 21:33:46.347 [INFO ] [eclipse.smarthome.model.script.Debug] - test04_Dimmer
2019-01-24 21:33:46.350 [INFO ] [eclipse.smarthome.model.script.Debug] - test05_Dimmer
2019-01-24 21:33:46.355 [INFO ] [eclipse.smarthome.model.script.Debug] - test06_Dimmer
2019-01-24 21:33:46.358 [INFO ] [eclipse.smarthome.model.script.Debug] - test07_Dimmer
2019-01-24 21:33:46.362 [INFO ] [eclipse.smarthome.model.script.Debug] - test08_Dimmer
2019-01-24 21:33:46.365 [INFO ] [eclipse.smarthome.model.script.Debug] - test09_Dimmer
2019-01-24 21:33:46.369 [INFO ] [eclipse.smarthome.model.script.Debug] - test00_Dimmer
2019-01-24 21:33:46.372 [INFO ] [eclipse.smarthome.model.script.Debug] - test01_Dimmer
rlkoshak
(Rich Koshak)
January 24, 2019, 10:40pm
7
Wait, why do you have name in quotes? It should be .sortBy[ name ]
. You are actually calling .name on each member of the list. With “name” you are doing nothing because “name” will be the same for each member of the list.
Tentazione
(Tentazione)
January 25, 2019, 5:30am
8
Perfect. Now its working. Thanks…