Questions about transformations and MQTT binding :

Hello there ,

I have a problem when declaring and item, i want so publish a message to the topic , normally this works but in this case the message messes up the parser for the items.

what i want to do is the following:
publish the message from between the brackets ( “{“status”:“OFF”}”) to the topic lights/0x1234/rgbw/4

if i declare my swithch item like this :

Switch mqttsw1  "MQTT" {mqtt=">[broker:lights/0x1234/rgbw/4:command:ON:"{"status":"ON"}"],>[broker:lights/0x1234/rgbw/4:command:OFF:"{"status":"OFF"}"]"}

then i get an error :

Binding configuration of type 'mqtt' of item 'mqttsw1' could not be parsed correctly. org.eclipse.smarthome.model.item.BindingConfigParseException: Configuration 'broker:lights/0x1234/rgbw/4:command:ON:MAP(milight.map):TURNON' is not a valid outbound configuration: Configuration requires 5 parameters separated by ':' at org.openhab.core.binding.internal.BindingConfigReaderDelegate.processBindingConfiguration(BindingConfigReaderDelegate.java:50)[176:org.openhab.core.compat1x:2.0.0] at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:312)[123:org.eclipse.smarthome.model.item:0.9.0.b4] at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:284)[123:org.eclipse.smarthome.model.item:0.9.0.b4] at org.eclipse.smarthome.model.item.internal.GenericItemProvider.processBindingConfigsFromModel(GenericItemProvider.java:167)[123:org.eclipse.smarthome.model.item:0.9.0.b4] at org.eclipse.smarthome.model.item.internal.GenericItemProvider.modelChanged(GenericItemProvider.java:347)[123:org.eclipse.smarthome.model.item:0.9.0.b4] at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.notifyListeners(ModelRepositoryImpl.java:207)[122:org.eclipse.smarthome.model.core:0.9.0.b4] at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.addOrRefreshModel(ModelRepositoryImpl.java:120)[122:org.eclipse.smarthome.model.core:0.9.0.b4] at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.checkFile(FolderObserver.java:272)[122:org.eclipse.smarthome.model.core:0.9.0.b4] at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.access$1(FolderObserver.java:265)[122:org.eclipse.smarthome.model.core:0.9.0.b4] at org.eclipse.smarthome.model.core.internal.folder.FolderObserver$WatchQueueReader.processWatchEvent(FolderObserver.java:146)[122:org.eclipse.smarthome.model.core:0.9.0.b4] at org.eclipse.smarthome.core.service.AbstractWatchQueueReader.run(AbstractWatchQueueReader.java:122)[98:org.eclipse.smarthome.core:0.9.0.b4] at java.lang.Thread.run(Thread.java:748)[:1.8.0_131] 2017-06-04 02:02:41.130 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'lights.items' 2017-06-04 02:02:41.135 [ERROR] [el.item.internal.GenericItemProvider] - Binding configuration of type 'mqtt' of item 'mqttsw1' could not be parsed correctly. org.eclipse.smarthome.model.item.BindingConfigParseException: Configuration 'broker:lights/0x1234/rgbw/4:command:ON:MAP(milight.map):TURNON' is not a valid outbound configuration: Configuration requires 5 parameters separated by ':' at org.openhab.core.binding.internal.BindingConfigReaderDelegate.processBindingConfiguration(BindingConfigReaderDelegate.java:50)[176:org.openhab.core.compat1x:2.0.0] at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:312)[123:org.eclipse.smarthome.model.item:0.9.0.b4] at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(GenericItemProvider.java:284)[123:org.eclipse.smarthome.model.item:0.9.0.b4] at org.eclipse.smarthome.model.item.internal.GenericItemProvider.processBindingConfigsFromModel(GenericItemProvider.java:167)[123:org.eclipse.smarthome.model.item:0.9.0.b4] at org.eclipse.smarthome.model.item.internal.GenericItemProvider.modelChanged(GenericItemProvider.java:347)[123:org.eclipse.smarthome.model.item:0.9.0.b4] at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.notifyListeners(ModelRepositoryImpl.java:207)[122:org.eclipse.smarthome.model.core:0.9.0.b4] at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.addOrRefreshModel(ModelRepositoryImpl.java:120)[122:org.eclipse.smarthome.model.core:0.9.0.b4] at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.checkFile(FolderObserver.java:272)[122:org.eclipse.smarthome.model.core:0.9.0.b4] at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.access$1(FolderObserver.java:265)[122:org.eclipse.smarthome.model.core:0.9.0.b4] at org.eclipse.smarthome.model.core.internal.folder.FolderObserver$WatchQueueReader.processWatchEvent(FolderObserver.java:146)[122:org.eclipse.smarthome.model.core:0.9.0.b4] at org.eclipse.smarthome.core.service.AbstractWatchQueueReader.run(AbstractWatchQueueReader.java:122)[98:org.eclipse.smarthome.core:0.9.0.b4] at java.lang.Thread.run(Thread.java:748)[:1.8.0_131]

Is there a way to transform the contents of my message ("{“status”:“OFF”}") so that it doesn’t interfere with the syntax?

The exception seems to refer to an old situation are you its the correct exception

ok so i found out what the problem is, its the colon ( : ) from my message “{“status”:“OFF”}” :
and the double quotes .

i figured out how to escape the double quotes but i cant do it for the colon.
i replaced the colon with a semicolon , just to see what happens so if i would declare my switch like :

Switch mqttsw1 “MQTT” {mqtt=">[broker:lights/0x1234/rgbw/1:command:ON:{“status”;“ON”}],

					>[broker:lights/0x1234/rgbw/1:command:OFF:{\"status\";\"OFF\"} "}

my device receives the message : “{“status”;“OFF”}”, and openhab loggger gives no error.

but the problem is that it needs a colon in order to interpret the message correctly . as in it needs to receive “{“status”:“OFF”}”

if in the above declaration i replace the semicolon with a colon the the logger gives the error that i cannot parse the switch correctly becasue it interprets the colon as a separator and not as a part of the string (or at least this is my theory )

2017-06-04 15:25:44.243 [ERROR] [el.item.internal.GenericItemProvider] - Binding configuration of type ‘mqtt’ of item ‘mqttsw1’ could not be parsed correctly.
org.eclipse.smarthome.model.item.BindingConfigParseException: Configuration ‘broker:lights/0x1234/rgbw/1:command:ON:’ is not a valid outbound configuration: Configuration requires 5 parameters separated by ‘:’

anbody has any idea on how to overcome this issue?

You could maybe do it in 2 steps, first step update a string item to contain the string to send.
Step two send the string item on update over mqtt

hi

Thanks for your reply. That sounds like a good idea. but how do i call the value of a string item (sorry for the noob question)

if i do this :

String TurnOff "{“status”:“OFF”}"
String TurnOn “{“status”:“ON”}” - some of the quotes maybe need to be escaped

Switch mqttsw1 “MQTT” {mqtt=">[broker:lights/0x1234/rgbw/1:command:ON:TurnOn],>[broker:lights/0x1234/rgbw/1:command:OFF:TurnOff] "}

it just sends TurnOn and TurnOff

i found the solution in the end , it was very frustrating.

so the solution is to do as described in this forum topic :

Send a : in a MQTT Command