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:
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”.
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
I went back to paperUI and linked channel with this item.
Created rule:
rule “sonofftripple_multitouched”
when
Item SonoffTripple1Remote received command
then
logInfo(“debugrule”, “update received”)
end
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.
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.
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.
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.
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:
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"
when
Item SonoffTripple1Remote received command
then
logInfo("debugrule", "update received")
end
Holding a button 1 produces a command, screenshot from MQTTFx:
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.
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 '127.0.0.1' with clientid embedded-mqtt-broker and file store '/var/lib/openhab2/mqtt/127.0.0.1'
2019-05-29 14:57:03.123 [hingStatusInfoChangedEvent] - 'mqtt:systemBroker:embedded-mqtt-broker' changed from OFFLINE to ONLINE
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.
That’s all from ui. No things, no links. Now your rules file can look like:
rule "test broker trigger"
when
Channel "mqtt:systemBroker:embedded-mqtt-broker:sonofftrippleMultitouch" triggered
then
logInfo("broker trigger debug", "triggered!")
end