Number thing channel without dimension to be used as percent value

I have a (z-wave) thing which provides a number channel without dimension. This actually shows humidity value but instead of getting 44 %, I get 44, not even 0,44.
When I add display metadata with %unit% then it shows 44 one.
Is there any way to convert it to a real percentage value?

Ideally, you’d correct the zwave device database to indicate the correct channel type.

Meantime, a transform profile could append " %" to an update to a Number:Dimensionless type Item.

I haven’t seen the database yet, but I’ll give it a try :slight_smile:

Ok, so I set a REGEX profile between the channel and the item like this:

s/(.*)/$1 %/g

As I don’t know how to force the device to update it’s state, I have to wait until it happens automatically… :crossed_fingers:

Unfortunately item is not updated based on the above REGEX transformation, what am I missing? :thinking:

2021-10-24 18:04:58.795 [DEBUG] [ss.ZWaveMultiLevelSensorCommandClass] - NODE 18: Sensor Type = RelativeHumidity(5), Scale = 0
2021-10-24 18:04:58.796 [DEBUG] [ss.ZWaveMultiLevelSensorCommandClass] - NODE 18: Sensor Value = 41.1
2021-10-24 18:04:58.796 [DEBUG] [ding.zwave.handler.ZWaveThingHandler] - NODE 18: Got an event from Z-Wave network: ZWaveMultiLevelSensorValueEvent
2021-10-24 18:04:58.796 [DEBUG] [ding.zwave.handler.ZWaveThingHandler] - NODE 18: Got a value event from Z-Wave network, endpoint=9, command class=COMMAND_CLASS_SENSOR_MULTILEVEL, value=41.1
2021-10-24 18:04:58.796 [DEBUG] [erter.ZWaveMultiLevelSensorConverter] - NODE 18: Sensor conversion not performed for RELATIVE_HUMIDITY.
2021-10-24 18:04:58.796 [DEBUG] [ding.zwave.handler.ZWaveThingHandler] - NODE 18: Updating channel state zwave:device:controller:node18:sensor_relhumidity9 to 41.1 [DecimalType]

I gave up regex, even the simplest (.*) didn’t work, item wasn’t updated.
So I used JS transform:

(function(i) {
    return parseFloat(i) + " %";
})(input)

After this the item is updated with sensor data, unit is not displayed which surprises me, but the UoM should be correct, because the group value is correct this way (avarage humidity).
I tried to use the advanced “State Formatter” on the profile with several formats (eg: %.0f %unit%) but every time the item lost it’s % UoM and reverted to “one” and messed up average calculation on group.
Finally I left the state formatter empty on the profile and put the same into the item’s state description pattern and voila, it is displayed as I wanted (eg: 41 %) at last.

I think it should have worked with the profile’s state formatter, am I missing something? I’m on OH 3.2.0.M3.

REGEX like other transformations, is an installable add-on.
When used in a profile, it is very difficult to obtain diagnostic info.
Trialling a transform in a rule can produce more help.

var results = transform("REGEX", "s/(.*)/$1 %/g", "3.142")
logInfo("test", "extracts " + results)

2021-10-24 19:08:13.469 [INFO ] [.eclipse.smarthome.model.script.test] - extracts 3.142 % %

Which I think will upset the units parsing, % % not being a valid unit.

Have you discovered your events.log? That should show you Item state changes.

That is about formatting between channel and profile, i.e. pre-formatting "41.2"or whatever before handover to your transformation.

Thanks for the tip, now I can see the problem.
I was viewing the event.log and based on that I wrote:

Although I don’t really understand why that regex returns two matches, as in my understanding .* should match everything except line ends and the sensor returns float value… :thinking:
So by using s/(.*)/$1 %/ it is working (I removed the global option which I borrowed from the addon’s documentation) the same way as with JS, the display doesn’t show % sign, but UoM is %. When adding %.0f %unit% to the profile state formatter, the UoM is again “one” not a precentage which is strange :man_facepalming:

That’s a presentation issue then, look to the Item’s state presentation metadata, ‘pattern’ in particular.

Yes, this still operates on the data passed from the channel to the transformation. It will not affect the presentation of the Item’s state in a UI.

I understand, however it’s not intuitive imho.
Maybe sometime all bindings will have an option on their channel configuration page where the Unit could be set like for Number channels in HTTP binding, that’s a great feature! :+1: