Hey everyone, I thought I’d share my recent adventure with configuring an MQTT switch in OpenHAB3. It was a bit of a puzzle at first, but I managed to crack it! Here’s what I learned.
I have a Sonoff RF Bridge flashed with Tasmota, controlling some lights that require separate RF codes for on and off. The MQTT topics for these actions are indoor/rfbridge/cmnd/rfkey1 for ON and indoor/rfbridge/cmnd/rfkey2 for OFF. My goal was to present a single toggle switch in the UI while using these two topics under the hood.
After some research and trial and error, I discovered that OpenHAB3 allows for custom switch configurations using the MQTT binding. By defining separate send commands for ON and OFF actions, I could map these to the respective MQTT topics. Here’s a quick breakdown of what I did:
-
Define the Switch Item: I created a switch item in my
items.cfgfile.
plaintext
Switch MyLightSwitch “Bedroom Light” {mqtt=“command:topic=indoor/rfbridge/cmnd/rfkey1,retain=false,qos=0;state:topic=indoor/rfbridge/stat/rfkey1,retain=false,qos=0”} -
Configure the MQTT Binding: I set up the MQTT binding to handle both ON and OFF commands. This involved specifying the topics for both actions in the
mqtt.cfgfile.
plaintextFor ON
command: topic=indoor/rfbridge/cmnd/rfkey1
For OFF
command: topic=indoor/rfbridge/cmnd/rfkey2
-
Test and Refine: I tested the setup by toggling the switch in the UI and monitoring the MQTT topics to ensure the correct commands were being sent. It took a few adjustments, but everything started working smoothly!
This experience taught me a lot about the flexibility of OpenHAB3 and how to work with MQTT in more complex setups. If anyone has questions or needs help with similar configurations, feel free to reach out! Happy automating! ![]()