[SOLVED] MQTT configuration error

Hello all,
I managed to follow the various tutorials and flashed an Sonoff S20 and am able to switch it throug MQTT.fx.
Status updates can also be seen in mqtt sub.

Here is my problem:
I created a sitemap according to the tutorial and created a switch for the S20 but it doesn’t do anything.
In openhab.log I see the following entry:

[ERROR] [org.apache.felix.configadmin        ] - Cannot use configuration org.openhab.mqtt for [org.openhab.core.scriptengine.action.ActionService, org.osgi.service.cm.ManagedService, id=392, bundle=207/mvn:org.openhab.action/org.openhab.action.mqtt/1.10.0]: No visibility to configuration bound to mvn:org.openhab.io/org.openhab.io.transport.mqtt/1.10.0

my mqtt.cfg looks like this

#
# Define your MQTT broker connections here for use in the MQTT Binding or MQTT
# Persistence bundles. Replace <broker> with an ID you choose.
#

# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
<broker>.url=tcp://192.168.178.199:1883

# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a random default is generated.
#<broker>.clientId=<clientId>

# Optional. True or false. If set to true, allows the use of clientId values
# up to 65535 characters long. Defaults to false.
# NOTE: clientId values longer than 23 characters may not be supported by all
# MQTT servers. Check the server documentation.
#<broker>.allowLongerClientIds=false

# Optional. User id to authenticate with the broker.
#<broker>.user=<user>

# Optional. Password to authenticate with the broker.
#<broker>.pwd=<password>

# Optional. Set the quality of service level for sending messages to this broker.
# Possible values are 0 (Deliver at most once),1 (Deliver at least once) or 2
# (Deliver exactly once). Defaults to 0.
#<broker>.qos=<qos>

# Optional. True or false. Defines if the broker should retain the messages sent to
# it. Defaults to false.
<broker>.retain=<retain>

# Optional. True or false. Defines if messages are published asynchronously or
# synchronously. Defaults to true.
<broker>.async=<async>
# Optional. Defines the last will and testament that is sent when this client goes offline
# Format: topic:message:qos:retained <br/>
broker>.lwt=<last will definition>

my .items file looks like this:

Switch ki_plug1_SWITCH "Küche Steckdose 1" <light> (LR,gLight)
    { mqtt=">[broker:cmnd/sonoff_ki_plug1/POWER:command:*:default],<[broker:stat/sonoff_ki_plug1/POWER:state:default]" }

Number ki_plug1_WIFI "Küche Steckdose 1: WIFI [%d %%]" (gRSSI)
    { mqtt="<[broker:tele/sonoff_ki_plug1/STATE:state:JSONPATH($.Wifi.RSSI)]" }

String ki_plug1_VERBOSE "Living Room Light: MQTT return message [%s]"
    { mqtt="<[broker:tele/sonoff_ki_plug1/INFO1:state:default],
            <[broker:stat/sonoff_ki_plug1/STATUS2:state:default],
            <[broker:stat/sonoff_ki_plug1/RESULT:state:default]" }

//Maintenance
String  Sonoff_Action "Sonoff Action" <sonoff_basic>

my reachable.map looks like this:

Online=ON
Offline=OFF

my .rules file looks like this:

// Work with a list of selected Sonoff modules
val sonoff_device_ids = newArrayList(
    "sonoff_ki_plug1",
    "sonoff_sz_lightswitch"
    //... add all your modules here!

)
// OR
// Work with the grouptopic, addressing ALL modules at once
//val sonoff_device_ids = newArrayList("sonoffs")

rule "Sonoff Maintenance"
when
    Item Sonoff_Action received command
then
    logInfo("sonoff.rules", "Sonoff Maintenance on all devices: " + receivedCommand)
    for (String device_id : sonoff_device_ids) {
        switch (receivedCommand) {
            case "restart" :
                publish("broker", "cmnd/" + device_id + "/restart", "1")
            case "queryFW" :
                publish("broker", "cmnd/" + device_id + "/status", "2")
            case "upgrade" : {
                publish("broker", "cmnd/" + device_id + "/otaurl", "http://sonoff.maddox.co.uk/tasmota/sonoff.ino.bin")
               publish("broker", "cmnd/" + device_id + "/upgrade", "1")
            }
        }
    }
    Sonoff_Action.postUpdate(NULL)
end

Any suggestions?

Thank you in advance
Florian

Your posting is all be unreadable. Please use code fences.

Highlight the code and press the icon that has </> on the posting screen or

```
code goes here
```

Also, please see

From what I can guess you didn’t replace the <broker> in your configs with a name for your broker (e.g. “mosquitto”)

@Monsterflo I’ve done that for you. You can’t expect to receive an answer if you just barf everything in there. How are we supposed to make sense of it?

Now that the message is formatted @rlkoshak’s answer is the obvious one.
Please go through the whole tutorial to get a full understanding and a good working setup.

Best! Thomas

1 Like

Hello all,
sorry for the mess and thanks for the cleanup and help.

Do I have to replace the “broker” in all files?

Thanks for the help

Florian

yes, you have to replace everywhere.

  1. in the mqtt.cfg => there you can give the Broker a understable Name like “mosquitto”
  2. this Name (“mosquitto”) has to be replaced on every file you want to use this Broker

The reason behind this is you could add more than one Broker for different purposes.
again: please read the documentation and if unclear come back to us with questions, the question you asked was answered in the docs - and in the very first lines of mqtt.cfg here: (Replace < broker> with an ID you choose.):

#
# Define your MQTT broker connections here for use in the MQTT Binding or MQTT
# Persistence bundles. Replace <broker> with an ID you choose.
#

…if the docs are unclear, please tell us here, so we could update them for better understanding. Thanks!

2 Likes

Hello Thomas,

I followed the guide in the wiki step by step and couldn’t get it running. A working example configuration with reference to the used wildcards would be great.

Anyhow. I replaced every broker with 'mosquitto set the values back to standard (exept mosquitto.url=tcp://192.168.178.199:1883 and
mosquitto.clientId=openhab2_mqtt

Even after uninstalling mqtt action persistence and binding and reinstalling the mqtt binding the error remains:

[INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection '<broker>' [ERROR] [org.apache.felix.configadmin ] - Cannot use configuration org.openhab.mqtt for [org.openhab.core.scriptengine.action.ActionService, org.osgi.service.cm.ManagedService, id=291, bundle=207/mvn:org.openhab.action/org.openhab.action.mqtt/1.10.0]: No visibility to configuration bound to mvn:org.openhab.io/org.openhab.io.transport.mqtt/1.10.0

Most common solution was uninstalling and reinstalling the addon(s) but it obviously didn’t help.

Thanks
Florian

So there is a bug that I think has been fixed or at least is being fixed where if you delete a configuration from a cfg file it does not properly get deleted from OH’s active config file.

In short, because you tried to create an invalid <broker> config and have switched to using mosquitto the old invalid <broker> connection is still hanging around.

You can fix the problem easiest by stopping OH and then remove /var/lib/openhab2/config/org/openhab/mqtt.config and then restarting OH. The complaint about <broker> should go away. You should see something in the logs saying that it has connected to mosquitto. That mqtt.config file should reappear and no longer contain any reference to <broker>. If it does it is because you still have <broker> inside your mqtt.cfg file.

1 Like

It is alive!

Thank you Rich

1 Like

Not sure what you mean?

I think it would have been most helpful if the actual binding default config and README had been improved long ago. With the new MQTT binding on the verge, all this will be solved soon enough.