How to evaluate the state of a ChromeCastAudio item?

I’m pretty new at this so the answer will likely be pretty easy…
I want to evaluate the state of a chromecastaudio
I tried something like this:

if (chromecast_audio_12345xxx_control.state == "PLAY)

but I always get the error:

The name ‘If()’ cannot be resolved to an item or type.

What am I doing wrong?

Your line looks good to me.

Maybe the lines above are wrong.

Please post your complete rule.

I got it working as follows:

import org.openhab.model.script.actions
import org.openhab.core.library.types
import java.util

rule "check chromecast state"
when
    Item chromecast_audio_473325b22fd70ba5c3e51dd0d503fc7c_control changed
then
var String command = chromecast_audio_473325b22fd70ba5c3e51dd0d503fc7c_control.state.toString

if (command.contains("PLAY"))
	{
        logInfo("TEST","Chromecast is playing")
    }
else if (command.contains("PAUSE"))
	{
        logInfo("TEST","Chromecast is paused")
    }
  
end

Do this work for you when you start casting something?

I only get the state change when I press play or pause on OHab UI, but nothing when i start casting or stop from spotify app.

So far I’ve used it only to play iHeartRadio streams and it works

Hi Alex,

Could you help me out here? When you say you are using this for streaming iHeart, do you mean you are streaming iHeart from a phone or tablet, separate from OH? Or do you actually have music steaming integrated into OH? (I would love to see how this works, if so.)

And I have the CCast binding installed, and channels active. But I am really just starting with Rules. Can you tell me what else i need to make use of it? ie, scripts, items, sitemap entry etc?

Thanks for any help.
TD