# Exec Binding: transform input value

**URL:** <https://community.openhab.org/t/exec-binding-transform-input-value/127134>\
**Category:** Bindings\
**Tags:** execbinding, exec\
**Created:** [October 3, 2021, 1:42pm UTC](https://community.openhab.org/t/exec-binding-transform-input-value/127134 "2021-10-03T13:42:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rfk](https://community.openhab.org/user_avatar/community.openhab.org/rfk/32/71638_2.png) [@rfk](https://community.openhab.org/u/rfk)\
**Post date:** [October 3, 2021, 1:42pm UTC](https://community.openhab.org/t/exec-binding-transform-input-value/127134/1 "2021-10-03T13:42:33Z")

</div>

Hello together,

currently I’m setting up a new openHAB 3 installation (to replace my current openHAB 2 setup) and I’m at the point where I need the Exec Binding: I have several devices in my home which I can control via a single command line application using different arguments, some examples are:

> /usr/bin/app some\_lamp\_on  
> /usr/bin/app some\_lamp\_off  
> /usr/bin/app room\_shutters\_up  
> /usr/bin/app room\_shutters\_stop  
> /usr/bin/app room\_shutters\_down

So I’ve created an exec thing with the command `/usr/bin/app %2$s` and linked its input channel to a `String` item named `App_Test`. In the basic\_ui sitemap I added it as `Switch item=App_Test`. When I enable and disable the switch I can see that the command is executed with the arguments `ON` and `OFF` respectively.

**Now here comes my question:** Is it possible to transform `ON` and `OFF` to e.g. `some_lamp_on` and `some_lamp_off` for the `String` (or `Switch`) item (without rule and with preserving the default switch look in the UI)? Or do I really have to add one exec thing for each element (lamp, shutters, …) and (shell) scripts to do the transformation? What’s the best solution for this problem? By the way, as suggested I’m using the new UI for the configuration so far.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [October 3, 2021, 2:25pm UTC](https://community.openhab.org/t/exec-binding-transform-input-value/127134/2 "2021-10-03T14:25:17Z")

</div>

> [@rfk](#):
>
> Is it possible to transform `ON` and `OFF` to e.g. `some_lamp_on` and `some_lamp_off` for the `String` (or `Switch`) item

Exec binding does not provide ‘command’ transformation features.  
The idea is, since the input is a string, you do that yourself before submitting your command to exec.

You might do that via rule.  
In your UI example, you might do it directly in the UI, have poking buttons send “bananas” or whatever instead of ON.  
In a sitemap, you could use `mappings=[]`

---

<div class="post-metadata">

**Author:** ![rfk](https://community.openhab.org/user_avatar/community.openhab.org/rfk/32/71638_2.png) [@rfk](https://community.openhab.org/u/rfk)\
**Post date:** [October 3, 2021, 6:36pm UTC](https://community.openhab.org/t/exec-binding-transform-input-value/127134/3 "2021-10-03T18:36:53Z")

</div>

What do you mean with “poking buttons”? When adding mappings to the sitemap the “switch look” gets replaced by “named buttons”, while the arguments passed to the command are still `ON` and `OFF` instead of `some_lamp_on` and `some_lamp_off`:  
`Switch item=App_Test mappings=[ON="some_lamp_on", OFF="some_lamp_off"]`

Adding a rule for each item would certainly work, but it takes a lot of effort. With the Exec Binding 1 this was a one-liner along with the item definition, isn’t there a comparable simple solution?

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [October 3, 2021, 7:18pm UTC](https://community.openhab.org/t/exec-binding-transform-input-value/127134/4 "2021-10-03T19:18:14Z")

</div>

> [@rfk](#):
>
> When adding mappings to the sitemap the “switch look” gets replaced by “named buttons”,

Yes, it is restrictive in style.

> [@rfk](#):
>
> the arguments passed to the command are still `ON` and `OFF`

Because that’s what you asked for.  
The widget might be Switch but you’ve linked it to a String Item, send it what you like  
`mappings=["some_lamp_on"="banana", "some_lamp_off"="apple"]`

Mappings takes the form of command, display text. The command has to suit the target Item, not the widget.

> [@rfk](#):
>
> Adding a rule for each item would certainly work, but it takes a lot of effort.

Don’t do that then, write one rule to handle many Items.

```auto
when
   Member of someGroup received command
then
   execItem.sendCommand(triggeringItem.name + ", " + receivedCommand.toString)

```

If you’re going to do it that way, you may as well use `executeCommandLine()` in your rule. You don’t have to use Things if you find them so inconvenient.

---

<div class="post-metadata">

**Author:** ![rfk](https://community.openhab.org/user_avatar/community.openhab.org/rfk/32/71638_2.png) [@rfk](https://community.openhab.org/u/rfk)\
**Post date:** [October 5, 2021, 6:11pm UTC](https://community.openhab.org/t/exec-binding-transform-input-value/127134/5 "2021-10-05T18:11:59Z")

</div>

Ok thanks, it works that way, but I dislike the style.
