Does a JS profile transformation inherit units?

Hi all

I am adding my homemade air sensors into OH3 (stable release). The battery voltage is an item linked to an mqtt channel with Voltage property - it seems to work properly as the “V” unit is added.

I use a JS transformation to get the battery level

(function(voltage) {
var batt_level = (voltage - 3.5)/0.7;
return batt_level;
})(input)

and I define a dimensionless item

Question - why does the value still have the “V” unit as the parallel item linked to the same channel?

I cannot use use the %% label formatter, of course (it returns 1%).

Any explanation for this behavior?

Thanks
Max

I think you have a variation of this problem

The OH framework is applying the default channel formatting suggested by the binding to the output of your transform profile, in this case adding " V".
It’s not yet clear if/how they’ll fix this bug.

You should be able to circumvent by removing the units from the channel, and have MQTT deal with number only.

@rossko57

thanks - I will try it and post the results here.

Has the issue (bug?) already filed?

Max

Yes, as referenced in the other thread that you read

Almost there!

I have now reprogrammed my (ESP-based) sensor by deleting the battery voltage unit in the source code.

I also had to clean mosquitto DB according to this tutorial

In mosquitto, I read

openhabian@openhabHost:~ $ mosquitto_sub  -v   -t homie/esp_gateway/kidsBedroomTH/battery/#
homie/esp_gateway/kidsBedroomTH/battery/$name Battery
homie/esp_gateway/kidsBedroomTH/battery/$datatype float
homie/esp_gateway/kidsBedroomTH/battery 4.08

I am now able to link this channel to the existing equipment and getting voltage (w/o unit) and battery level (in %) right.

Thanks!
Max