micware
(Michiel)
May 23, 2021, 7:41pm
1
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?
rossko57
(Rossko57)
May 23, 2021, 10:30pm
2
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
Yes, I can.
By creating a garbage rule and then overwriting it with the proper YAML code:
triggers:
- id: "1"
configuration:
event: SINGLE
channelUID: mqtt:topic:autoPogoNAS:9F306C:Button1
type: core.ChannelEventTrigger
conditions: []
actions:
- inputs: {}
id: script
configuration:
type: application/vnd.openhab.dsl.rule
script: |
// context: mqtt-1
logWarn("ButtonLog: ", "SINGLE")
type: script.ScriptAction
I’m able to achieve exp…
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?
micware
(Michiel)
May 24, 2021, 7:21am
3
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.
rossko57
(Rossko57)
May 24, 2021, 10:20am
4
Let’s start with that.
What do the events in your events.log
look like, that you are trying to trigger from?
micware
(Michiel)
May 24, 2021, 12:13pm
5
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
system
(system)
Closed
July 5, 2021, 4:14am
6
This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.