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.
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…
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.