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.
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.
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.
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:
}
@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.
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.