[SOLVED] Sonoff rf bridge and 2way contacts?

Hm. I have developed this binding, I should know :slight_smile: and I did not consider on/off for open/close hence the warning.

BUT: As every good developer I’m lazy as and the same data type is used for all channel types. So on/off IS read in by the code also for TEXT, Numbers and even the contact type. Afaik if nobody has changed the code in the meantime it should not do anything for contacts however.

I’m not saying you dont know, I’m saying it does not make much sense as it is working with on/off and not without it…

So what is the correct way to define that 2way contact (different code for closed and different for open) which communicates with mqtt enabled rf bridge?

anyone?

can you please give me a hint of a syntax?
is it something like that?
(documentation is not really talking about chained map transforms at all)

Type switch : maindoor     "Main Door"     [ stateTopic="home/rfbridge/tele/RESULT", transformationPattern="JSONPATH:$.RfReceived.Data", transformationPattern="MAP:contacts" ]

and contacts.map should look something like this?

OPEN="44C20A"
CLOSED="44C20E"

OPEN="D9AA0A"
CLOSED="D9AA0E"

OPEN="45550A"
CLOSED="45550E"

I have the same issue yesterday, when I tried to add my 4 button Sonoff remote and use it in a rule…
The problem is, Openhab receives the command 41E00A. But it is neither an ON/OFF or OPEN/CLOSE command which is why you see the complaint.
In order to get it to work, I had to map each button to the RF bridge. Ie button A mapped to Key 1, button to Key 2 etc…

I then use the RF_Received_Key for triggering my rule to postupdate to a proxy item. But you should be able to let it do anything else.

My setup:
.things file

  Thing topic sonoffbm "RF Bridge" @ "second Room"    {
    Channels: 
        Type string : reachable     "Reachable"            [ stateTopic="tele/sonoffbm/LWT" ]
        Type string : recieveddata  "Received Data"        [ stateTopic="tele/sonoffbm/RESULT", transformationPattern="JSONPATH:$.RfReceived.Data"]
        Type string : recievedsync  "Received Sync"        [ stateTopic="tele/sonoffbm/RESULT", transformationPattern="JSONPATH:$.RfReceived.Sync"]
        Type string : recievedlow   "Received Low"         [ stateTopic="tele/sonoffbm/RESULT", transformationPattern="JSONPATH:$.RfReceived.Low"]
        Type string : recievedhigh  "Received High"        [ stateTopic="tele/sonoffbm/RESULT", transformationPattern="JSONPATH:$.RfReceived.High"]
        Type string : recievedrfkey "Received RfKey"       [ stateTopic="tele/sonoffbm/RESULT", transformationPattern="JSONPATH:$.RfReceived.RfKey"]
        Type switch : button1       "Button 1"             [ stateTopic="stat/sonoffbm/RESULT", commandTopic="cmnd/sonoffbm/RFKEY1", transformationPattern="JSONPATH:$.RfKey1" ]
        Type switch : button2       "Button 2"             [ stateTopic="stat/sonoffbm/RESULT", commandTopic="cmnd/sonoffbm/RFKEY2", transformationPattern="JSONPATH:$.RfKey2" ]
        Type switch : button3       "Button 3"             [ stateTopic="stat/sonoffbm/RESULT", commandTopic="cmnd/sonoffbm/RFKEY3", transformationPattern="JSONPATH:$.RfKey3" ]
        Type switch : button4       "Button 4"             [ stateTopic="stat/sonoffbm/RESULT", commandTopic="cmnd/sonoffbm/RFKEY4", transformationPattern="JSONPATH:$.RfKey4" ]
        Type number : rssi          "WiFi Signal Strength" [ stateTopic="tele/sonoffbm/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
    }

.items file

//-> Sonoff RF 
Group  GF_Sonoff_RF                "RF Bridge"                                  <sonoff_rf>     (Sonoff_RF)
String GF_Sonoff_RF_Reachable      "Reachable: [%s]"                            <contactable>   (GF_Sonoff_RF)               { channel="mqtt:topic:mosquitto:sonoffbm:reachable" }
String GF_Sonoff_RF_Received_Data  "Received Data: [%s]"                        <none>          (GF_Sonoff_RF)               { channel="mqtt:topic:mosquitto:sonoffbm:recieveddata" }
String GF_Sonoff_RF_Received_Sync  "Received Sync: [%s]"                        <none>          (GF_Sonoff_RF)               { channel="mqtt:topic:mosquitto:sonoffbm:recievedsync" }
String GF_Sonoff_RF_Received_Low   "Received Low: [%s]"                         <none>          (GF_Sonoff_RF)               { channel="mqtt:topic:mosquitto:sonoffbm:recievedlow" }
String GF_Sonoff_RF_Received_High  "Received High: [%s]"                        <none>          (GF_Sonoff_RF)               { channel="mqtt:topic:mosquitto:sonoffbm:recievedhigh" }
String GF_Sonoff_RF_Received_RfKey "Received RfKey: [%s]"                       <none>          (GF_Sonoff_RF)               { channel="mqtt:topic:mosquitto:sonoffbm:recievedrfkey" }
Switch GF_Sonoff_RF_Button_1       "Button 1: [%s]"                             <none>          (GF_Sonoff_RF)               { channel="mqtt:topic:mosquitto:sonoffbm:button1", autoupdate="false"}
Switch GF_Sonoff_RF_Button_2       "Button 2: [%s]"                             <none>          (GF_Sonoff_RF)               { channel="mqtt:topic:mosquitto:sonoffbm:button2", autoupdate="false"}
Switch GF_Sonoff_RF_Button_3       "Button 3: [%s]"                             <none>          (GF_Sonoff_RF)               { channel="mqtt:topic:mosquitto:sonoffbm:button3", autoupdate="false"}
Switch GF_Sonoff_RF_Button_4       "Button 4: [%s]"                             <none>          (GF_Sonoff_RF)               { channel="mqtt:topic:mosquitto:sonoffbm:button4", autoupdate="false"}
Number GF_Sonoff_RF_RSSI           "WiFi Signal Strength [%d %%]"               <wifi>          (GF_Sonoff_RF)               { channel="mqtt:topic:mosquitto:sonoffbm:rssi" }

And the rule:

rule "Sonoff Remote"
when
    Item GF_Sonoff_RF_Received_RfKey changed

then
        if(GF_Sonoff_RF_Received_RfKey.state.toString == "1") {
           logInfo("info", "Sonoff Remote Button A")
        Sonoff_RF_RemoteA.postUpdate(ON)
}

else
        if(GF_Sonoff_RF_Received_RfKey.state.toString == "2") {
           logInfo("info", "Sonoff Remote Button B")
        Sonoff_RF_RemoteB.postUpdate(ON)
}

else
        if(GF_Sonoff_RF_Received_RfKey.state.toString == "3") {
           logInfo("info", "Sonoff Remote Button C")
        Sonoff_RF_RemoteC.postUpdate(ON)
}

else
        if(GF_Sonoff_RF_Received_RfKey.state.toString == "4") {
           logInfo("info", "Sonoff Remote Button D")
        Sonoff_RF_RemoteD.postUpdate(ON)
}

end

At least I hope it gets you futher.

I need to again repeat that my setup WORKS
only thing I’m really kind of solving is unnecessary log warning, but at the end of the day … I can ignore it :wink:

It’s really not needed to define any RF contact as button (it does not make much sense as RF Bridge buttons should be used for switching things, not for receiving contact statuses), and as well rule and everything else is just not needed overhead.

I understand that. But the error you get is a real error. You cant use the ID for a on/off or open/close command. In cache you just want to get rid of the error visually, you could just log this one to a seperate logfile insted :wink:

I obviously can, it’s getting remapped by the binding

it’s not an ERR but WARN so I guess it’s not really an error :wink:

need bit of update, can you please give me syntax for chained transformations? I can’t find it in documentation at all.
Thanks

figured it out…
so now I have chained transformation where in map file i do have OPEN=“4xx” CLOSED=“4yy” and it works in terms of OH.
map file

OPEN="44C20A"
CLOSED="44C20E"

thing

Thing mqtt:topic:Contacts "Door & Window contacts" (mqtt:broker:home) @ "Other" {
Channels:
    Type contact : door_main         "Main Door"        [ stateTopic="home/rfbridge/tele/RESULT", transformationPattern="JSONPATH:$.RfReceived.Data∩MAP:contact_door_main.map"      ]
}

Anyway still getting the same warning in logs as in my first post.

tl;dr: chaining transformations has got same result as my original approach, both works, both have warning.

Has anybody actually solved this somehow?

any idea @David_Graeff ?

well bit weird behaviour couple of last days I’m experiencing with chained transformations.
I do have this in my logs (two logs about not supported by type is something I’m not able to solve thus ignoring it.) But it seems it can’t map data via map file anymore?
and on top of it, for all defined items it tries single code even when mapped to just one item via map file

2020-02-11 20:14:27.881 [WARN ] [rm.AbstractFileTransformationService] - Could not transform '44C20A' with the file 'contact_door_main.map' : Target value not found in map for '44C20A'
2020-02-11 20:14:27.882 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.
2020-02-11 20:14:27.882 [WARN ] [rm.AbstractFileTransformationService] - Could not transform '44C20A' with the file 'contact_door_side.map' : Target value not found in map for '44C20A'
2020-02-11 20:14:27.883 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.
2020-02-11 20:14:27.884 [WARN ] [rm.AbstractFileTransformationService] - Could not transform '44C20A' with the file 'contact_window_kitchen.map' : Target value not found in map for '44C20A'
2020-02-11 20:14:27.884 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.
2020-02-11 20:14:27.884 [WARN ] [rm.AbstractFileTransformationService] - Could not transform '44C20A' with the file 'contact_door_terrace.map' : Target value not found in map for '44C20A'
2020-02-11 20:14:27.885 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.
2020-02-11 20:14:27.885 [WARN ] [t.generic.ChannelStateTransformation] - Executing the MAP-transformation failed: An error occurred while opening file.
2020-02-11 20:14:30.600 [WARN ] [rm.AbstractFileTransformationService] - Could not transform '44C20E' with the file 'contact_door_main.map' : Target value not found in map for '44C20E'
2020-02-11 20:14:30.601 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.
2020-02-11 20:14:30.602 [WARN ] [rm.AbstractFileTransformationService] - Could not transform '44C20E' with the file 'contact_door_side.map' : Target value not found in map for '44C20E'
2020-02-11 20:14:30.602 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.
2020-02-11 20:14:30.603 [WARN ] [rm.AbstractFileTransformationService] - Could not transform '44C20E' with the file 'contact_window_kitchen.map' : Target value not found in map for '44C20E'
2020-02-11 20:14:30.604 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.
2020-02-11 20:14:30.604 [WARN ] [rm.AbstractFileTransformationService] - Could not transform '44C20E' with the file 'contact_door_terrace.map' : Target value not found in map for '44C20E'
2020-02-11 20:14:30.605 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.
2020-02-11 20:14:30.606 [WARN ] [t.generic.ChannelStateTransformation] - Executing the MAP-transformation failed: An error occurred while opening file.

but in my corresponding map file I do have this

OPEN="44C20A"
CLOSED="44C20E"

which is used like this

Thing mqtt:topic:Contacts "Door & Window contacts" (mqtt:broker:home) @ "Other" {
Channels:
    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"   ]
}

which in MQTT I can see incomming message in correct format

home/rfbridge/tele/RESULT {"Time":"2020-02-11T20:14:27","RfReceived":{"Sync":14040,"Low":480,"High":1380,"Data":"44C20A","RfKey":"None"}}
home/rfbridge/tele/RESULT {"Time":"2020-02-11T20:14:29","RfReceived":{"Sync":14090,"Low":480,"High":1380,"Data":"44C20E","RfKey":"None"}}

It tells you it’s looking up 44C20E in your MAP.
That’s not there.
Try

"44C20A"=OPEN
"44C20E"=CLOSED

huh i thought that syntax is

state=text

will try your suggestion

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