AnDuR
(Andrea )
November 30, 2021, 3:47pm
1
Hello,
I’ve a problem but I cannot solve alone.
I have some items in a group, called
Item1
Item1_TimerOn
Item1_TimerOff
I would like to know which is calling. I use this
val oggettochiamata = triggeringItem
val oggettoprincipale = oggettochiamata.name.split("_Timer")
but if Item1 is calling, I receive this error:
[ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘gestione_timer_stufa1’ failed: Index 1 out of bounds for length 1
How can I change the behavior and check if “_Timer” is into the name of calling item or not without having an error?
Thanks to all
rossko57
(Rossko57)
November 30, 2021, 4:06pm
2
I suppose you could use string method .contains("xx")
in an if() test.
EDIT - maybe its .includes("xx")
depending on Java version.
AnDuR
(Andrea )
November 30, 2021, 6:12pm
3
Thanks for your info. You give me the right way…
After many errors, I found the right way for my java is:
.indexOf("String") > 0
into if statement.
if (oggettochiamata.name.indexOf("Timer") > 0)
btw… other than triggeringItem, there is a way to extract the name of the group calling?
If I have group1
with item1, item1_TimerOn, item1_TimerOff
and group2
with item2, item2_TimerOn
and both group fire the rule, how can I find the right group assignment?
Regards
rossko57
(Rossko57)
November 30, 2021, 8:07pm
4
To find group(s) that an Item is a member of -
So after several testing now, here is the conclusion:
if i.memberOf( sceneGroup) { FAILS
sceneGroup.members.filter[ j | j.name == i.name].size > 0 SLOW
if (i.getGroupNames.contains(sceneGroup.name) { FAST
@5iver thanks for the tip, however you had a small typo:
if (i.getGroupNames.contains("sceneGroup") {
should be
if (i.getGroupNames.contains(sceneGroup.name) {
@rlkoshak maybe you can add this method to your orginal post of ho…