Getting OH3 to receive Payload messages from RFBridge

Hello all, I’m new to OpenHAB and stuck on next steps for receiving payload information from my Sonoff rfBridge. I’ve followed this guide to set up a single channel that should receive a single string when I press an rF button: [Adding Things - Advanced | openHAB](https://Adding Things Advanced). The MQTT Broker Thing is running and I’ve created a new Generic MQTT Thing, but what is next? How do I view the string? when I look at the Model page, the string says ‘NULL’.

I’m running OpenHab 3 on Windows 10 as well as a Mosquitto broker on the same machine, I have verfied that the broker is receiving messages from the bridge.

UID: mqtt:topic:mosquitto:OpenGarage
label: OpenGarageSwitch
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:mosquitto
location: Garage
channels:
  - id: GarageStateString
    channelTypeUID: mqtt:string
    label: GarageStateString
    description: ""
    configuration:
      stateTopic: tele/sonoff-bridge/RESULT
      transformationPattern: JSONPATH:$.RfReceived.Data

If you go to the rf bridge webpage and then press the rf button do you see something like this:

08:11:03 MQT: tele/rf-bridge/RESULT = {"RfReceived":{"Sync":14060,"Low":460,"High":1380,"Data":"53D80A","RfKey":"None"}}
08:11:06 MQT: tele/rf-bridge/RESULT = {"RfReceived":{"Sync":14120,"Low":470,"High":1370,"Data":"53D80E","RfKey":"None"}}
08:11:16 MQT: tele/rf-bridge/RESULT = {"RfReceived":{"Sync":14040,"Low":480,"High":1350,"Data":"0EFE0A","RfKey":"None"}}
08:11:22 MQT: tele/rf-bridge/RESULT = {"RfReceived":{"Sync":14080,"Low":480,"High":1340,"Data":"0EFE0E","RfKey":"None"}}

Some rf remotes don’t work straight out of the box with the rf-bridge.

Hi there! Yes, That is what I see. Everything on the MQTT side seems to be working.

Are both the rf-bridge and the OH looking at the same MQTT broker?
Below is the from th einformation page of the rf-bridge.

MQTT Host 192.168.0.164
MQTT Port 1883
MQTT User DVES_USER
MQTT Client DVES_8247F1
MQTT Topic rf-bridge

Below is the mqtt broker thing.

image

1 Like

Update: I went back to the Generic MQTT Thing, clicked on the Channel, and then ‘Add Link to Item…’. I created a string Item and the data string is now updating correctly, however, the string is stored there and doesn’t reset. I found a section in the docs on creating a profile here:https://www.openhab.org/docs/configuration/items.html#profiles

Does this look like it might work? I’m planning on pasting this into the .items file.

I advise against using profile here.

The binding gives you transformation functions. Importantly, it allows you to chain two transformations together, so that you can for example select by some ID value and then extract another value.

@rossko57 , what about the ‘expire’ parameter? My thing code would look like this:

UID: mqtt:topic:mosquitto:OpenGarage
label: OpenGarageSwitch
thingTypeUID: mqtt:topic
configuration: {expire="5s,state=0"}
bridgeUID: mqtt:broker:mosquitto
location: Garage
channels:
  - id: GarageStateString
    channelTypeUID: mqtt:string
    label: GarageStateString
    description: ""
    configuration:
      stateTopic: tele/sonoff-bridge/RESULT
      transformationPattern: JSONPATH:$.RfReceived.Data
      allowedStates: On="44D476", Off="0"

Not sure what you want expire for, don’t you get key press and key release codes? Wouldn’t you want to use a switch channel?

An easy way to make the switches work is to get the codes from the rf-bridge and make a rule to do what you want to do when the code has been sent.

Below is an excerpt of a JavaScript rule as an example:

var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);
// var rfinput = itemRegistry.getItem('RFBridgekitchen_Receiveddata').getState();
var Exec = Java.type("org.openhab.core.model.script.actions.Exec");
var Duration = Java.type("java.time.Duration");
var TOPIC = null;
var PAYLOAD = null;

var rfinput = itemRegistry.getItem('RFBridgekitchen_Receiveddata').getState().toString();

switch(rfinput) {
//row 1 green and switch is on S
     case 'BB369E':
     events.sendCommand("CoffeeMachine_CoffeeMachine", 'ON');
       logger.info('Coffee machine ON');
    break;
     
 //row 2 green and switch is on S
     case 'BB369C':
     events.sendCommand("Phonecharger_Phonechargerbedroom", 'ON');
       logger.info('Phone charger ON');
    break;
    
  default:  
}

The rf-bridge Kitchen looks like this:

UID: mqtt:topic:0b73c672
label: RF-Bridge kitchen
thingTypeUID: mqtt:topic
configuration:
  payloadNotAvailable: Offline
  availabilityTopic: tele/rf-bridge/LWT
  payloadAvailable: Online
bridgeUID: mqtt:broker:mqttbroker
location: Bedroom
channels:
  - id: rfreceiveddata
    channelTypeUID: mqtt:string
    label: Received data
    description: null
    configuration:
      stateTopic: tele/rf-bridge/RESULT
      transformationPattern: JSONPATH:$.RfReceived.Data

@rossko57 I only receive a single ‘on’ code from my switches.

@ubeaut This looks like it will work, thank you so much. Question: If the rule is set to trigger when the RfBridge code is updated, what happens if I press the same button twice? For example, I press the rF switch to open the garage door and the rule is triggered, then when I want to close the garage door I press the same switch again to close. Does the rule look at that data ID and only trigger if the code changes? Or does it trigger every time the button is pressed, regardless of the ID.

Try the code and you will answer your question. :slight_smile:

Comment; if you only get “key pressed” events, and never “key released”, it’s not a good fit to an openHAB Item state. You can make it work that way, but there is no state really, only events.

MQTT binding allows you to set an “post command” channel option on incoming messages. Instead of the usual state update, it will instead generate an openHAB command event to the linked Item. This is acting more like a UI does, and is appropriate for a control keypad.

Or you can go the whole hog with “trigger” channel option, this triggers an event directly on openHAB event bus with no Item involved at all. Rules can be triggered directly from this.