Exploring OpenHAB Rule Automation in Version 3

I’ve been diving into the world of smart home automation with OpenHAB, and I must say, it’s been an exciting journey! Starting with OpenHAB 2.x, I managed to set up a few rules that really made my home feel smarter. One of my favorites was a rule that adjusted the living room lights when I pressed play or pause on Kodi. It was such a simple yet effective way to enhance my media experience. Here’s how it looked in the older version:

java
rule “Adjust living room lighting when Kodi Play/Pause”
when
Item AchterkamerKodiMediacenter_MediaControl changed
then
var String stateKodi = AchterkamerKodiMediacenter_MediaControl.state.toString()
switch (stateKodi.lowerCase) {
case “play” : {
if (achterkamerlampdimmer_DimmerSwitch2.getStateAs(OnOffType) == ON) {
achterkamerlampdimmer_DimmerSwitch2.sendCommand(0)
}
}
case “pause” : {
achterkamerlampdimmer_DimmerSwitch2.sendCommand(10)
}
}

Now, with OpenHAB 3, I wanted to recreate this rule using the Main UI for a more streamlined experience. However, I encountered some challenges. The rule didn’t work as expected, and I kept getting an error message about a mismatched input. I tried tweaking the configuration, adjusting triggers, and even recreating the rule from scratch, but nothing seemed to work. Here’s what my attempt in the Main UI looked like:

triggers:

  • id: “1”
    configuration:
    itemName: AchterkamerKodiMediacenter_MediaControl
    command: PLAY
    type: core.ItemCommandTrigger
    conditions:
    actions:
  • inputs: {}
    id: “2”
    configuration:
    itemName: achterkamerlampdimmer_DimmerSwitch2
    command: OFF
    type: core.ItemCommandAction

After some research and trial and error, I realized that the issue might be with how the rule was structured in the Main UI. I decided to revisit the rule file approach and noticed that I had forgotten to include the end keyword, which was causing the syntax error. Here’s the corrected version:

java
rule “Adjust living room lighting when Kodi Play/Pause”
when
Item AchterkamerKodiMediacenter_MediaControl changed
then
var String stateKodi = AchterkamerKodiMediacenter_MediaControl.state.toString()
switch (stateKodi.lowerCase) {
case “play” : {
if (achterkamerlampdimmer_DimmerSwitch2.getStateAs(OnOffType) == ON) {
achterkamerlampdimmer_DimmerSwitch2.sendCommand(0)
}
}
case “pause” : {
achterkamerlampdimmer_DimmerSwitch2.sendCommand(10)
}
}
end

This time, it worked perfectly! I learned a valuable lesson about the importance of syntax and the end keyword in OpenHAB 3. I’m really grateful to the OpenHAB community for their resources and support. If anyone has tips or tricks for optimizing rules in OpenHAB 3, I’d love to hear them!

Cheers to making our homes smarter one rule at a time! :rocket: