Rules Error - no viable alternative .....executeCommandLine

Any Idea what i did wrong. Tried many ways to set the " " so its accepcted - but as i have no clue about the error log, it was only a guess that there is some confusion about the marks…

[251,144]: no viable alternative at input '":"'
[251,152]: mismatched input ‘)’ expecting 'end’

Thanks a lot
Norbert

switch(receivedCommand) {
    case 0 : executeCommandLine("mosquitto_pub -h 192.168.1.95 -t 'W/0cxxxxxxx8/settings/0/Settings/CGwacs/MaxDischargePower' -m '{"value":"0"}'")
    case 1 : executeCommandLine("mosquitto_pub -h 192.168.1.95 -t 'W/0cxxxxxxx8/settings/0/Settings/CGwacs/MaxDischargePower' -m '{"value":"50"}'")
    case 2 : executeCommandLine("mosquitto_pub -h 192.168.1.95 -t 'W/0cxxxxxxx8/settings/0/Settings/CGwacs/MaxDischargePower' -m '{"value":"250"}'")
    case 3 : executeCommandLine("mosquitto_pub -h 192.168.1.95 -t 'W/0cxxxxxxx8/settings/0/Settings/CGwacs/MaxDischargePower' -m '{"value":"500"}'")
    case 4 : executeCommandLine("mosquitto_pub -h 192.168.1.95 -t 'W/0cxxxxxxx8/settings/0/Settings/CGwacs/MaxDischargePower' -m '{"value":"1000"}'")
    case 5 : executeCommandLine("mosquitto_pub -h 192.168.1.95 -t 'W/0cxxxxxxx8/settings/0/Settings/CGwacs/MaxDischargePower' -m '{"value":"1500"}'")
}

maybe there is anyhow a more smart way to handle an MQTT publish towards an external broker.

Which version of openHAB? The arguments to executeCommandLine have changed in OH 3.

The MQTT Binding perhaps. You don’t have to use the embedded Moquette broker and in fact in OH 3 that embedded broker has been removed.

i’m old school 2.5.10. I tried so many things, i looked so many times to this rule - but i cannot find anything wrong. but it has to be - otherwise it would be accepted.

You have double quotemarks inside double qoutemarks, not going to work. You’ll need to escape them \"

Did you know the MQTT binding gives you a Publish Action for use in rules?

Looking at the String passed to executeCommandLine, you have double quotes inside the double quotes. You need to escape those that are part of the string. As currently written your quotes don’t line up.

If you break it up you are passing the following five arguments:

  1. “mosquitto_pub -h 192.168.1.95 -t ‘W/0cxxxxxxx8/settings/0/Settings/CGwacs/MaxDischargePower’ -m '{”
  2. value
  3. “:”
  4. 0
  5. “}’”

executeCommandLine requires one or two arguments, not five. That’s why it’s complaining. You need to escape the quotes that are part of the string.

"mosquitto_pub -h 192.168.1.95 -t 'W/0cxxxxxxx8/settings/0/Settings/CGwacs/MaxDischargePower' -m '{\"value\":\"0\"}'"

Without the escapes, the first " will close the String and the next one will open a new String.

But really, you should use the MQTT binding.

1 Like

Thanks a lot,…i was pretty sure its something with these many marks…but not thinking about the " to make it happen the way i want it. Thanks

I’m only using MQTT 1.x binding for items. still even more old school. will look into publishing inside of rules, if it works with the old version of the binding as well.

Cheers

There is a separate MQTT action you need to install.

ah thanks, was just looking into the MQTT standard binding and it does not seem to have this inside. Thanks!!!

According to the documentation the spaces need to be replaced with @@.

@rlkoshak just for curiosity - as MQTT action is related to MQTT binding 1.x…how is this covered in MQTT 2.x binding? is MQTT action integrated in the 2.x binding, or 1.x still cooperates with MQTT 2.x binding - which i guess is not the case.

Yes, it’s in the docs.

1 Like

To elaborate a little, in OH 2 they’ve done away with separately installible Action add-ons. Instead bindings come bundled with their actions (if any). There are even some cases where the binding only exists to provide the action (e.g. the email binding). Instead of filling out a cfg file, one creates a Thing with the connection information. From the rule you pull the action from that Thing, making it much easier to support more than one connection.

thanks for the clarification/background information - indeed soon i should swap over to 2.x binding. As 3.x will not support 1.x bindings from what i understand as the most important todo-part for myself…

Sorry to bother you all again, but still my issue is not solved.

Tried simply the publish (mqtt action). Does not work, even if i try to send to a standard mosquitto broker. I read that there are some issues with MQTT action, so i stopped this path to not invest too much time on a dead horse :slight_smile:

Again i tried the executeCommandLine. it shows that it was triggered on the logs, but nothing happens. Now i tried the same command to put it into a script and execute the script …it works.
So any idea what else i could try…already did the \ " and tried @@

Any further ideas what i could try on top?

executeCommandLine("mosquitto_pub -h 192.168.1.95 -t 'Wdsfasdfds38/settings/0/Settings/CGwacs/MaxDischargePower' -m '{\"value\":0}'")

What issues and how old was there post and which version of the Action? As far as I’m aware the 2.x version works without problem.

Personally, I’d spend my time and effort trying to solve the problem is the most straightforward and typical manner, which would be using the MQTT Action.

Since you got it to work using a shell script, why not stop there and claim success? Using execute command line is already kind of a hack and a work around. Using a script is really no more so.

Thanks @rlkoshak, i really would love to use MQTT action, but i tried now many things last evening but nothing arrives at the broker.

Maybe you can see anything i did wrong:
mosquitto is the name in the service cfg file for MQTT. this one works for years now and also the broker has a lot of messages if i use MQTT.fx as a subscriber. Looking at this topic below, nothing arrives at all.

publish("mosquitto","/home/test","teststring")

  • is mosquitto_pub in the path of the user that OH runs under ? If not add the path in front of the executable
  • is it executable, readable for the OH user ?
  • add a timeout value as second argument to executeCommandLine
  • the first set of single quotes is not required
  • are you sure that double quotes around value are required ?
  • I would try
executeCommandLine("mosquitto_pub -h 192.168.1.95 -t Wdsfasdfds38/settings/0/Settings/CGwacs/MaxDischargePower -m {value:0},5000")

or

executeCommandLine("mosquitto_pub -h 192.168.1.95 -t Wdsfasdfds38/settings/0/Settings/CGwacs/MaxDischargePower -m '{value:0}', 5000")

resp.
the above two examples with path to mosquitto_pub

That one line will not be sufficient to diagnose the problem.

What version of the binding is installed?
What version of the Action is installed? They are both installed right?
Do MQTT Items work?
What order did you install the add-ons? There was a time when the Action needed to be installed second or else problems would occur.
Anything in the logs?

If there is a bug with the Action of the Binding, it’s never going to be fixed. At some point entropy is going to force you to upgrade to the 2.x binding. Maybe it’s time to spend the effort now when you are not under the gun to fix it.

Sorry, you’re right.
Its 2.5.10 core and the binding is 1.14.0. YES MQTT works fine. MQTT first, and the Action second.
Logs do not show anything regarding MQTT.

but from all the threats i see today i better stop with MQTT action efforts…many issues people have/had and i do not want to end up with install/uninstalling until it runs for a certain time.

e.g., not too much reliance…

There is a problem with the mqtt action that occur sometimes.
Remove the action, clear the cache and after a restarting oh, install the action agian