Migrating Exec-Bindings from OH1 to OH2: A Success Story

Hey everyone! I’ve been diving into the world of smart home automation for a while now, and I wanted to share my recent experience with migrating from OpenHAB 1 (OH1) to OpenHAB 2 (OH2). For those of you who might be in the same boat, I hope this can help you avoid some of the pitfalls I encountered!

Earlier this year, I decided to fully commit to OH2 after years of using OH1. One of the biggest challenges I faced was translating my old exec-binding configurations into the new system. I remember spending hours searching forums and documentation, trying to find a straightforward solution. Let me walk you through how I tackled this.

In OH1, I had a simple setup for controlling a coffee maker using a TP-Link smart plug. The item looked like this:

plaintext
Switch swCoffee “Coffee” (gKitchen, gPlugs) {exec=“>[ON:/usr/bin/hs100.sh 10.0.0.62 9999 on] >[OFF:/usr/bin/hs100.sh 10.0.0.62 9999 off] <[/usr/bin/hs100.sh 10.0.0.62 9999 check:20000:]”}

The goal was to turn the coffee maker on and off with a simple switch. Sounds easy, right? But OH2’s approach to bindings is quite different, and I had to do some serious digging to get this working.

After some trial and error, I discovered that OH2 handles third-party devices through the Generic MQTT binding. By setting up a custom MQTT topic and payload, I was able to replicate the functionality of my old exec-binding. Here’s how I did it:

  1. Install the Generic MQTT Binding: This was straightforward through the Paper UI.
  2. Configure the MQTT Broker: I used my existing Mosquitto broker, but you can set up a new one if needed.
  3. Create the Switch Item: I defined a new switch item in my items.txt file, specifying the MQTT topics for publishing and subscribing.
  4. Set Up the MQTT Commands: I mapped the ON and OFF states to the appropriate commands for my TP-Link plug.

Here’s the final configuration that worked for me:

plaintext
Switch swCoffee “Coffee” (gKitchen, gPlugs) {
mqtt=“command:mqtt://cmnd/switch/coffee/set#ONOFF,
state:mqtt://stat/switch/coffee/state”
}

This setup allows me to control the coffee maker seamlessly through the OH2 UI, and it even updates its state in real-time!

Reflecting on this experience, I realize how much the community has helped me along the way. From detailed forum posts to helpful GitHub repositories, I wouldn’t have made it through this migration without you all. If you’re considering an upgrade to OH2, don’t be intimidated! Take it one step at a time, and remember—there’s a wealth of knowledge out there to guide you.

Cheers to all the tinkerers and automation enthusiasts out there! Let’s keep pushing the boundaries of what’s possible!

Best regards,
[Your Name]