Map item value to string

The Nuki binding returns the state of the lock as follows:
1 (Locked), 2 (Unlocking), 3 (Unlocked), 4 (Locking), …

I would like to map these states to ON, OFF or any other value.

In my items file, I’ve defined

String Office_frontdoor_state           "Voordeur"		<nukisl>        (gNukiOfficeState)      { channel="nuki:smartlock:NB_OFFICE_BACK_AND_FRONT_DOOR:SL_OFFICE_FRONT:lockState" [profile="transform:MAP", function=""] }

I’ve created a file as follows


But when I turn the lock, I don’t see any changes in events.log. What am I doing wrong?

Assuming your lock is setup and tested to work, that’s likely because your item definition is bad.
I’ve never seen that use of profiles so can’t tell if it’s supposed to work, but the common way would be

Number Office_frontdoor_state           "Voordeur [MAP(]"		<nukisl>        (gNukiOfficeState)      { channel="nuki:smartlock:NB_OFFICE_BACK_AND_FRONT_DOOR:SL_OFFICE_FRONT:lockState"  }

For testing purposes, create another Number Item and link to the same channel (to get confidence in your setup).

So far as I know, your profile should work … transform profile currently only works with String target Item, thats fine, it’s what you are doing.
You have to install the MAP service, but you’d have seen an error message if you hadn’t.

However, Markus’idea is sound. (Except you should use a Number Item)
Don’t transform the Item actual state - who cares if its numeric. You only need the conversion if/when you display it in the UI. Transform the displayed state.

I wanted to map it to a boolean (ON / OFF) so I could use a widget I’ve created. The OpenHab widget shows a selected icon for the ON value and another icon for the OFF value.

But because the native Nuki binding returns more values than ON or OFF, I wanted to map them.

But apparently, this isn’t the correct way. Can I accomplish the same with a rule?

You cannot map data types. It’s a matter of fact that it has more values than 0 and 1 (ON/OFF).
What you probably want is to map the display. That’s what my code above does. You should be able to use your widget there.

Upps, missed that in the first place.
Of course it should be a number (assuming that’s the data type your device uses).

1 Like

Fair point. The OH icon selector delivers based on “real” Item state, not after any transforming for display.

So you are forced into the kind of thing you tried to do. Worth playing with that a bit more.

You don’t need the key=value first line by the by, though it does no harm either.