Add/RemoveGroups not working

Hi guys,

I am using OH 4.1 with JScripting Automation on a Pi4. I tried to use to AddGroups/RemoveGroups functions to change the group assignment of an item. But the system will give me the following warning:

2024-01-04 19:57:47.181 [WARN ] [mon.registry.AbstractManagedProvider] - Could not update element with key g_DG_Guest in ManagedItemProvider, because it does not exist.

The groups as well as the item itself is defined in an *.items file:

Group SC_Night (SceneControl)
Group SC_Sleeping (SceneControl)

Group g_DG_Guest "Gästezimmer" 
    (g_DG)
    ["Room"]

The code of the rule which causing the warning is as following:

rules.JSRule({
    name: rulePrefix + "scene interest switch between night and sleeping",
    triggers: triggers.ItemStateChangeTrigger("DG_Guest_Scene_NightSeln"),
    execute: (event) => {
        var sleeping = items.getItem("SC_Sleeping");
        var night = items.getItem("SC_Night");
        var guestroom = items.getItem("g_DG_Guest", true);

        if(guestroom !== null) {
            /* add guest room to night scene interest group */
            if(event.newState === "ON") {
                logger.info("adding " + guestroom.name + " to interest group " + night.name);
                guestroom.removeGroups(sleeping);
                guestroom.addGroups(night);

            } else { /* add guest room to sleeping scene interest group */
                logger.info("adding " + guestroom.name + " to interest group " + sleeping.name);
                guestroom.removeGroups(night);
                guestroom.addGroups(sleeping);
            }
        }
        else {
            logger.warning("g_DG_Guest not found!");
        }
    }
})

Do you have any ideas/tips how to solve it? Is there maybe a known issue?

Thanks a lot in advance.

Regards,
Matthias

I’m not certain you can modify an Item that isn’t managed (i.e. defined in .items files) from a rule or any other way. You cannot modify anything else (rules, Things, etc.) from a rule that is defined in text config files so I don’t see why Items would be an exception to that restriction.

I don’t know this for certain but what you describe is the behavior I would expect, though the error could be a little more clear perhaps.

It can’t find g_DG_Guest in the ManagedItemProvider because that Item isn’t managed (i.e. stored in the JSONDB instead of .items files), it’s read only.

Hi Rich,

thanks for the quick response. Means if I want to have my items “managed” I need to configure them all in the PaperUI? Or is there another way to have the configuration somehow file based?

Regards,
Matthias

  1. There is no PaperUI since OH 3.0. We now have MainUI which really has nothing to do with PaperUI.

  2. Anything configured through the UI/REST API/Karaf Console gets saved in files. They are just in a different location and in a different format ($OH_USERDATA/jsondb).

  3. .items files can be imported through MainUI. Just choose “import from text definition” and paste your .items file into the form that appears.

But once the Items are managed, you must maintain/modify them through the manages Items interfaces (i.e. MainUI, REST API, Karaf Console).

aha ok. Good to know. I am sorry. I am a Beginner in OH and still struggling sometimes with all the different approaches and names :).

Then I will change my approach of managing my items. Thanks a lot.

Regards,
Matthias