# Send a : in a MQTT Command

**URL:** <https://community.openhab.org/t/send-a-in-a-mqtt-command/10629>\
**Category:** Beginners\
**Tags:** mqtt\
**Created:** [May 14, 2016, 12:45pm UTC](https://community.openhab.org/t/send-a-in-a-mqtt-command/10629 "2016-05-14T12:45:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chaos](https://community.openhab.org/letter_avatar_proxy/v4/letter/c/9d8465/32.png) [@Chaos](https://community.openhab.org/u/Chaos)\
**Post date:** [May 14, 2016, 12:45pm UTC](https://community.openhab.org/t/send-a-in-a-mqtt-command/10629/1 "2016-05-14T12:45:34Z")

</div>

Hi i need to send a Colon as in the command like :  
Switch ED001 {mqtt=“\>[openhab:mytopic/test:command:ON:{out12:1}],\>[openhab:mytopic/test:command:OFF:{out12:0}]”}  
but openhab interperates this wrong. is there a way around this?  
Thanks Chris.

---

<div class="post-metadata">

**Author:** ![watou](https://community.openhab.org/user_avatar/community.openhab.org/watou/32/70595_2.png) [@watou](https://community.openhab.org/u/watou)\
**Post date:** [May 14, 2016, 12:52pm UTC](https://community.openhab.org/t/send-a-in-a-mqtt-command/10629/2 "2016-05-14T12:52:45Z")

</div>

That ought to be possible with the transformation parameter at the end of the [outbound binding string](https://github.com/openhab/openhab/wiki/MQTT-Binding#item-binding-configuration-for-outbound-messages):

> **transformation** : Rule defining how to create the message content. Transformations are defined in the format of TRANSFORMATION\_NAME(transformation\_function). Allowed values are ‘default’ or any of the transformers provided in the org.openhab.core.transform bundle. Custom transformations can be contributed directly to the transform bundle by making the Transformation available through Declarative Services. Any other value than the above types will be interpreted as static text, in which case this text is used as the message content. |

Another approach is to write a rule and use the MQTT `publish` action when a command is sent to the item.

---

<div class="post-metadata">

**Author:** ![Chaos](https://community.openhab.org/letter_avatar_proxy/v4/letter/c/9d8465/32.png) [@Chaos](https://community.openhab.org/u/Chaos)\
**Post date:** [May 14, 2016, 4:03pm UTC](https://community.openhab.org/t/send-a-in-a-mqtt-command/10629/3 "2016-05-14T16:03:59Z")

</div>

hi  
thanks for quick response, but i’m pretty new to this, and don’t really understand. Where i have ‘{out12:x}’ i replace this with something that runs something else ?. i thought of running node red and using it to convert a valid text to what i need, but dont really want any more than nessescery running on my open hab raspberry. plus i really want to get to grips with openhab now i have got this far. i have run node red before its ok, but not as stable as openhab.  
thanks  
Chris

---

<div class="post-metadata">

**Author:** ![watou](https://community.openhab.org/user_avatar/community.openhab.org/watou/32/70595_2.png) [@watou](https://community.openhab.org/u/watou)\
**Post date:** [May 14, 2016, 4:24pm UTC](https://community.openhab.org/t/send-a-in-a-mqtt-command/10629/4 "2016-05-14T16:24:22Z")

</div>

If you made a file like `transform/ED001.map`:

```auto
ON={out12:1}
OFF={out12:0}

```

and changed your binding config to:

```auto
Switch ED001 { mqtt=">[openhab:mytopic/test:command:*:MAP(ED001.map)]" }

```

I believe (haven’t tried it) that the ON command will be mapped to `{out12:1}` which will be used as the message to publish to `mytopic/test`.

---

<div class="post-metadata">

**Author:** ![Chaos](https://community.openhab.org/letter_avatar_proxy/v4/letter/c/9d8465/32.png) [@Chaos](https://community.openhab.org/u/Chaos)\
**Post date:** [May 14, 2016, 4:28pm UTC](https://community.openhab.org/t/send-a-in-a-mqtt-command/10629/5 "2016-05-14T16:28:34Z")

</div>

i have to go out but will try later  
many thanks  
chris

---

<div class="post-metadata">

**Author:** ![Chaos](https://community.openhab.org/letter_avatar_proxy/v4/letter/c/9d8465/32.png) [@Chaos](https://community.openhab.org/u/Chaos)\
**Post date:** [May 14, 2016, 10:15pm UTC](https://community.openhab.org/t/send-a-in-a-mqtt-command/10629/6 "2016-05-14T22:15:23Z")

</div>

hi  
it worked !! thank you so much  
chris

---

<div class="post-metadata">

**Author:** ![Ianc99](https://community.openhab.org/user_avatar/community.openhab.org/ianc99/32/45970_2.png) [@Ianc99](https://community.openhab.org/u/Ianc99)\
**Post date:** [December 9, 2018, 11:43pm UTC](https://community.openhab.org/t/send-a-in-a-mqtt-command/10629/7 "2018-12-09T23:43:12Z")

</div>

I’ve a similar situation and I’ve tried the solution but am not having such good luck.

If my Tasmota device reports power1 “OFF” I need to flip it to reporting “ON”.

FYI - I need to do the same flipping of the on/off when issuing commands to the device. I have this part working.  
The reason for this is my relays are energised with a 0 on the GPIO.

Anyway I have the sending command working and I’'m trying to flip the incoming message using the same technique described earlier in this thread.  
My line in my item file looks like this:

`Switch GSonoff0104 "Front Lamp" <light> (LR,gLight) ["Lighting"] { mqtt=">[mosquitto:cmnd/GSONOFF01/POWER4:command:OFF:ON],>[mosquitto:cmnd/GSONOFF01/POWER4:command:ON:OFF], <[mosquitto:stat/GSONOFF01/POWER4:state:MAP(FLIP.map)]"}`

and I’ve placed a file named FLIP.map in /srv/openhab2-conf/transform directory which contains:

```
ON=OFF
OFF=ON

```

If I change the state of the device via Openhab all is fine. If it changes on the device I get this error in the openhab log and the state is not updated

```
2018-12-09 23:32:00.285 [WARN] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type MAP
2018-12-09 23:32:00.291 [WARN] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn't post update for 'GSonoff0104'

```

Do I need to do something more to get MAP working?

---

<div class="post-metadata">

**Author:** ![Ianc99](https://community.openhab.org/user_avatar/community.openhab.org/ianc99/32/45970_2.png) [@Ianc99](https://community.openhab.org/u/Ianc99)\
**Post date:** [December 9, 2018, 11:52pm UTC](https://community.openhab.org/t/send-a-in-a-mqtt-command/10629/8 "2018-12-09T23:52:32Z")

</div>

I had not installed the MAP transform. Doh!  
So I’m going to hide under the desk now!
