Problems following standard MQTT example

  • Issue of the topic:
    I am follow the MQTT example here, but the switch state is not published over MQTT.
    https://docs.openhab.org/addons/bindings/mqtt1/readme.html

  • Platform information: Raspberry Pi 2 B

    • Hardware: Raspberry Pi 2 B
    • OS: Archlinux ARM
    • Java Runtime Environment: Zulu 8
    • openHAB version: 2

    In the log i see the following errors:


2018-01-21 00:44:26.559 [INFO ] [.dashboard.internal.DashboardService] - Stopped dashboard
2018-01-21 00:44:50.944 [INFO ] [er.internal.HomeBuilderDashboardTile] - Started Home Builder at /homebuilder
2018-01-21 00:44:53.393 [INFO ] [.dashboard.internal.DashboardService] - Started dashboard at http://192.168.0.10:8080
2018-01-21 00:44:53.415 [INFO ] [.dashboard.internal.DashboardService] - Started dashboard at https://192.168.0.10:8443
2018-01-21 00:45:10.493 [INFO ] [thome.model.lsp.internal.ModelServer] - Started Language Server Protocol (LSP) service on port 5007
2018-01-21 00:45:12.563 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'default.sitemap'
2018-01-21 00:45:17.367 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app
2018-01-21 00:45:17.555 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
2018-01-21 00:45:17.766 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
2018-01-21 00:45:18.349 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2018-01-21 00:45:18.357 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'mosquitto'
2018-01-21 00:45:27.694 [WARN ] [basic.internal.render.SwitchRenderer] - Cannot determine item type of 'mySwitch'
org.eclipse.smarthome.core.items.ItemNotFoundException: Item 'mySwitch' could not be found in the item registry
        at org.eclipse.smarthome.core.internal.items.ItemRegistryImpl.getItem(ItemRegistryImpl.java:70) [109:org.eclipse.smarthome.core:0.10.0.b1]
        at org.eclipse.smarthome.ui.internal.items.ItemUIRegistryImpl.getItem(ItemUIRegistryImpl.java:724) [155:org.eclipse.smarthome.ui:0.10.0.b1]
        at org.eclipse.smarthome.ui.basic.internal.render.SwitchRenderer.renderWidget(SwitchRenderer.java:55) [196:org.eclipse.smarthome.ui.basic:0.10.0.b1]
        at org.eclipse.smarthome.ui.basic.internal.render.PageRenderer.renderWidget(PageRenderer.java:172) [196:org.eclipse.smarthome.ui.basic:0.10.0.b1]
        at org.eclipse.smarthome.ui.basic.internal.render.PageRenderer.processChildren(PageRenderer.java:137) [196:org.eclipse.smarthome.ui.basic:0.10.0.b1]
        at org.eclipse.smarthome.ui.basic.internal.render.PageRenderer.processPage(PageRenderer.java:100) [196:org.eclipse.smarthome.ui.basic:0.10.0.b1]
        at org.eclipse.smarthome.ui.basic.internal.servlet.WebAppServlet.service(WebAppServlet.java:159) [196:org.eclipse.smarthome.ui.basic:0.10.0.b1]
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:848) [88:org.eclipse.jetty.servlet:9.3.22.v20171030]
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:584) [88:org.eclipse.jetty.servlet:9.3.22.v20171030]
        at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:71) [191:org.ops4j.pax.web.pax-web-jetty:6.0.7]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) [87:org.eclipse.jetty.server:9.3.22.v20171030]
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548) [85:org.eclipse.jetty.security:9.3.22.v20171030]
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226) [87:org.eclipse.jetty.server:9.3.22.v20171030]
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1180) [87:org.eclipse.jetty.server:9.3.22.v20171030]
        at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:284) [191:org.ops4j.pax.web.pax-web-jetty:6.0.7]
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:512) [88:org.eclipse.jetty.servlet:9.3.22.v20171030]
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185) [87:org.eclipse.jetty.server:9.3.22.v20171030]
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1112) [87:org.eclipse.jetty.server:9.3.22.v20171030]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) [87:org.eclipse.jetty.server:9.3.22.v20171030]
        at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:80) [191:org.ops4j.pax.web.pax-web-jetty:6.0.7]
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134) [87:org.eclipse.jetty.server:9.3.22.v20171030]
        at org.eclipse.jetty.server.Server.handle(Server.java:534) [87:org.eclipse.jetty.server:9.3.22.v20171030]
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:333) [87:org.eclipse.jetty.server:9.3.22.v20171030]
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251) [87:org.eclipse.jetty.server:9.3.22.v20171030]
        at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:283) [79:org.eclipse.jetty.io:9.3.22.v20171030]
        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:108) [79:org.eclipse.jetty.io:9.3.22.v20171030]
        at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:93) [79:org.eclipse.jetty.io:9.3.22.v20171030]
        at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.executeProduceConsume(ExecuteProduceConsume.java:303) [90:org.eclipse.jetty.util:9.3.22.v20171030]
        at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceConsume(ExecuteProduceConsume.java:148) [90:org.eclipse.jetty.util:9.3.22.v20171030]
        at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:136) [90:org.eclipse.jetty.util:9.3.22.v20171030]
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:671) [90:org.eclipse.jetty.util:9.3.22.v20171030]
        at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:589) [90:org.eclipse.jetty.util:9.3.22.v20171030]
        at java.lang.Thread.run(Thread.java:745) [?:?]
2018-01-21 00:45:27.738 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'mySwitch' for widget org.eclipse.smarthome.model.sitemap.Switch
2018-01-21 00:45:27.747 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item for widget org.eclipse.smarthome.model.sitemap.Switch
2018-01-21 00:45:27.751 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'mySwitch' for widget org.eclipse.smarthome.model.sitemap.Switch
2018-01-21 00:45:27.763 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'mySwitch' for widget org.eclipse.smarthome.model.sitemap.Switch
2018-01-21 00:45:27.766 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'mySwitch' for widget org.eclipse.smarthome.model.sitemap.Switch
  • Please post configurations (if applicable):
    • Items configuration related to the issue
Switch mySwitch {mqtt=">[mybroker:myhouse/office/light:command:ON:1],>[mybroker:myhouse/office/light:command:OFF:0]"}
Switch mySwitch {mqtt=">[mybroker:myhouse/office/light:command:ON:1],>[mybroker:myhouse/office/light:command:*:Switch ${itemName} was turned ${command}]"}```

  * Sitemap configuration related to the issue 
  
```php
sitemap default label="My first sitemap"
{
    Switch item=mySwitch label="Office Light"

}

Are you allowed to have 2 distinct channels with the same unique ID?

no, you should use different names for your Items to avoid conflicts (that can lead to the errors being logged in the OP)

Switch mySwitch1 {mqtt=“>…
Switch mySwitch2 {mqtt=”>…

@luk what are you trying to achieve here? send a telegram to MQTT with a string message for a payload?
maybe you are trying to create a rule that logs this string message? or to send it to another MQTT topic?
There are better ways to do such stuff… Describe what you want (and the devices you are using) and we can recommend methods

I’m just trying to get a test configuration to work without any use case, so i can see that openhab is set up correctly and capable of sending MQTT messages that i can receive. My configuration is taken without any changes from docs.openhab.org. If there is an error in this documention, someone should change it.

https://docs.openhab.org/addons/bindings/mqtt1/readme.html#example-outbound-configurations

I removed the second line from sitemap and item, still not working.
mySwitch.item

Switch mySwitch {mqtt=">[mosquitto:myhouse/office/light:command:ON:1],>[mosquitto:myhouse/office/light:command:OFF:0]"}
sitemap default label="My first sitemap"
{
    Switch item=mySwitch label="Office Light"
}

2018-01-22 11:12:43.362 [WARN ] [basic.internal.render.SwitchRenderer] - Cannot determine item type of 'mySwitch'
org.eclipse.smarthome.core.items.ItemNotFoundException: Item 'mySwitch' could not be found in the item registry
        at org.eclipse.smarthome.core.internal.items.ItemRegistryImpl.getItem(ItemRegistryImpl.java:70) [109:org.eclipse.smarthome.core:0.10.0.b1]
        at org.eclipse.smarthome.ui.internal.items.ItemUIRegistryImpl.getItem(ItemUIRegistryImpl.java:724) [155:org.eclipse.smarthome.ui:0.10.0.b1]
        at org.eclipse.smarthome.ui.basic.internal.render.SwitchRenderer.renderWidget(SwitchRenderer.java:55) [196:org.eclipse.smarthome.ui.basic:0.10.0.b1]
        at org.eclipse.smarthome.ui.basic.internal.render.PageRenderer.renderWidget(PageRenderer.java:172) [196:org.eclipse.smarthome.ui.basic:0.10.0.b1]
        at org.eclipse.smarthome.ui.basic.internal.render.PageRenderer.processChildren(PageRenderer.java:137) [196:org.eclipse.smarthome.ui.basic:0.10.0.b1]
        at org.eclipse.smarthome.ui.basic.internal.render.PageRenderer.processPage(PageRenderer.java:100) [196:org.eclipse.smarthome.ui.basic:0.10.0.b1]
        at org.eclipse.smarthome.ui.basic.internal.servlet.WebAppServlet.service(WebAppServlet.java:159) [196:org.eclipse.smarthome.ui.basic:0.10.0.b1]
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:848) [88:org.eclipse.jetty.servlet:9.3.22.v20171030]
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:584) [88:org.eclipse.jetty.servlet:9.3.22.v20171030]
        at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:71) [191:org.ops4j.pax.web.pax-web-jetty:6.0.7]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) [87:org.eclipse.jetty.server:9.3.22.v20171030]
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548) [85:org.eclipse.jetty.security:9.3.22.v20171030]
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226) [87:org.eclipse.jetty.server:9.3.22.v20171030]
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1180) [87:org.eclipse.jetty.server:9.3.22.v20171030]
        at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:284) [191:org.ops4j.pax.web.pax-web-jetty:6.0.7]
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:512) [88:org.eclipse.jetty.servlet:9.3.22.v20171030]
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185) [87:org.eclipse.jetty.server:9.3.22.v20171030]
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1112) [87:org.eclipse.jetty.server:9.3.22.v20171030]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) [87:org.eclipse.jetty.server:9.3.22.v20171030]
        at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:80) [191:org.ops4j.pax.web.pax-web-jetty:6.0.7]
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134) [87:org.eclipse.jetty.server:9.3.22.v20171030]
        at org.eclipse.jetty.server.Server.handle(Server.java:534) [87:org.eclipse.jetty.server:9.3.22.v20171030]
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:333) [87:org.eclipse.jetty.server:9.3.22.v20171030]
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251) [87:org.eclipse.jetty.server:9.3.22.v20171030]
        at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:283) [79:org.eclipse.jetty.io:9.3.22.v20171030]
        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:108) [79:org.eclipse.jetty.io:9.3.22.v20171030]
        at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:93) [79:org.eclipse.jetty.io:9.3.22.v20171030]
        at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.executeProduceConsume(ExecuteProduceConsume.java:303) [90:org.eclipse.jetty.util:9.3.22.v20171030]
        at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceConsume(ExecuteProduceConsume.java:148) [90:org.eclipse.jetty.util:9.3.22.v20171030]
        at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:136) [90:org.eclipse.jetty.util:9.3.22.v20171030]
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:671) [90:org.eclipse.jetty.util:9.3.22.v20171030]
        at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:589) [90:org.eclipse.jetty.util:9.3.22.v20171030]
        at java.lang.Thread.run(Thread.java:745) [?:?]
2018-01-22 11:12:43.393 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'mySwitch' for widget org.eclipse.smarthome.model.sitemap.Switch
2018-01-22 11:12:43.400 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item for widget org.eclipse.smarthome.model.sitemap.Switch
2018-01-22 11:12:43.403 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'mySwitch' for widget org.eclipse.smarthome.model.sitemap.Switch
2018-01-22 11:12:43.412 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'mySwitch' for widget org.eclipse.smarthome.model.sitemap.Switch
2018-01-22 11:12:43.415 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'mySwitch' for widget org.eclipse.smarthome.model.sitemap.Switch

Have you confirmed the broker is actually running using a 3rd party client like MQTTLens?

.items

https://docs.openhab.org/configuration/items.html#introduction

Your item config is ok, but you can try to simplify also:

Switch mySwitch {mqtt=">[mosquitto:myhouse/office/light:command:*:default]"}

https://docs.openhab.org/addons/bindings/mqtt1/readme.html#item-configuration-for-outbound-messages

Thanks, that solved it. I would mark as solution as well but i can only mark one post.

For others who read this, likely mistakes i ran into.

  • Don’t forget to install the mqtt binding from the ui.
  • In mqtt.cfg use protocol and address, for example mosquitto.url=tcp://localhost:1883 instead of just the address, whereas mosquitto_pub uses just the address
1 Like