[SOLVED] Using item variables within rules

Hi all,

I’m just getting started with OpenHAB but I’m having some difficulty with writing a rule containing a variable.

Essentially what I would like to do is echo out the string value of ‘Chromecast_YouTube’ and use it as part of my curl command. Can someone point out where I’m going wrong here please?

Also, what language/script is this? Where can I find documentation on using variables within these rules?

Here is my rule:

rule "Chromecast YouTube Content Changed"
when
    Item Chromecast_YouTube changed
then
    executeCommandLine('curl -H “Content-Type:application/json” "http://192.168.1.12:8008/apps/YouTube" -X POST -d '.Chromecast_YouTube, 5000)
end

Here is my log:
2018-12-30 14:41:13.375 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Chromecast YouTube Content Changed': 'Chromecast_YouTube' is not a member of 'java.lang.String'; line 5, column 24, length 112

Thanks in advance.

To start with that, it is Xtend: Xtend - Modernized Java

And to concatenate two strings, you would need to use a + instead of a point. and if you want to get the string value of an item, you first of all need to get its state, so your executeCommandLine would become something like:

    executeCommandLine('curl -H “Content-Type:application/json” "http://192.168.1.12:8008/apps/YouTube" -X POST -d ' + Chromecast_YouTube.state, 5000)
1 Like

Excellent - thank you :slight_smile:

Please mark the thread as solved, thanks
Tick the solution mark under the relevant post.