[SOLVED] String Items with MQTT

Hey guys,
I’m just getting started with MQTT - the ultimate goal is to control my irrigation using a relay switch.
So Openhab running on Raspi Pi with MQTT Broker sends Command via MQTT to NodeMCU which switches the relays on/off. To fully grasp what MQTT is doing I coded the NodeMCU to switch the relay when receiving a command.
On top the NodeMCU generates a “Hello World” Message in a topic.

in openhab I configured an items file with the switch:

Switch mqtt_Test "Testing..." (System) { mqtt=">[MQTT:mqtt/irrigation/relay1:command:ON:1], >[MQTT:mqtt/irrigation/relay1 :command:OFF:0]" }  

which is working fine.
I also configured a String item for the "Hello World Message (which could also be Temp sensor in the future) as follows:

String mqtt_status "MQTT:" (System) {mqtt="<[MQTT:mqtt/irrigation/status:state:default]"}

I do get the status updates in my logfile

2018-07-17 00:18:26.110 [vent.ItemStateChangedEvent] - mqtt_status changed from hello world #136 to hello world #137

But my sitemap remains empty

What am I doing wrong?

Have you written a .sitemap file?

I tried both:

Group item=System	
Text item=mqtt_status label="status"

Change your sitemap to:

Group item=System	
Text item=mqtt_status

and your item to:

String mqtt_status "MQTT:[%s]" (System) {mqtt="<[MQTT:mqtt/irrigation/status:state:default]"}

The label part is defined in the item, so no need to re-invent the wheel in the sitemap
Add [%s] in the label to tell OH to display the state (s is for string) in the label

Welcome to OH

1 Like

[%s] is what was missing…Duh!