OH3 | Trigger rule + script not working

I am trying to create a rule / script that responds to my 6 button switch

I tried with a trigger rule that then starts a script but it didn’t work.

Rule:

triggers:
  - id: "1"
    configuration:
      thingUID: mqtt:topic:b8be661fe1:huiskamer_switch
    type: core.ThingStatusUpdateTrigger
conditions: []
actions:
  - inputs: {}
    id: "2"
    configuration:
      considerConditions: true
      ruleUIDs:
        - 2bc44a0f7f
    type: core.RunRuleAction

Script: (ruleUIDs: 2bc44a0f7f)

var actionName = receivedEvent
logInfo("Opple switch","Opple switch recived  command")
  
switch(actionName) {
        case "button_1_single": { scenes_switch_huiskamer_off.sendCommand(ON)    }
        case "button_2_single": { scenes_switch_huiskamer_work.sendCommand(ON)   }
        case "button_3_single": { scenes_switch_huiskamer_tv.sendCommand(ON)     }
        case "button_4_single": { scenes_switch_huiskamer_dinner.sendCommand(ON) }
        case "button_5_single": { scenes_switch_huiskamer_relax.sendCommand(ON)  }
    }
end

Then I thought! what if I use a .rules file, like I would in openHAB 2.X.

rule "Scene switch huiskamer"

 when
    Channel "mqtt:topic:b8be661fe1:huiskamer_switch:action" triggered 
 then

 var actionName = receivedEvent
 logInfo("Opple switch","Opple switch recived  command")
  
switch(actionName) {
        case "button_1_single": { scenes_switch_huiskamer_off.sendCommand(ON)    }
        case "button_2_single": { scenes_switch_huiskamer_work.sendCommand(ON)   }
        case "button_3_single": { scenes_switch_huiskamer_tv.sendCommand(ON)     }
        case "button_4_single": { scenes_switch_huiskamer_dinner.sendCommand(ON) }
        case "button_5_single": { scenes_switch_huiskamer_relax.sendCommand(ON)  }
    }
end

When I do that, the file is read by OH3 without errors. But the first lines are ignored (comment out)

anyone any idea what i am doing wrong?

This has nothing to do with channel event triggers. Thing status is something completely different (and is usually just permanently ONLINE).

Example of UI rule channel triggering here

Looks like there may be a UI bug and you have to hand-edit it?

I can’t imagine what you’re actually doing here.
You should only need to put your complete DSL rule in a file named xxx.rules in the /rules folder, no other action needed openhab.log should show if that loads okay.
Are you trying to import in the UI somehow?

Thank you for your comments Ross,

I have an Aqara Opple 6 way switch.
if I press button 1 the action channel changed to “button_1_single” and for button 2 “button_2_single” etc.

I can make a rule (main UI) for every singel button (6X), but “switch case rule/script in DSL” look like a beter solution!?

I made a DSL rule in a file named xxx.rules in the /rules folder
So I don’t know what you mean by “have to hand-edit it”

I have turned off the rules that I made via the UI
So that only the rule in the xxxx.rules file does its job.

When I look from the UI at the rule I created in the xxx.rules file the first 3 lines are ignored.

Let’s start with that.
What do the events in your events.log look like, that you are trying to trigger from?

My events.log shows:

2021-05-24 14:06:25.393 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Huiskamerswitch_Action' changed from button_1_single to button_2_single

This is an Item sate, not a channel state, I realize now.

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.