Connecting MQTT server with OpenHab

As a sample test, I just want to ON/OFF a bulb using OpenHab via wifi. So I connect the hivemq server and openhab as follows in the openhab configuration.

mqtt:broker.url=tcp://127.0.0.1:1883
mqtt:broker.clientId=openhab

So when starting openhab I can see following in the console.

2016-09-01 19:18:11.692 [INFO ] [.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2016-09-01 19:18:11.695 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting MQTT broker connection ‘broker’
2016-09-01 19:18:13.092 [INFO ] [penhab.io.rest.RESTApplication] - Started REST API at /rest

So it seems openhab and hivemq connected successfully. Then I created following file on openhab distribution.

home.sitemap

sitemap home label=“My House”
{
Frame label=“ESP Module”{
Group item=FF_Bed label=“Front Porch”
}
}

home.items

Group All
Group gGF (All)
Group gFF (All)

Group GF_Living “Living Room”

Dimmer Light_GF_Living_Table “Table” (GF_Living, Lights) {mqtt=“<[mybroker:/myHome/Table:command:ON]”}
Switch Light_FF_Bed_Ceiling “Ceiling” (FF_Bed, Lights) {mqtt=“<[mybroker:/myHome/doorbell:command:ON]”}

/* Locations */
Location HomeLocation MyHome

esp-pic.map

0=Still
1=Motion

I can see above specified items on my openhab site. But when I click on the light there are no updates from the MQTT server. But I can see following on OpenHab console.

2016-09-02 12:00:35.484 [INFO ] [runtime.busevents ] - Light_FF_Bed_Ceiling received command ON

So why it doesn’t publish this change to HiveMQ topic?

Thanks.

In your item definition the ‘<’ indicates an input (broker -> OH). To send a command, you must replace this with a ‘>’.

Thanks for reply. I changed it to

Dimmer Light_GF_Living_Table “Table” (GF_Living, Lights) {mqtt=“>[mybroker:/myHome/Table:command:ON]”}
Switch Light_FF_Bed_Ceiling “Ceiling” (FF_Bed, Lights) {mqtt=“>[mybroker:/myHome/doorbell:command:ON]”}

But still I couldn’t see anything on MQTT server. Here is how my interface looks like.

On further inspection, I see you are missing the <transformation> element from the item definition. See https://github.com/openhab/openhab/wiki/MQTT-Binding#item-binding-configuration-for-outbound-messages

For comparison, see my definition of a switch, sending the commands On and Off

Switch Light_FF_Bed_Table         "Bedside Lamp"             <switch>        (FF_Bed, Lights){mqtt=">[raspberryPI:/energenie/ENER002/444102/1:command:ON:On],>[raspberryPI:/energenie/ENER002/444102/1:command:OFF:Off]"}

You can use ‘*’ and ‘${command}’ to replace the <trigger> and <transformation> elements, to act as a wildcard and send the command as the data in the mqtt topic.