micware
(Michiel)
January 20, 2021, 9:37pm
1
Raspberry PI Openhab 3
MQTT binding 3
My channel “mqtt:topic:b8be661fe1:slaapkamer_wireless_wall_switch:action” can produce 3 strings “single_right”, “single_left” and “single_both”
I can see this in my event.log
2021-01-20 22:18:14.821 [INFO ] [openhab.event.ChannelTriggeredEvent ] - mqtt:topic:b8be661fe1:slaapkamer_wireless_wall_switch:action triggered single_left
How do i use this in a rule to react to one of the values?
The rule below gives no error , but its not working
//Wireless 2 button switch
rule "lamp on/off"
when
Channel "mqtt:topic:b8be661fe1:slaapkamer_wireless_wall_switch:action" triggered
then
var actionName = "receivedEvent.getEvent"
switch(actionName) {
case "single_left": {
StudeerkamerHuewhite_Dimmer.sendCommand(100)
logInfo("test", "Light ON")
}
case "single_right": {
StudeerkamerHuewhite_Dimmer.sendCommand(0)
logInfo("test", "Light OFF")
}
}
end
How do i get the value off my channel in my variable “actionName”
Something which might make this easier is to link your String Channel to a String Item, and then trigger when that Item has changed.
I think you can then use triggeringItem.state
in your subsequent rule, i.e.
switch(triggeringItem.state) {
...
}
Scroll down to the DSL rule in the post below, where I do what you’re ultimately after, in a slightly different way:
I recently received a zigbee Xiaomi Mijia Wireless Switch , which can trigger on:
Single click
Double clicks
Triple clicks
Quadruple clicks
Many clicks (anything over four clicks is sent as many)
Long press (hold)
Long press (release)
It will also output the duration of the long press.
Here is how I integrated into openHAB, via zigbee2mqtt and Mosquitto .
Prerequisites
Ensure the openHAB MQTT binding is installed (V2, not V1)
My Mosquitto MQTT broker is setup as per default.
Pair the device …
1 Like
rlkoshak
(Rich Koshak)
January 20, 2021, 10:04pm
3
This line of code sets actionName to the String “receivedEvent.getEvent”. That’s not meaningful. You want the actual string value from the event itself.
val actionName = receivedEvent
In OH 3 receivedEvent was changed from being an object that carries an event to just be the String value of the event.
But, if I were to set this up I’d do it in the Channel and use a mapping or JS transformation to convert the values to an appropriate Item state. Then there’s be no need for a rule at all.
1 Like
micware
(Michiel)
January 21, 2021, 5:08pm
4
Both of you explanations were very educational.
Thanks for that.
I’ve gotten it working with "val actionName = receivedEvent
I get the concept, but sometimes find it difficult to find the correct spelling (syntax) in DSL and other languages used in openhab
Thanks.
system
(system)
Closed
March 4, 2021, 9:22am
5
This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.