# Transform in Rule

**URL:** <https://community.openhab.org/t/transform-in-rule/130664>\
**Category:** Installation\
**Tags:** mqtt\
**Created:** [December 27, 2021, 11:36am UTC](https://community.openhab.org/t/transform-in-rule/130664 "2021-12-27T11:36:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrissaich](https://community.openhab.org/letter_avatar_proxy/v4/letter/c/ea666f/32.png) [@chrissaich](https://community.openhab.org/u/chrissaich)\
**Post date:** [December 27, 2021, 11:36am UTC](https://community.openhab.org/t/transform-in-rule/130664/1 "2021-12-27T11:36:23Z")

</div>

Hi

Hope you all had a good Christmas. For me it’s too much food and not enough coding.

I have a system working happily on RPI4 running OpenHAB 3 with Mosquitto MQTT Broker running and communicating on the same RPI4.

I have a number of temperature inputs which will send me a topic of

```auto
occ/location/ti

```

and the payload will be the number of the temperature sensor 1-8, followed by a ‘:’ followed by the temperature value, so a typical payload might be

```auto
1:11.6

```

Can somebody show me a rule which will allow me to ‘Switch/case’ on the first digit and extract the temperature value to forward to the relevant UI location?

Thanks as ever

---

<div class="post-metadata">

**Author:** ![hafniumzinc](https://community.openhab.org/letter_avatar_proxy/v4/letter/h/b9bd4f/32.png) [@hafniumzinc](https://community.openhab.org/u/hafniumzinc)\
**Post date:** [December 27, 2021, 11:57am UTC](https://community.openhab.org/t/transform-in-rule/130664/2 "2021-12-27T11:57:39Z")

</div>

You might be able to do this in your Thing Channel directly without a rule by using REGEX to filter for the sensor by looking for

```auto
1:

```

then chaining another REGEX transform to extract the temperature value. All of this would go in the `transformationPattern` of the Thing Channel. You can then create a separate Channel for each temperature sensor, adjusting your first REGEX filter to suit.

This may help:

> [@MQTT 2.5 M1+ How to implement the equivalent to MQTT1 REGEX filters](https://community.openhab.org/t/mqtt-2-5-m1-how-to-implement-the-equivalent-to-mqtt1-regex-filters/68350):
>
> Problem In the MQTT1 binding there was a feature that let us filter messages published to a given topic and only pass those that match a given REGEX to the transformation and/or on to the Item. This was useful to handle devices that publish messages to a single well known topic for all their devices. For example, the official firmware from the vendor of Shelly devices have a request/response protocol over MQTT to get meta data about the devices (IP address, MAC address, firmware version, whethe…

---

<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:** [December 27, 2021, 1:46pm UTC](https://community.openhab.org/t/transform-in-rule/130664/3 "2021-12-27T13:46:04Z")

</div>

> [@chrissaich](#):
>
> Can somebody show me a rule which will allow me to ‘Switch/case’ on the first digit

If you must go that way, string `.split(":")` would be useful.  
But I’d direct effort at doing it in the channel(s) by transformation, as suggested by @hafniumzinc
