Temperature Definition - Foramting of an item no decimal

Here is my situation,

Where the actual temperature is 23.5 and not 235.0
I have an item edit with meta of [%2.1f °C] but of course won’t work.

Any suggestions?

Add an ‘Incoming Value Transformation’?

Things → [Your Thing] → Channels → [Your Channel] → Configure Channel → check ‘Show advanced’ → Incoming Value Transformation

( function(i) { return i / 10  } ) (input)

as a JSTransformation (place the code into a file divide_by_10.js and put JS:divide_by_10.js into the input box) should do the trick. IIRC, you would have to install the ‘Javascript Transformation’ add-on.

1 Like

I’ve got no screen like that in the channel settings.

Looks like your tuya Thing doesn’t support ‘Incoming Value Transformation’, but you should be able to use a Profile for conversion, see New Z-Wave hardware: Neo Coolcam PIR 5 in 1, NAS-PD07Z - #22 by Ap15e .

2 Likes

I managed to create a transformation.js file and map it with the metadata. That worked fine, but still if I have to make a rule and use that particular item, I should take for example the 21°C as 210, unfortunately.

If you use a profile like @anon71759204 recommends, it will transform the number before it gets to the Item.

1 Like

I’ve stack in here, as I have many transformations installed, including JS, but there is no way to apply a profile. Is there something to do with the edit in the item file and not in the UI?

You want to do a divide by 10 so you’ll want to use a JS transform. For something this simple you can use an inline transform as documented. In fact the example shown in the docs is exactly your use case, divide by 10.

1 Like

Now I’m trying to figure out the inline formatting.

Number:Temperature Living_FanCT "Living Room FCT Temp [JS(| input / 10):%.1f °C]" <temperature> { channel="tuya:tuyaDevice:38381801e868e770395e:temp_current" }

How does it look?

Fine I guess, but that’s just going to change the label. If you want to change it before it gets to the Item, you’ll have to use a profile. Items | openHAB

Would you mind giving an example?

Sure, since the examples that are at that link and the link to the JS Transformation add-on are not sufficient.

Number:Temperature Living_FanCT "Living Room FCT Temp [JS(| input / 10):%.1f °C]" <temperature> { channel="tuya:tuyaDevice:38381801e868e770395e:temp_current" [profile="transform:JS", function="| input / 10"]}
1 Like

That was helpful, thanks a lot, and of course thank you all for your time.
Now I’m trying to figure out how I could get one decimal back because it has disappeared :thinking: