Transformations are used to translate data from a cluttered or technical raw value to a processed or human-readable representation.
They are often useful, to **interpret received Item values**, like sensor readings or state variables, and to translate them into a human-readable or better processible format.
**Examples:**
- Translation of a technical Binding output, e.g., "CLOSED" can be translated to the Spanish translation "cerrado"
- Processing of a raw Item value, e.g., Parsing a number from a JSON string, like `{ "temperature": 23.2 }`
- Conversion of sensor readings, e.g., temperature in degree Celsius can be converted to degree Fahrenheit
## Usage
Transformations are applicable in Item and Sitemap element labels and inside DSL rules.
Transformations can sometimes be used in binding add-ons. For example, transforming an openHAB ON command into "action=powerup" for sending to a device.
If, and how, this use may be available is described in individual binding documentation.
1. Profiles
Transformations can be associated with channels, working on data being passed between bindings and Items. See [profile documentation]({{base}}/configuration/items.html#profiles) for more detail.
The `SCRIPT` transformation is available from the framework and needs no additional installation.
It allows transforming values using any of the available scripting languages in openHAB (JSR-223 or DSL).
The script needs to be placed in the `$OPENHAB_CONF/transform` folder with an extension `.script` regardless of the actual script type.
When referencing a transformation, the script type must be prepended to the filename (e.g. `dsl:stringlength` for the DSL version of `stringlength.script`).
Please note that you cannot have transformations with the same name and different languages as the file-extension is always `script`.
The input value is injected into the script context as a string variable `input`.
The result needs to be returned from the script, it can have be `null` or value of type that properly implements `.toString()`.
Additional parameters can be injected in the script by adding them to the script identifier in URL style (`js:scale?correctionFactor=1.1÷r=10` would also inject `correctionFactor` and `divider`).
The examples show a simple transformation with the same functionality for some languages.
It takes the length of the input string and e.g. returns `String has 5 characters`.
:::: tabs
::: tab DSL
The script-prefix is `dsl`.
```java
var returnValue = "String has " + input.length + " characters"
returnValue
```
:::
::: tab Nashorn JS
The script-prefix is `js`
```java
(function(data) {
var returnValue = "String has " + data.length + " characters"
return returnValue
})(input)
```
:::
::::
Currently the `SCRIPT` transformation is not available as profile.