JS Transform

Hi

My item:

Number solarview “Leistung [%.2f W]” {exec="<[/share/MD0_DATA/.qpkg/openHAB/configurations/scripts/pv.sh:10000:JS(pv.js)]"}

This is the result:
{00,17,01,2016,21,55,0003.4,00089,000089,00012053,00000,000,000.0,000,000.0,000,000.0,000,000.0,00},%

But I don’t understand how to get only the value that I have marked as bold. What I have tried is state.toString.split(",") but without success.

Any help?

Thanks
Michael

Hi Michael, what does pv.js look like. Your item is a number, so the JS transform should be returning an int. If your shell script is returning the above String then your JS file can look something like:
var str = input.split(","); result = parseInt(input[9]);
This of course has no error checking and assumes the value is in the same place (9) all the time. This is off the top of my head, so the above code could have errors :wink:

Taking a look at this. I’m interested in seeing your JS also, specifically what type of variable/object the result is stored as. I mocked up some JS below, @digitaldan was pretty close but his solution returns NAN. I think I am slightly off since I assumed you are starting with a string.

var input = "{00,17,01,2016,21,55,0003.4,00089,000089,00012053,00000,000,000.0,000,000.0,000,000.0,000,000.0,00}";
var str = input.split(',');
var result = parseInt(str[9]);
console.log(result);

When I run the above code in a console I get the string but it is just the true int version, ‘12053’ and does not have the leading zeros. If you want the leading zeros you will want,

var input = "{00,17,01,2016,21,55,0003.4,00089,000089,00012053,00000,000,000.0,000,000.0,000,000.0,000,000.0,00}";
var str = input.split(',')[9];
console.log(str);

Working now! Thanks!! :+1: