Problem monitoring and setting MQTT values

Hey there :slight_smile:

I´m currently trying to set up my OpenHAB system, but it doesn´t work properly and unfortunately I have no idea what I´m doing wrong :frowning:
I hope someone can help me with this…

I have four MQTT topics which I want to subscribe to and display the last (retained) value and also want to be able to publish to those topics.
So I set up items which display the current value.

I set up my defaul.items as followed:

String testVal1 "Value1 [%s]" <house> { mqtt="<[mymosquitto:test/val1:state:default]" }
String testVal2 "Value2 [%s]" <house> { mqtt="<[mymosquitto:test/val2:state:default]" }
Number testVal3 "Value3 [%d]" <house> { mqtt="<[mymosquitto:test/val3:state:default]" }
Number testVal4 "Value4 [%d]" <house> { mqtt="<[mymosquitto:test/val4:state:default]" }

And the default.sitemap:

sitemap default label="Main Menu"
{
  Frame label="Test" {
  	Text item=testVal1
  	Text item=testVal2
  	Text item=testVal3
  	Text item=testVal4
   }
}

If I look at the openhab.app I see the test values I published:

(Values 2 and 4 are set to “retain”, Values 1 and 3 are not retained)

And I also get messages in the console that the items were updated to my published values…

After that I wanted to add a pushbutton which publishes a value to a topic:

Items: Switch testSwitch1 "Set Value1" <house> { mqtt=">[mymosquitto:test/val1:command:*:test_val]", autoupdate="false"}
Sitemap: Switch item=testSwitch1

But as soon I add this Switch item, most my values are no longer displayed - they only show a “-” as value…

Also if I delete my switch item, it still no longer displays my values. I have to restart OpenHAB to get the values displayed again…

-> I don´t know how to fix this?!
-> I wan´t to be able to choose from a few predefined values for my topics, is it possible to implement a drop-down menu to select the value to be published?

I hope someone can help me with that… Thank you in advance!

Best regards

I think you are not waiting long enough after saving your files. Changing your sitemap/items files will make values go undetermined. Wait a few minutes (seems like forever) and then publish some new value and I’m guessing you’ll see it.

Hello,

here is how I set a switch linked directly to an mqtt topic:
Switch AlarmSwitch "Alarme" <shield> (Published) {mqtt=">[broque:hm/cmd/alarm:command:on:default],>[broque:hm/cmd/alarm:command:off:default]"}

@tommycw10 waiting doesn´t seem to help. In the console I can see that my default.items has been reloaded and directly afterwards I get the messages that all my items states have been updated to the retained values, but they are not displayed (I waited 5min and nothing changed) - still only the “-”…
If I publish the values another time (also with retain = true) then they get displayed…

@1technophile I tried your AlarmSwitch - it publishes ON to the configured topic, but if I reload the page, the button is disabled again, so I can´t disable it so that it would publish OFF to the topic.
I also doesn´t know how to publish other values than ON and OFF, unfortunately the wiki page for the MQTT binding doesn´t helps me with this topic either :frowning:

…Even the example Switch from the MQTT Binding Wikipage doesn´t work :frowning:

Switch mySwitch {mqtt=">[mymosquitto:/myhouse/office/light:command:ON:1],>[mymosquitto:/myhouse/office/light:command:OFF:0]"} 

I only changed the broker to mine. I only can set it to ON, but then it stucks at ON and I can´t turn it off again :-/

EDIT: :skull_crossbones: The problem was the browser inside of the OpenHAB Designer! I just tried the Switch in Chrome and it seems to switch states as it should be… Now I was able to configure the items to recieve MQTT values and switches to publish MQTT values.

To be able to send any of a list of values from the UI, do something like:
item:

String myCommand "Command" { mqtt=">[broker:/topic:command:*:default]" }

sitemap:

Switch item=myCommand mappings=[STOP=Stop,START=Start,REWIND=Rewind,DELETE=Delete]

So you will get buttons Stop, Start, Rewind, and Delete in the UI, and pressing them publishes STOP, START, REWIND or DELETE messages to the topic on the broker.