Mqtt binding issue in openhab2

Hello, i m new to openHab2. I am trying to set a switch in openhab2. If the switch is ON it should publish ON and if its OFF it should publish OFF. i have written following code in my items folder.

Switch switch “Bed room” { mqtt=">[broker:/bedroom/light:command:ON:ON],>[broker:/bedroom/light:command:OFF:OFF]" }

i have download mqtt binding from addon section of openhab2.

In mqtt.cfg i have

broker.url=tcp://localhost:1883

I m unable to see any thing in CONTROL section of openhab2 paper UI and basic UI.

What should i do?

Try it without the / before bedroom/light.

So
{ mqtt=">[broker:bedroom/light:command:ON:ON],>[broker:bedroom/light:command:OFF:OFF]" }

Thanks for your reply @Maurits28.

Tried still not showing anything on control pannel

Make sure OH can talk to your broker, check OH logs.
Forget about OH for a moment and check if you can control your device by sending commands manually using mosquitto_pub, MQTTLens or any other tool.
Once you have command working - copy the exact topic to your item configuration.

I have a very busy openHAB 2 installation and a completely empty Control page. It would be nice if there were something to go on that page, but oh well!

Normally you would create a sitemap and have Switch item=switch in it. Then the Basic UI or Classic UI would show you a switch. You can also turn the switch ON or OFF from the openhab> prompt, via the REST API, rules…

Thanks for reply .@AndrewZ
I tried it, command works perfectly fine.

thanks for suggestion @watou

My sitemap file is as follow.

Frame lable=“mqtt”
{
Switch item=switch lable=“Switch 1”
}

It do not show anything on basic UI and classic UI

Your sitemap has to have the correct spelling of “label” and be a complete sitemap, like

example.sitemap

sitemap example label="Example"
{
  Frame label="mqtt"
  {
  Switch item=switch label="Switch 1"
  }
}

Note that the file name and the name of the sitemap have to agree (“example” in this case).

Thanks, above it was my typing mistake i have stated same thing as above.

sitemap switch label="Menu"
{
   Frame label="mqtt"
  { 
    Switch item= switch   label="switch 1"
   }
}


My items file name is switch.items
Still it’s not showing me anything in basic UI.
@watou

So the name of your sitemap file is switch.sitemap? How are you telling the UI to use that sitemap?

@watou
yes my sitemap file name is switch.sitemap.

I don’t know how to tell UI to use sitemap.

Configuration is done in PaperUI, see screenshot - default sitemap. You can set it the same way for basicUI and classicUI.

It is in the docs:
http://docs.openhab.org/addons/uis/basic/readme.html#accessing-sitemaps

Thank you @AndrewZ @hmerk i got it.

if i have more than 1 sitemap file than how can i pass it?

And y i cant see in controls of PaperUI?

You would add ?sitemap=name to the end of the URL.

openHAB 2 has a bit of a split personality, where add-ons from 1.x are not fully represented in the UIs, and yet still provide critical functionality that works perfectly well and is mature and well understood code.

Normally you would have 1 main sitemap which you will set as a default in the UI configuration as it was shown by @hmerk earlier.
If you will ever need additional sitemaps for testing purposes - then you can append the sitemap name at the end of the URL.

Thanks @watou and @AndrewZ

1 Like