[SOLVED] Sonoff rf bridge and 2way contacts?

MAP is general purpose string lookup.
You might use it to turn state into label text, incoming data to state, text to another language, whatever.

Syntax is just
String_to_be_converted = string_to_be_returned

thanks, it worked ā€¦ kind of
ā€¦
I guess issue with OH in this case is the fact that in MQTT there is a information as ā€œDataā€:ā€œ44C20Aā€ and then OH tries to find this string in ALL files defined by the thing

Type contact : door_main         "Main Door"        [ stateTopic="home/rfbridge/tele/RESULT", transformationPattern="JSONPATH:$.RfReceived.Dataāˆ©MAP:contact_door_main.map"      ]
    Type contact : door_side         "Back Door"        [ stateTopic="home/rfbridge/tele/RESULT", transformationPattern="JSONPATH:$.RfReceived.Dataāˆ©MAP:contact_door_side.map"      ]
    Type contact : door_terrace      "Terrace Door"     [ stateTopic="home/rfbridge/tele/RESULT", transformationPattern="JSONPATH:$.RfReceived.Dataāˆ©MAP:contact_door_terrace.map"   ]
    Type contact : window_kitchen    "Kitchen Window"   [ stateTopic="home/rfbridge/tele/RESULT", transformationPattern="jSONPATH:$.RfReceived.Dataāˆ©MAP:contact_window_kitchen.map" ]
    Type contact : window_guestroom  "Guestroom Window" [ stateTopic="home/rfbridge/tele/RESULT", transformationPattern="jSONPATH:$.RfReceived.Dataāˆ©MAP:contact_window_guest.map"   ]

at first it might look like valid approach, as indeed OH canā€™t know if there isnā€™t defined same string somewhere else.
As per logs

2020-02-12 00:09:32.833 [WARN ] [rm.AbstractFileTransformationService] - Could not transform '44C20E' with the file 'contact_door_side.map' : Target value not found in map for '44C20E'
2020-02-12 00:09:32.834 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.
2020-02-12 00:09:32.838 [WARN ] [rm.AbstractFileTransformationService] - Could not transform '44C20E' with the file 'contact_window_kitchen.map' : Target value not found in map for '44C20E'
2020-02-12 00:09:32.839 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.
2020-02-12 00:09:32.840 [WARN ] [rm.AbstractFileTransformationService] - Could not transform '44C20E' with the file 'contact_door_terrace.map' : Target value not found in map for '44C20E'
2020-02-12 00:09:32.840 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.
2020-02-12 00:09:32.841 [WARN ] [rm.AbstractFileTransformationService] - Could not transform '44C20E' with the file 'contact_window_guests.map' : Target value not found in map for '44C20E'
2020-02-12 00:09:32.852 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.

you can see I do have 5 contacts defined, but only 4 errors. Thatā€™s because in one of the files there is 44C20E defined.

Thing is, I need to have it defined like that as then I wouldnā€™t know which contact gets opened or closed if they will be defined in one file, eg. one thing eg. all states defined in all files.

Any idea how to solve this?
I mean ā€¦ I can write a rule which will take the Data string and then trigger DummyItem accordingly, but it seems bit overengeneered as I should be able to map string into Thing directly, or is that the only way?

another approach (working one) is to define this directly as here:

    Type contact : door_main         "Main Door"        [ stateTopic="home/rfbridge/tele/RESULT", transformationPattern="JSONPATH:$.RfReceived.Data", on="44C20A", off="44C20E" ]
    Type contact : door_side         "Back Door"        [ stateTopic="home/rfbridge/tele/RESULT", transformationPattern="JSONPATH:$.RfReceived.Data", on="D9AA0A", off="D9AA0E" ]
    Type contact : door_terrace      "Terrace Door"     [ stateTopic="home/rfbridge/tele/RESULT", transformationPattern="JSONPATH:$.RfReceived.Data", on="45550A", off="45550E" ]
    Type contact : window_kitchen    "Kitchen Window"   [ stateTopic="home/rfbridge/tele/RESULT", transformationPattern="jSONPATH:$.RfReceived.Data", on="41E00A", off="41E00E" ]
    Type contact : window_guestroom  "Guestroom Window" [ stateTopic="home/rfbridge/tele/RESULT", transformationPattern="jSONPATH:$.RfReceived.Data", on="4EA80A", off="4EA80E" ]

Only downside is log warn complans about

Command '44C20E' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.44C20E

On the other hand, thatā€™s quite acceptable as I mentioned in my first post.

Yes, you chain a REGEX transform to ā€œpre-scanā€ the incoming string for your target codes on each channel. If there is a ā€œmissā€, the REGEX fails silently and never passes the code to the chained MAP transform to produce the error.

not sure, if it is working only on channels which are string, mine are contacts

All transformations are performed on strings. After that, the channel is responsible for delivering the appropriate state to the linked Item.

well if I have syntax right

transformationPattern="REGEX:(.*44C20*)āˆ©JSONPATH:$.RfReceived.Dataāˆ©MAP:contact_door_main.map"

Itā€™s not working, no errors in log, but no action in OH

is

REGEX:(.*44C20*)

correct to find 44C20A and 44C20E in this string: ?

{"Time":"2020-02-12T20:52:21","RfReceived": "Sync":14100,"Low":490,"High":1360,"Data":"44C20E","RfKey":"None"}}

and is order of the things in transformation pattern right? Shouldnā€™t be JSONPATH first, then REGEX and then MAP?

No idea, follow the suggested tutorial.

There is more than one way to do this. One way -
REGEX first to see if string contains ā€œkeyā€ - if so, pass whole string to
JSONPATH to do its usual thing
then MAP to convert to OPEN/CLOSED

To experiment with this stuff, create a new temporary String type channel and Item. You can use your REGEX on its own to see what you get.

figured it out
itā€™s

REGEX:(.*44C20?.*)

working without warns now. Downside is that you really need to define it on two places, but I guess itā€™s quite OK