I split Values returned by MQTT Topic in things using JS:
thing:
Type number : temperature_outside [ stateTopic="ebusd/24849/temperature.outside", transformationPattern="JS:|(input).split(';')[6]" ]
value (as visible in MQTT Explorer):
0;0;0d;°C;50.0;-50.0;22.0
this returns in item the correct value 22.0
a string type thing
Type string : status_heating [ stateTopic="ebusd/24849/status.heating", transformationPattern="JS:|(input).split(';')[6]" ]
with value
51;1;00;0;25.5;0.0;Abgeschaltet
returns nothing.
The value returned ist a semicolon separated array, JS split method should return the element at index 6 (array starts with index 0), but only if I define thing as number.
I would guess because it is a string it is not going to be separated by the ;
I just did a quick JS script to test and you have to put each part of the string that is separated by the ; into an array.
Below should give you something to work with:
var str = "51;1;00;0;25.5;0.0;Abgeschaltet";
var temp = new Array();
// This will return an array with strings "1", "2", etc.
temp = str.split(";")[6];
console.log(temp)
I use only files, my OH is 4.1.3 but I started with version 2 so most of my config relays on files.
I don’t know how to write a working js file for this case to put into the scripts directory, the way to define the thing I found in the meantime:
OK that should work I guess.
I started with 2.5 and went to version 3 and now 4.1.
When I went from 2.5 to 3 I dropped all DSL scripts and dropped all files and just used the UI and it made it so much easier in some ways.
The only thing I missed was being able to grep for code in the files but in the UI you can do that in the developer tools.
Good luck. Hope it works for you.