How to ignore the string item if its UNDEF

Great application of the 1-2-3 Design Pattern :smiley:

The only addition I can make here is it’s possible that the title or artist Item has changed since the rule was triggered (unlikely) or one of the Items changed but the other hasn’t changed yet (more likely). So you might need to add some logic to handle that.

The most straight forward might be to use a timer to wait long enough for both to have changed before updating the summary.

rule "Kodi Now Playing Summary"
when
    Item myKodi_title changed or
    Item myKodi_artist changed
then
    val timer = privateCache.get('timer')

    // If there already is a timer running, reschedule it
    if(timer !== null && !timer.hasTerminated) {
        timer.reschedule(now.plusMillis(500))
    }
    // Create a timer to wait half a second before updating the summary
    else {
        privateCache.put('timer', createTimer(now.plusMillis(500), [ |
            var strSummary = myKodi_title.state.toString
            if(myKodi_artist.state != UNDEF)
                strSummary = myKodi_artist.state.toString + " - " + strSummary

            KodiSummary.postUpdate(strSummary)
        ])
    }
end

So let’s say a new media starts playing and both the title and artist change. Let’s say the rule triggers first for the artist. The above will wait up to half a second for the title to change before updating the summary Item.

You can experiment to see the minimum reliable amount of time to wait.

Finally, I’ll mention that if you are using MainUI to display this summary, you might be able to eliminate this rule entirely and use a custom widget instead. MainUI lets you combine multiple Items into one widget. For example Mediaplayer Now Playing and Control shows artist, media title, and lets you control the playback (combines five separate Items) in one list Item widget.