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
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
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
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
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:
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…
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