Issue of the topic:rule doesn’t trigger
Hi, despite to some well explained examples about triggering channel in Cube rule with Xiaomi Gateway binding I didn’t discovered the same for a MQTT (zigbee2mqtt) based solutions
It seems channel id being not well specified (in the gateway bind, a serial number is required not present in the generic mqtt thing
So I wonder if I correctly specify the channel for triggerring the associated event
Items configuration related to the issue
mqtt.items&thing
String AqaraCubeAction "Cube action [%s]" <action> (gAqaraCube) { channel="mqtt:topic:mosquitto:testthecube:action" }
MQTT.Thing
Thing topic testthecube "Aqara Cube Test" {
Channels:
Type string : action "Action" [ stateTopic="zigbee2mqtt/testthecube", transformationPattern="JSONPATH:$.action"]
Type number : voltage "Voltage" [ stateTopic="zigbee2mqtt/testthecube", transformationPattern="JSONPATH:$.voltage"]
Type number : battery "Battery" [ stateTopic="zigbee2mqtt/testthecube", transformationPattern="JSONPATH:$.battery"]
Type number : linkquality "RSSI" [ stateTopic="zigbee2mqtt/testthecube", transformationPattern="JSONPATH:$.linkquality" ]
}
```csv
rule "Xiaomi Cube"
when
Channel "mqtt:topic:mosquitto:testthecube:action" triggered
then
var actionName = receivedEvent.getEvent()
...
// logInfo("xiaomi","action is {}",actionName) //<---
logInfo( "CUBO", "INFO: Channel Event = '{}'", actionName )
Sorry Vincent to bother you again but this is just my problem
the example you submit is the one where I started from but the difference is that I use a MQTT generic item not as specific as the MIHOME bind that refer its own channel id format
So again, can I trigger a MQTT channel event? Is my channel id correctly expressed in my rule (I assume the channel ID is ‘mqtt:topic:mosquitto:testthecube:action’
If both assumptions are YES then why my rule doesn’t trigger?
Quoting the Channel Configuratuon documentation: * **trigger** : If true, the state topic will not update a state, but trigger a channel instead.
Did you set trigger to true?
// Sonoff Basic
Thing topic basic03 "Sonoff Basic 03 Schreibtischlampe" @ "MQTT2" {
Channels:
Type switch : power "Power " [ stateTopic="stat/basic_03/POWER", commandTopic="cmnd/basic_03/POWER" ]
Type number : rssi "WiFi Signal Strength" [ stateTopic="tele/basic_03/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
Type string : version "Firmware Version " [ stateTopic="stat/basic_03/STATUS2", transformationPattern="JSONPATH:$.StatusFWR.Version"]
Type switch : reachable "Reachable" [ stateTopic="tele/basic_03/LWT",transformationPattern="MAP:reachable.map" ]
// Trigger String : powerx "Power x Trigger Test " [ stateTopic="stat/basic_03/POWER" ] // seems not to work with this syntax
Type switch : powerx "Power X" [ stateTopic="stat/basic_03/POWER", trigger=true ] // Trigger Channel; no need to define an item
}
.rules
rule "Test MQTT Events"
when
Channel 'mqtt:topic:hans:basic03:powerx' triggered
then
logInfo("test_channel.rules", " Channel triggerd: {} ", receivedEvent.getEvent) // test
logInfo("test_channel.rules", " Channel triggerd: {} ", receivedEvent) // test
end
Result:
2019-10-02 15:57:23.837 [INFO ] [home.model.script.test_channel.rules] - Channel triggerd: ON
2019-10-02 15:57:23.850 [INFO ] [home.model.script.test_channel.rules] - Channel triggerd: mqtt:topic:hans:basic03:powerx triggered ON
2019-10-02 15:58:34.777 [INFO ] [home.model.script.test_channel.rules] - Channel triggerd: OFF
2019-10-02 15:58:34.786 [INFO ] [home.model.script.test_channel.rules] - Channel triggerd: mqtt:topic:hans:basic03:powerx triggered OFF
I expect that is a consequence of openHAB connecting to MQTT broker and asking for the topic. A kind of REFRESH leading to an update.
It has to do that to find out if the topic is ‘retained’.
EDIT - it is debatable if an update (to UNDEF) should still be issued if no retained data is found on the broker - but that is what it does for now.
Considering for things like RSSI you are possibly going to want to display it on your UI sometimes, linking to an Item gives you that option.
There are occasional uses for profiles in conjunction with channels, these are only available for use with channels linked to Items. The fairly comprehensive transformation options for MQTT binding can usually take care of any needs there though.