Multiple transformations on thing channel

I have the following thing:

Type number : speed "Speed" [
	stateTopic="wled/rgb2/v",
	transformationPattern="XPATH:/vs/sx/text()"
]

At the moment this outputs a number between 0 and 255.

I would like to bind this to a dimmer, which does 0 to 100.

Can I perform an additional transform within the channel? If so, how? I’m very comfortable with JS transforms in channels, but wouldn’t know how to JS transform the XPATH transform, so to speak…

Only the MQTT binding supports multiple transformations at the moment.
Your binding is a secret, so answer is “maybe”.

It does look like MQTT binding, and how-to chain transforms is described in the docs.

1 Like

I just needed to know to look for chain!

You’re right, it is the MQTT binding.

EDIT:

For completeness, my working channel (with explicit thing…):

Thing mqtt:topic:swRGB2 "RGB lights" (mqtt:broker:MosquittoMqttBroker) {
		Channels:
			Type dimmer : speed "Speed" [
				stateTopic="wled/rgb/v",
				transformationPattern="XPATH:/vs/sx/text()∩JS:wled2openhab.js"
			]
	}

Where wled2openhab.js (saved in the transform folder):

(function(x) {
    return Math.round(((x / 255) * 100));
})(input)
1 Like