Trigger a rule by MQTT command?

I’m slowly going crazy here. I have Sonoff 3 gang T1 flashed with Tasmota. What I want is that single tap on it toggles relays, but that long press executes some complex action. I configured tasmota ok, checked and indeed Sonoff sends cmnd/sonofftrippleMultitouch/POWER1 HOLD when I hold button 1 for 1,5s.

Then I moved to rules file. I get it that above command needs an item configured to receive it, so I can use it as a rule trigger, but I don’t know how.

I’m using OpenHAB 2.5 M1 on Raspbian. I create Things using PaperUI and everything else in files. What I tried:

  1. usead already existing MQTT thing (for standard sonoff single-taps that work) and added 1 more channel (String type) named “sonofftripple1Multitouch”. Added MQTT command topic to it: “cmnd/sonofftrippleMultitouch/POWER1” and state topic “stat/sonofftrippleMultitouch/POWER1”.
  2. I created another item in my items file like:
    String SonoffTripple1Remote “Kitchen Light (Multitouch)” (gMQTT,gKitchen)
    { mqtt=">[mqtt:cmnd/sonofftrippleMultitouch/POWER1:command:*:default]
    … and also numerous variations of mqtt parameters with stat and cmd included/excluded
  3. I went back to paperUI and linked channel with this item.
  4. Created rule:
    rule “sonofftripple_multitouched”
    Item SonoffTripple1Remote received command
    logInfo(“debugrule”, “update received”)

What happends… long press on sonoff 1 does send cmnd/sonofftrippleMultitouch/POWER1 HOLD (checked with MQTT.fx client) but nothing happens. Event log stays empty.

1 Like
  1. That’s the old MQTT 1 syntax. In OH 2, ALL Channels are linked to Items in .items files the same way, as documented here. Remove everything between the { } and replace it with channel="<channel id> where the channel ID is shown in PaperUI.

  2. You may not need to configure the link since you’ve already done so in PaperUI, but I would not be surprised if the bad MQTT binding config there is causing problems.

  3. Did you toggle “Is command”? If not then all received messages will be treated as an update and the Rule will never trigger. Be careful though because if you check that box, since you have both a state and a command topic, you might end up in an infinite loop. You would probably be better off separating the topics into separate Channels linked to different Items or changing your Rule to trigger on updates instead of commands.

Thx. So that’s why item was not linked automatically as all my other items :slight_smile: Someties it’s hard to track all different versions in tutorials.

Anyway, I deleted links, recreated items correctly and they autolinked, deleted state topic, left only command topic and enabled “is command”.

… but still nothing in my logs and Sonoff is sending command ok.

Do you have Simple mode turned on? If not then there is no automatic linking of Items to Channels. If you do have it turned on, then there may be a bug where Channels that don’t get automatically created do not automatically get Items created and Channels linked.

[ I freaking hate Simple mode ].

Show your MQTT Thing’s configuration. A screenshot is fine in this case.

I don’t have simple mode turned on. When I said links got autolinked now, what I ment was that item created in items file appeared under “Linked items” of the channel. This is my thing config. I’m working on the last one:

This is channel config:

In my mqtt.items file there is the line:
String SonoffTripple1Remote "Kitchen Light (Multitouch)" (gMQTT,gKitchen) {channel="mqtt:topic:df1d9de2:sonofftripple1Multitouch" }

My sonofftripple rules file:

rule "sonofftripple_multitouched"
    Item SonoffTripple1Remote received command
    logInfo("debugrule", "update received")

Holding a button 1 produces a command, screenshot from MQTTFx:

Unselect ‘is command’, add a state topic, and change your rule trigger to use ‘received update’.

Did that earlier, but tried again. No change.

I’ll try from start to create different MQTT generic thing binding separate from current sonoff one, and configure item and rule from scratch again. I’m running out of ideas.

Strange. To eliminate the rule as an issue, did the Item state get updated? You could check it in a UI, the console, or the events.log.

Nope, nothing, no state update, not a single log output.

But rebooting machine discovered some warnings that might be some leads. Checking it now.

Still no clue. Log showed me I had some item links defined through UI (was warning me of duplicated). I deleted all those and let all be defined from items file. Those warnings went away but problem remains.

Second error in log was:

019-05-29 14:57:02.718 [hingStatusInfoChangedEvent] - 'mqtt:systemBroker:embedded-mqtt-broker' changed from OFFLINE (CONFIGURATION_ERROR): The system connection with the name embedded-mqtt-broker doesnt exist anymore. to OFFLINE

but I guess it is booting process, while mqtt broker is still not up. Just a scond later it goes online:

2019-05-29 14:57:02.834 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to '' with clientid embedded-mqtt-broker and file store '/var/lib/openhab2/mqtt/'

2019-05-29 14:57:03.123 [hingStatusInfoChangedEvent] - 'mqtt:systemBroker:embedded-mqtt-broker' changed from OFFLINE to ONLINE

What did you set the state topic to, and do you see it come in on the mqtt client?

stateTopic. state/sonofftrippleMultitouch/POWER1

BTW, from my understanding now this is not possible. First, if I use MQTT client and issue state/sonofftrippleMultitouch/POWER1 HOLD then state of the item is updated. But if I issue command topic, nothing happens. Further reading suggests this is by design of MQTT and binding. Item LISTENS on state topic but command topic it only uses to SEND.

I checked this topic: [SOLVED] New MQTT 2.4 - incoming State works, incoming Command does not

… and it appears to be what I’m experiancing, although I’m on OH 2.5M1

Now I’m looking for event bus option or channel triggers like mentioned in that topic.

Oh yes, SOLVED! So many articles out there about Item proxy, “is command” but I guess it is all wrong or outdated for MQTT2 / OH2.5M1

Solution is in above link and in docs here:

So, no item proxies, what you need to do is create a channel on MQTT broker binding (I’m using embedded one), using Paper UI, with those settings:

That’s all from ui. No things, no links. Now your rules file can look like:

rule "test broker trigger"
    Channel "mqtt:systemBroker:embedded-mqtt-broker:sonofftrippleMultitouch" triggered
    logInfo("broker trigger debug", "triggered!")