JSScript - Strange behaviour with item returning to UNDEF

Hi all,

I have a simple rule that is dependant on a item state as per follows:

// Chromecast (http://www.radiofeeds.co.uk/)
rules.JSRule({
    id: "ChromecastGroupPlaylist",
    name: "Chromecast Group Playlist",
    description: "Play radio on Chromecast Group Devices",
    triggers: [triggers.ItemCommandTrigger("chromecast_Group_PlayListURL")],
    execute: event => {
        
        // Declare all variables
        const logger = log("Chromecast.Group");
        const castAction = actions.get("chromecast","chromecast:audiogroup:home_group");
        const castTitle = items.getItem("chromecast_Group_PlaylistTitle");

        logger.debug("Chromecast Group Script - Start");
        console.info("Received Command:", event.receivedCommand);

        switch (event.receivedCommand) {
            case "bbcAsianNetwork":
                castAction.playURL("http://lstn.lv/bbc.m3u8?station=bbc_asian_network&bitrate=320000");
                castTitle.postUpdate("BBC Asian Network");
                break;
            case "desiRadio":
                castAction.playURL("http://radio.canstream.co.uk:8001/live.mp3");
                castTitle.postUpdate("Desi Radio");
                break;
            case "gulshanRadio":
                castAction.playURL("http://s3.voscast.com:11510/;.mp3");
                castTitle.postUpdate("Gulshan Radio");
                break;
            case "panjabRadio":
                castAction.playURL("http://91.121.134.23:8584/stream");
                castTitle.postUpdate("Panjab Radio");
                break;
        }

        logger.debug("Chromecast Group Script - End");
  
     }
 });

Now, it triggers and casts the radio no issues. However, the playlist title will automatically go to ‘UNDEF’ after setting it. Please see logs below:

2024-11-25 17:48:37.521 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'chromecast_Group_PlayListURL' changed from NULL to bbcAsianNetwork
2024-11-25 17:48:38.945 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'chromecast_Group_PlaylistTitle' changed from UNDEF to BBC Asian Network
2024-11-25 17:48:41.016 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'chromecast_Group_Switch' changed from ON to OFF
2024-11-25 17:48:41.901 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'chromecast_Group_PlaylistTitle' changed from BBC Asian Network to UNDEF

This is true for all variations.

Any assistance will be greatly appreciated.

Many thanks in advanced!

Jeevs :slight_smile:

It’s not your rule doing this. It’s the binding.

You can put the binding into debug logging and see if there is something in it’s logs to indicate why it’s setting the Item to UNDEF but usually UNDEF means the binding cannot determine what state that Channel/Item is in.

1 Like

Apologies its taken so long to reply.

Firstly, thank you for confirming I wasn’t going mad lol.

I’ve put the chromecast binding into debug and have the following pertinent logs:

2024-12-04 17:15:02.624 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'chromecast_Group_PlaylistTitle' changed from UNDEF to Panjab Radio
==> /var/log/openhab/openhab.log <==
2024-12-04 17:15:03.452 [DEBUG] [ast.internal.ChromecastStatusUpdater] - MEDIA_STATUS MediaStatus{activeTrackIds: <null>, mediaSessionId: 1, playbackRate: 1, playerState: BUFFERING, currentItemId: 1, currentTime: 0.000000, customData: <null>, loadingItemId: null, items: <null>, preloadedItemId: null, supportedMediaCommands: 274447, volume: Volume{level: 1.0, muted: false, increment: 0.05, stepInterval: 0.05000000074505806, controlType: null}, media: null, repeatMode: REPEAT_OFF, idleReason: null}
2024-12-04 17:15:04.092 [DEBUG] [ast.internal.ChromecastStatusUpdater] - MEDIA_STATUS MediaStatus{activeTrackIds: [], mediaSessionId: 1, playbackRate: 1, playerState: PLAYING, currentItemId: 1, currentTime: 0.000000, customData: <null>, loadingItemId: null, items: [Item{id: 1, media: Media{url: http://91.121.134.23:8584/stream, contentType: audio/mpeg, duration: null}}], preloadedItemId: null, supportedMediaCommands: 274447, volume: Volume{level: 1.0, muted: false, increment: 0.05, stepInterval: 0.05000000074505806, controlType: null}, media: Media{url: http://91.121.134.23:8584/stream, contentType: audio/mpeg, duration: null}, repeatMode: REPEAT_OFF, idleReason: null}
2024-12-04 17:15:04.095 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'chromecast_Group_PlaylistTitle' changed from Panjab Radio to UNDEF
==> /var/log/openhab/openhab.log <==
2024-12-04 17:15:04.517 [DEBUG] [ast.internal.ChromecastStatusUpdater] - MEDIA_STATUS MediaStatus{activeTrackIds: [], mediaSessionId: 1, playbackRate: 1, playerState: PLAYING, currentItemId: 1, currentTime: 0.124547, customData: <null>, loadingItemId: null, items: <null>, preloadedItemId: null, supportedMediaCommands: 274447, volume: Volume{level: 1.0, muted: false, increment: 0.05, stepInterval: 0.05000000074505806, controlType: null}, media: null, repeatMode: REPEAT_OFF, idleReason: null}
2024-12-04 17:15:04.787 [DEBUG] [ast.internal.ChromecastStatusUpdater] - MEDIA_STATUS MediaStatus{activeTrackIds: [], mediaSessionId: 1, playbackRate: 1, playerState: PLAYING, currentItemId: 1, currentTime: 0.415330, customData: <null>, loadingItemId: null, items: [Item{id: 1, media: Media{url: http://91.121.134.23:8584/stream, contentType: audio/mpeg, duration: null}}], preloadedItemId: null, supportedMediaCommands: 274447, volume: Volume{level: 1.0, muted: false, increment: 0.05, stepInterval: 0.05000000074505806, controlType: null}, media: Media{url: http://91.121.134.23:8584/stream, contentType: audio/mpeg, duration: null}, repeatMode: REPEAT_OFF, idleReason: null}
2024-12-04 17:15:14.909 [DEBUG] [ast.internal.ChromecastStatusUpdater] - MEDIA_STATUS MediaStatus{activeTrackIds: [], mediaSessionId: 1, playbackRate: 1, playerState: PLAYING, currentItemId: 1, currentTime: 10.517183, customData: <null>, loadingItemId: null, items: [Item{id: 1, media: Media{url: http://91.121.134.23:8584/stream, contentType: audio/mpeg, duration: null}}], preloadedItemId: null, supportedMediaCommands: 274447, volume: Volume{level: 1.0, muted: false, increment: 0.05, stepInterval: 0.05000000074505806, controlType: null}, media: Media{url: http://91.121.134.23:8584/stream, contentType: audio/mpeg, duration: null}, repeatMode: REPEAT_OFF, idleReason: null}
2024-12-04 17:15:16.103 [DEBUG] [overy.ChromecastDiscoveryParticipant] - Chromecast Type: null

I’m afraid I dont see anything in relation to ‘title’.

Maybe I need to go back to the docs and see if this is even possible…

As always thank you!

Not all Channels are avaialble for all media types being played by a CC. So it very well might be the case that the title is not available for these types of streams. That makes some sense for streams.

1 Like

Yep, suspect you may well be right - may be ‘Read only’. Rather than, write…