I successfully can publish message from the OH rule engine to the local mqtt broker. Works like a charm.
rule "Temporarily unlock the door"
when
Item UnlockDoor received command
then
logInfo("SAH", "Unlock the door temporarily.")
val mqttActions = getActions("mqtt", "mqtt:broker:localbroker")
mqttActions.publishMQTT("sah/aarau/maindoor/lock/cmd", UnlockDoor.state.toString)
end
That tells me the broker is configured correctly - at least to accept messages to be published.
Anyhow, the rule does NOT receive messages from the mqtt channel defined thru PaperUI. I copied the channel after I have created it: mqtt:topic:maindoor:contact and added it to the rule.
rule "mechanical door bell pressed"
when
Item MechanicalDoorBell received command or Item MechanicalDoorBell changed
then
var msg = "The mechanical door bell was pushed."
sendBroadcastNotification(msg)
playSound("doorbell.mp3")
logInfo("SAH", msg)
//say(msg, "voicerss:enUS", "chromecast:audiogroup:PublicSpeakers", new PercentType(100))
end
Some observations I can confirm:
The ruleset file has no errors (as I know how it would be indicated by the log file)
The rule that publishes successfully to the mqtt broker is in the same ruleset file as the receiving rule, which is not working.
with MQTT.fx I can see that the message, which the rule should react on, arrives at the broker (I also did shut down the MQTT.fx client to make sure the message is not consumed before OH does).
I also tried to work with channels and triggered.
rule "mechanical door (channel) bell pressed"
when
Channel "mqtt:topic:doorbell:mechanicaldoorbell" triggered
then
var msg = "The mechanical door bell was pushed."
sendBroadcastNotification(msg)
playSound("bird.wav")
logInfo("SAH", msg)
//say(msg, "voicerss:enUS", "chromecast:audiogroup:PublicSpeakers", new PercentType(100))
end
I clearly miss out on how to configure the consumption of mqtt messages with items or channels, since the messages are evidently delivered to the mqtt broker. What am I missing from the documentation?
I have not clue how that would look like in the ItemChannelLink.json file after entered in the PaperUI.
In the Thing.json file I have found what you propably are looking for. Where the mechanicaldoorbell is matched with the topic sah/aarau/maindoor/mechanicaldoorbell of the mqtt broker
It is only a ON. (A OFF is never sent. It’s assumed to be the default state. A debouncer ensure the signal is only sent once every 5 seconds so that no one can storm-signal the mechanical door bell)
Right then your rules triggers are wrong:
The item doesn’t receive a command nor does it changes
Updates of items to the same value are not shown of the events log.
Change the trigger to received update
rule "mechanical door bell pressed"
when
//Item MechanicalDoorBell received command or
//Item MechanicalDoorBell changed
Item MechanicalDoorBell received update
then
var msg = "The mechanical door bell was pushed."
sendBroadcastNotification(msg)
playSound("doorbell.mp3")
logInfo("SAH", msg)
//say(msg, "voicerss:enUS", "chromecast:audiogroup:PublicSpeakers", new PercentType(100))
end