Noob: Simple button which makes mqtt call

Hi Folks,

I’m a noob with openHAB…

I have:

  • OpenHab2 running on a RPi3.
  • Mosquitto setup on freenas jail and working
  • OpenHAB working with MiLight
  • OpenHAB is using JSONDB storage
  • I have set up mqtt in OH

Because I am using json storage I don’t have any item or thing files other than that in the jsondb folder.

I want to have a switch which sends an MQTT message but really cannot see how to do this. All examples I see and find use the “normal” (is it the normal?) flat-file item config. Nothing uses json.

I have the mqtt message which works - makes the milight rgb certain value.

Am I wrong in thinking a button should be able to do this? Or is it a rule that I need?
If I am not wrong, how do I put it into the json storage? I’ve tried and it fails to reload…

I’ve tried creating item files but they don’t seem to make a difference. I assume it’s because I am using the json storage…

TIA.

Cheers,
Crispin

This is because the MQTT binding is a 1.x version binding. Only .items files can be used with 1.x version bindings. You cannot bind an Item to a 1.x binding through the JSONDB, KAraf Console, PaperUI, et.

But, when you say you use the JSONDB, do you mean you are editing this file yourself? This file is not intended to be edited manually and you really need to stop OH before editing the JSONDB manually. Otherwise OH may not see your edits and/or may lose your edits when it dumps its memory into the JSONDB on a restart.

I’d have to see the message but without further information, I’d assume you can do this without a Rule. But be careful with your nomenclature. A"button" is a HABPanel widget and it only exists as a concept in HABPanel. For all the other UIs and for Items you have Switches et al. See the docs on Items for the full list.

You don’t. See above. You shouldn’t edit the JSONDB manually except when you are trying to fix a corruption or the like. And you cannot use the JSONDB at all if you are using 1.x version bindings.

No, the two can exist side by side. I suspect your first problem is that the JSONDB was not designed to be edited manually at runtime. Therefore OH doesn’t constantly watch that file for changes. And it creates a backup and dumps its current state out to the JSONDB on a restart (I think) so any changes you make would be lost.

Thanks for the reply.

Ok, so I “knew” that mqtt was a 1.x thing only. Does than mean I cannot use anything to do with it through the gui? Trying to understand the boundaries. I did edit the config to get it setup with vi. Thought that was all which was “not supported” by 2

no, not editing json other than to test. Noted that it’s not needed / should not happen.

Regarding what I am trying to do -
I want to send a message to mqtt lights/0x9B55/rgbw/3 with a value of {“status”:“on”, “command”:“set_white”}
If I send this message with another publisher the lights work as expected.

My expectation - which is mislead and seeking help - is that I would have a button (or switch?) which when “on” would send the above message. How would I do this?

thanks for the help!

Crispin

No.

openHAB 1.x Bindings do not provide things, so in Paper UI there is no way to use them. But Paper UI is for administration only, you should use Basic UI, Classic UI or HABpanel for manually controlling items.

So, the first step is to define items bound to mqtt.
The second step is, to build a Sitemap by using all items regardless is bound to openHAB1.x or openHAB2.x bindings.

That is correct. AperUI only supports 2.x bindings There is a 2.x version of the MQTT binding on the works but until it gets released the 1.x version is the only option for mqtt.

See the following for how to get started with mqtt.

Thanks for the replies. Due to work I have not slept since Friday night and nothing is making sense right now. Once recovered during the week I will revert.

Looking forward to understanding this all :slightly_smiling_face: