# Transform scale range to other range

**URL:** <https://community.openhab.org/t/transform-scale-range-to-other-range/118943>\
**Category:** Items & Sitemaps\
**Tags:** dimmer\
**Created:** [March 14, 2021, 8:41am UTC](https://community.openhab.org/t/transform-scale-range-to-other-range/118943 "2021-03-14T08:41:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![a.alakszai](https://community.openhab.org/user_avatar/community.openhab.org/a.alakszai/32/36535_2.png) [@a.alakszai](https://community.openhab.org/u/a.alakszai)\
**Post date:** [March 14, 2021, 8:41am UTC](https://community.openhab.org/t/transform-scale-range-to-other-range/118943/1 "2021-03-14T08:41:47Z")

</div>

Hi Guys,  
I have an OH2.5 on RPi

I purchased a Tuya WIFI dimmer what I could connect to OH via Tuya\_Mqtt and Mosquito.  
Issue is that the Tuya dimmer brightness is adjustable in a range of 1-1000. Dimmer Things / Items in OH can play in scale 0-100 range so I could play with the brightness in 0-10% range.

Is there a way to extend it?  
(if I initiate the Item as Number than it works well of course)

Thanks

---

<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:** [March 14, 2021, 9:13am UTC](https://community.openhab.org/t/transform-scale-range-to-other-range/118943/2 "2021-03-14T09:13:26Z")

</div>

Sure. The whole idea of Items is to represent many and various devices as idealized standard models. Leave the Dimmer Item alone, and instead do a transformation scaling in the binding channel.

---

<div class="post-metadata">

**Author:** ![a.alakszai](https://community.openhab.org/user_avatar/community.openhab.org/a.alakszai/32/36535_2.png) [@a.alakszai](https://community.openhab.org/u/a.alakszai)\
**Post date:** [March 14, 2021, 10:14am UTC](https://community.openhab.org/t/transform-scale-range-to-other-range/118943/3 "2021-03-14T10:14:31Z")

</div>

Great. But what transformation service do you advise? I cannot find any which can tranform a range to another.  
This is my Chanel definition:

```auto
Type dimmer : PowerDimmer "Fényerő" [stateTopic="tuya/tuyadimmer_01/dps/2/state", commandTopic="tuya/tuyadimmer_01/dps/2/command"]

```

---

<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:** [March 14, 2021, 10:20am UTC](https://community.openhab.org/t/transform-scale-range-to-other-range/118943/4 "2021-03-14T10:20:13Z")

</div>

> [@a.alakszai](#):
>
> I cannot find any which can tranform a range to another.

That’s just maths. (As you point out, although this is “scaling”, the SCALE transform is not the one for this job.)  
We can do any maths in a javascript transform.

I think you’d need two JS scripts here,one to multiply by 10 on the way out, one to divide by ten on the way in.  
Similar examples in modbus binding docs -

> **[Modbus - Bindings](https://www.openhab.org/addons/bindings/modbus/#transformation-example-scaling)**
>
> This is the binding to access Modbus TCP and serial slaves.

In the MQTT channel, you’d be looking to use **transformationPattern** (for inbound) and **transformationPatternOut**  
[https://www.openhab.org/addons/bindings/mqtt.generic/#channel-configuration](https://www.openhab.org/addons/bindings/mqtt.generic/#channel-configuration)

---

<div class="post-metadata">

**Author:** ![a.alakszai](https://community.openhab.org/user_avatar/community.openhab.org/a.alakszai/32/36535_2.png) [@a.alakszai](https://community.openhab.org/u/a.alakszai)\
**Post date:** [March 14, 2021, 11:54am UTC](https://community.openhab.org/t/transform-scale-range-to-other-range/118943/5 "2021-03-14T11:54:18Z")

</div>

Thanks, it is working well.  
Chanel:

```auto
Type dimmer : PowerDimmer "Fényerő" [stateTopic="tuya/tuyadimmer_01/dps/2/state", transformationPattern="JS:divide10.js", commandTopic="tuya/tuyadimmer_01/dps/2/command", transformationPatternOut="JS:multiply10.js"]

```

Item:

```auto
Dimmer MQTT_TuyaDimmer01_PowerDimmer "Nappali Fényerő" {channel="mqtt:topic:MQTT_Tuya_DIM_01:PowerDimmer"}

```

and the JS transformation (multiply10 is the same):  
divide10.js

```auto
(function(inputData) {
    // on read: the polled number as string
    // on write: openHAB command as string
    var DIVIDE_BY = 10;
    return Math.round(parseFloat(inputData) / DIVIDE_BY);
})(input)

```
