Hi there,
I’m missing the JavaScript - Transformation Services in openhab 4.
How can I now make sure that my items which are linked to a float channel only hold integer values so they only trigger a change when a massive change happend and not somthing minimal.
So 45.67 to 45.66 shouldn’t trigger thats why I saved it to 45 in my item.
I used the following javascript transform script before:
(function (i) {
return parseInt(i) // The value sent by OH is a string so we parse into an integer
})(input)
I hope the function return till openhab 4 gets released. Or is there a other way to do this now?
[WARN ] [.thing.internal.CommunicationManager] - No ProfileFactory found which supports profile 'system:JS' for link 'MS_Werkstatt_Luftfeuchte -> deconz:humiditysensor:bridge:00158d00042fdca5010405:humidity'
Side-Topic:
With the update to openhab 3 I changed my complete textual configuration because of many advices from very popular community members. One year later now I’m changing everything back except the Things to textual configuration.
It just works so much quicker and easier for me.
I can rename via search-and-replace quickly and having a new sensor is most of the time copy and paste of one existing sensor plus two search-and-replace calls for the itemname and the channelid.
I’m so happy textual configuration is still possible.
Okay I recognized know that my problem is not to call the transform function in the profile.
The problem is that the function is not working if I use the simple function Math.round().
Add some logging (you can do that easily now in OH 4 because the JS Scripting helper library is available) and log out the intermediate steps. You can use console.log() in a transform.
If your Item has units (e.g. 12.34 W as opposed to 12.34) Number(data) won’t work. That will return NaN. But parseFloat is a little more flexible in that it will parse up to the first non-numeric character so will ignore the units.
@rlkoshak as very often you are my hero! Thank you so much not only for the solution but especially for the explanation. I learned already so much from your posts here in the forum.
Without people like you we wouldn’t be able to have a smarthome Thanks a lot.
data: 69.54 %
parseFloat(data): 69.54
Number(data): NaN