Lightcontrol

Finally got around to start working on this.
Apparently there is something I am failing to understand when it comes to groups.
In a rule where I have a “Member of gIndoorLight” trigger the group exists and work.
When I try to do gIndoorLight.members.forEach in a cron triggered rule it cannot be found and I get an error saying “The name ‘gIndoorLight’ cannot be resolved to an item or type”.
What am I missing here?

Thanks

Is the rule written in the rules DSL or scripted automation?

Rules DSL.

Please post your rule.

rule "Automatic"
when
        Time cron "0 * * ? * * *"
then
        logWarn("light", "Automatic executed")
        gIndoorLight?.members.forEach[light |
                var lightName = light.name
                logWarn("light", "Test: " + lightName)
        ]
end

rule "Updated"
when
        Member of gIndoorLight received update
then
        val lightName = triggeringItem.name.split("_").get(0)
        logWarn("light", "Item updated " + lightName + " state: " + triggeringItem.state)
        val levelFromRule = autoLevel.get(lightName)
        if(levelFromRule != null) {
                logWarn("light", "map found: " + levelFromRule)
                manualDelay.put(lightName,  60) //Delay for 60 minutes
        }

end

Please How to use code fences when posting code.

Does this error happen on loading of the .rules file, when the Rule runs for the first time only, or when the Rule runs every time?

Sorry, posted from phone and missed that. Will edit.

Happens every time the rule runs.

Just to eliminate one error that crops up for some users, restart OH. Sometimes, especially immediately after an update, OH fails to recognize a bunch of Items until the next restart. It seems unlikely that that is the case but we can easily rule it out with a restart.

Watch openhab.log for any errors and report them here.

I don’t see anything obviously wrong with the Rule, assuming your “Updated” Rule actually triggers and runs.

The group is created in the UI, so not using an Item file.
So my guess was that the groups are not created because of the way that cron runs or something.

Will restart, but have done that a bunch of times.

This is when automatic is run, no relevant warnings before this:

2019-12-11 21:20:06.842 [WARN ] [eclipse.smarthome.model.script.light] - System started
2019-12-11 21:20:07.625 [WARN] [eclipse.smarthome.model.script.light] - Automatic executed
2019-12-11 21:20:07.627 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'Automatic': The name 'gIndoorLight' cannot be resolved to an item or type; line 36, column 2, length 12

This is when an update happens:

2019-12-11 21:20:45.179 [WARN ] [eclipse.smarthome.model.script.light] - Item updated SpotsFoldingTable state: 26
2019-12-11 21:20:45.189 [WARN] [eclipse.smarthome.model.script.light] - map found: 10

Copy and paste the body of the first rule to the end of the second rule and see what happens when it runs. Something strange is happening here.

Interestingly the same thing happens there.
I have never used groups like this before, so am I missing something?

Maybe. Nothing you have shown so far confirms the existence of a group with that name. Have you actually defined it? Linking an Item to group-name is not sufficient.

1 Like

I do get this in the log, missed that before:

2019-12-11 21:38:43.231 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'indoor_light.rules', using it anyway:
There is no context to infer the closure's argument types from. Consider typing the arguments or put the closures into a typed context.

@rossko57 I do get the updates for that group, so I just assumed it was defined.
I added the Items to groups in the UI, visible in the jsondb file.

If the ‘Member of’ trigger works without an actual group defined, then we’ve got some work to do!

That was my first thought, but the Member of gIndoorLight triggered Rule is running and running without error. So the Group does appear to exist. So I’m with Scott, this is really weird.

That could be a symptom. The error means it can’t figure out what type light is in the forEach. That strongly hints that there is something wrong with gIndoorLight. But it works as a trigger and you even get the same error in the Rule triggered by the Group.

Out of ideas, let’s try stuff.

Copy “gIndoorLight” from the Rule trigger and replace the “gIndoorLight” on the forEach line. There is something about it that even at .rules loading time is seen as a problem. Maybe there’s a hidden character or something weird like that going on.

Ok, that solved it.
I created the group in an .items file and it started working.
I did test removing items from the group before and stopped getting updates, so the system seemed to know about the group in the “Member of”,

Hmmmm. @5iver, is it possible we have a regression in JSONDB stored Groups?

I have played around so much, so it might be something I did on the way that is just really out of the ordinary.