Modify item.statedescription from a rule

Hi,

I’d love to dynamically populate the StateDescription.option list of an Item, in order to add/remove entries from a selection on a sitemap.

Sitemap:

...
Selection item=TestSelection
...

Items:

String TestSelection     "Demo [%s]"      

Rule:

    var List<StateOption> options=newArrayList()
    options.add(new StateOption("1", "Label1"));
    options.add(new StateOption("2", "Label2"));
    state = new StateDescription(null, null, null, "%s", false, options);
    TestSelection.stateDescription.options=options
//  TestSelection.stateDescription=state

However, the item’s stateDescription does not change, inspecting it with the REST API, neither by assigning values to the stateDescription.options nor by assigning the stateDescription.

Is there any way to replace/modify the stateDescription part of an item from a rule?

Background: I can read playlist options from the Spotify binding using this code:
Rule:

    ItemPlaylists.commandDescription.commandOptions.forEach[ entry |
    logInfo("Line is",entry.label)
    ]

Now I want to populate several other items with that information and mix it up with entries from other sources. Currently, I solve this with external PHP scripts that pull the required info from various sources and inject it into the .sitemap file, but I would love to do this within OH.

Regards,
Michael

1 Like

We all would… but we can’t :slightly_frowning_face:. You would need to use scripted automation, create a Thing, create a Channel, and link your Item to the Channel. You could then change the StateDescription by modifying the Channel. I dug into this a while ago to add as a helper library, but never finished it up since it would only be a work around until something permanent was put into OHC. Here is a related issue…

1 Like

Well, I think I will go for a change to my PHP script and continue to let this script modify the .sitemap files as required. I thought this would be a great chance to clean up architecture a bit :slight_smile: