[SOLVED] Sonoff rf bridge and 2way contacts?

Hey folks,
I did some searching but not much really helped.
What is correct way how to accomodate 2way contact switch with rf bridge sonoff into OH2?
(2 way contact means its broadcasting code for closed and different for open)

I have it like this (and it is working) but log complains … so what is correct way?

Thing mqtt:topic:Contacts "Door & Window contacts" (mqtt:broker:home) @ "Other" {
Channels:
    Type switch : maindoor     "Main Door"     [ stateTopic="home/rfbridge/tele/RESULT", transformationPattern="JSONPATH:$.RfReceived.Data", on="41E00A", off="41E00E" ]
}

items:

Switch  Contact_MainDoor    "Main Door"          <door>         (gStoreChange)        { channel="mqtt:topic:Contacts:maindoor" }

sitemap:

		Switch item=Contact_MainDoor 	label="main door []" mappings=[OFF="Closed",ON="Open"]

and log:

2019-10-21 16:40:39.154 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '41E00E' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.41E00E
2019-10-21 16:41:01.755 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '41E00A' not supported by type 'OnOffValue': No enum constant org.eclipse.smarthome.core.library.types.OnOffType.41E00A

This solution works, it’s switching states as it should. But I would like to have it without log complaining.
Should I use Contact instead? if so … it’s complaining as well

2019-10-21 16:44:18.889 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '41E00A' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.41E00A

Thanks for hint

1 Like

after a while of messing with it, I can’t really say what’s causing log warning.

if I do define Thing in paperUI and then compare file config with json config they are identical to me, but paper defined item is not causing any warning in log. Both approaches works just fine.

Can anybody spot something?

this is part of paperui config

"configuration": {
            "properties": {
              "stateTopic": "home/rfbridge/tele/RESULT",
              "transformationPattern": "JSONPATH:$.RfReceived.Data",
              "off": "41E00E",
              "on": "41E00A"
            }

and this is how I have Thing file

Type contact : test     "test"   [
    stateTopic="home/rfbridge/tele/RESULT", 
    transformationPattern="JSONPATH:$.RfReceived.Data", 
    on="41E00A", 
    off="41E00E" 
]

file is causing this warning, but working just fine

[WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '41E00E' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.41E00E

Should I care or… not? :slight_smile:

Hi I’m not able to answer your question but I can confirm that this warning is appearing in my logs and all my Contact items were created in paper UI (i do not use text files for configuration). I guess it is some kind of check inside MQTT binding before transformation is applied (and should be done after transform?). Maybe @David_Graeff can tell us more?

I think this part should not be in the things file. This should be in your transformation file.

Transformation file example named test.js:

{
    (function(jsonString) {
        var data = JSON.parse(jsonString);
        var value = data.state_genOnOff;
        var output = "NULL";
        if (value == On) {
                 output = "ON";
        } else if (value == Off) {
                 output = "OFF";
        }
        return output;
    })(input)
    
}

Also make sure you have the transformation addon install via PaperUI.

it does not matter where transformation pattern is, it can be in things file (why not?)
thing created in paperui does have it in the config file as well

that would be an answer and as well slight bug to fix maybe

“on” and “off” only work on switches, not on contact types. They have a special meaning for switches, and are a kind of a replacement for the map transformation. If you want to perform a mapping for contact types you either need a JavaScript or a Map transformation after your JSON one. (You can have chained transformations since 2.5m1).

2 Likes

Thank you for explanation David but I’m not really sure how to interpret following case :
my channel is Contact type :

with following settings:

and item Rf_bridge_MainDoor is also Contact type

When contact become physically open, JSON transformation return value defined in Custom On/Open value field and item Rf_bridge_MainDoor is update from CLOSED to OPEN state but in same time I get this warn in log:

==> /var/log/openhab2/events.log <==

2019-10-23 09:38:16.568 [vent.ItemStateChangedEvent] - Rf_bridge_MainDoor changed from CLOSED to OPEN

==> /var/log/openhab2/openhab.log <==

2019-10-23 09:38:16.573 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '4BC30A' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.4BC30A

2019-10-23 09:38:16.577 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '4BC30A' not supported by type 'OpenCloseValue': No enum constant org.eclipse.smarthome.core.library.types.OpenClosedType.4BC30A

Is it still necessary to have additional transformation to get rid of this warn? and if yes how to write it in channel definition please?

sorry but this does not make any sense as they are used in paperui defined things

"configuration": {
            "properties": {
              "stateTopic": "home/rfbridge/tele/RESULT",
              "transformationPattern": "JSONPATH:$.RfReceived.Data",
              "off": "41E00E",
              "on": "41E00A"
            }

without on/off it does not work, so even contact have to have on/off defined in order to work properly.

If there were some changes, I can’t find in documentantion anything related… so what is the proper way how to define item and avoid warning?

Again I must say that my definition works, only thing I really wanted to point out is warning in logfile

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