Transform the button state value directly on item

Hello,

i try to use transformations on an item using a trigger channel, but it won’t work as expected.

Target is to not deal with event numbers on higher levels like rules etc.

I followed the docs for transformations which says, that every transformation service has its own profile that can be used

Also, all Transformation Services provide a State Profile which allows you to do the transformation already on item-level instead doing it with a Sitemap. You can find the documentation of these Profiles within the Add-On documentation of the Transformation Service you would like to use.

So i tried the following for the Map Transformation service

String Sonoff_Mini_Switch_1_Button_State {channel="deconz:switch:homeserver:mini-switch-1:buttonevent" [profile="transform:MAP", function="sonoff.map"] }

with sonoff.map content

1002=PRESSED_SHORT
1003=PRESSED_LONG
1004=PRESSED_DOUBLE

But it won’t work, my item will not receive any event.

But when i change it to the profile “system:trigger-event-string”, it will receive an update, but just the number …

When i look to into the OH config page, only “Trigger Event String” can be chosen which would explain why it will not work with any other, but the comment on the doc page state something else imo.

What do i miss?

Best regards

Did you check access rights for sonoff.map?

Yes i did. The fact that using the map function in the Label works does indicate, that the permissions are set correctly imo.

not sure what you mean…

anyway, did you install map transformation add-on?

I mean i tried to use the map file for another item, but for the label in a sitemap

Default item=TestItem label="Test Label [MAP(sonoff.map):%s]"

So in general, the translation especially with this map file works

Yes

mapping is working on my side for v3.4 without problems at least for non-triggering channels.

Maybe mapping is not working for triggering channels? What version are you on? I know it has been introduced not too long ago to be able to link items to triggering channels.
For testing purposes try to add this item and mapping via GUI

edit:
Forgot to ask: does your item get updated when maping is deactivated?

That’s my fear too

3.3.0 … maybe an update to 3.4 is a chance

This is not possible via GUI. The only profile i could choose is the mentioned “Trigger Event String”, which works and does indeed make sense to a trigger channel.
But how is it then possible to map the technical values directly to a human readable string?

Like is said, i dont wan’t to deal with “when thing:channel:event triggered 1003” or something like this

Nope, only with the “Trigger Event String” profile

I just tried it. not working. Probably the same problem on your side:


I am not even able to select Trigger Event String

After reading the docs, it is clear that mapping does not work with triggering channels.
If your item works which is linked to a triggering channel, how about using state description?
Sure, that is converted after the item received the raw state but might give you what you need.

I tried this with

String Sonoff_Mini_Switch_1_Button_State {channel="deconz:switch:homeserver:mini-switch-1:buttonevent", stateDescription="" [profile="system:trigger-event-string", pattern="%d%%",options="1002=PRESSED_SHORT, 1003=PRESSED_LONG, 1004=PRESSED_DOUBLE"] }

But still, If I click the Button i get an log entry

Item 'Sonoff_Mini_Switch_1_Button_State' received command 1002
Item 'Sonoff_Mini_Switch_1_Button_State' predicted to become NULL

I am not familiar (anymore) with file based item definition…
I don’t think that pattern=“%d%%” is correct, maybe %d or even better %s.
Moreover, are you sure that trigger-event-string supports “options” for mapping?

What I meant with my previous post is to define

options="1002=PRESSED_SHORT, 1003=PRESSED_LONG, 1004=PRESSED_DOUBLE"] 

for your state description, but state description is “”

Again, I do not know how to define this with item files. How about for testing purposes defining your item through Main UI?

Is there a particular reason why you want to map it on channel level? You could do this also in your rule or GUI

Like i mentioned, i wanna map this at the lowest level as possible, since i don’t think it’s a good idea to deal in higher levels like rules with it.

Yes, rules itself might be an option to translate but for me it misleads the complete idea of mapping services since i think its exactly made for the case transforming from one value to another

Also its very annoying to always think about “what was 1002 about? was it short press? long press?”

Therefore, mapping it in rules is not really an option

I just adapted it from this post

But it also does not work with a string placeholder

This options is not for the profile, but for your mentioned state description approach. The profile is required to receive any change to the item … otherwise i’ll get nothing to the item.

the “options” are declared within the profile definition.

It has to be something like this:

String Sonoff_Mini_Switch_1_Button_State {channel="deconz:switch:homeserver:mini-switch-1:buttonevent",
stateDescription=""[options="1002=PRESSED_SHORT, 1003=PRESSED_LONG, 1004=PRESSED_DOUBLE"]}

Yes, like i did few posts above, doesn’t work anyway.

String Sonoff_Mini_Switch_1_Button_State {channel="deconz:switch:homeserver:mini-switch-1:buttonevent", stateDescription="" [profile="system:trigger-event-string", pattern="%d%%",options="1002=PRESSED_SHORT, 1003=PRESSED_LONG, 1004=PRESSED_DOUBLE"] }

really? I cannot see it as the syntax I was suggesting is different…
Not sure but there is a case where you have to add %s. Try

...stateDescription=""[pattern="%s",options="1002=PRESSED_SHORT,...

If tis does not work I’d really create a test item through MainUI to see if it works in general.
Then try to find the error in the syntax.

Yes, the only thing i have added (to receive an update to this item in general) was

profile="system:trigger-event-string"

and of course, i changed

pattern="%d%%"

to

pattern="%s"

But no change … i’ll try it on UI but doubt it will work … i think, trigger event items do not work well with all the translation stuff even if they imo would make really sense there

“%s”, not %s%

sorry, typo

Its strange. because if i add a test item to the UI, i cant choose the trigger channel at all there. Strange … but i saw there is another channel called only “button” instead of “buttonevent” which is not a trigger channel but can be used for my purpose because it changes to the the certain state … and tada … has working mapping

Anyway it would be good to clarify this “issue” anyway because i can think of situations where there is not such a “last pushed button” item