Mqtt and switch

Hi
I m trying since a while to have a switch that Will receive on or off from an external mosquitto.
I installed the mqtt service but nothing move for the switch
Do you have an exemple to share and tell me how to install mqtt in openhab
Thx

Hello, we will need to know a bit more about your setup and what are you are trying to achieve.
Which version of Openhab have you installed and which version of the mqtt binding?
If it is the more recent 2x version of the binding in principle you will have to create a broker thing which connects to your mentioned instance of mosquito that you have running. You can find information on this here:


Than once this Broker Thing is successfuly connected to your mosquito broker you have to create a generic mqtt thing associated with the broker thing and in it a channel of type switch that subscribes to your state/command topics of the switch (https://www.openhab.org/addons/bindings/mqtt.generic/).
You than have to create an item of type switch linked to this channel.
Best regards Johannes

hi,

i use openhabian 4.2.1 on raspberry pi 3B+
i use external mosquitto as a broker

when i start openhab i seems that the binding with external broker (on 192.168.0.6:1883) is ok :

2019-07-22 14:19:32.158 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to ‘192.168.0.6’ with clientid paho496327007958297 and file store ‘/var/lib/openhab2/mqtt/192.168.0.6’

cat /etc/openhab2/services/mqtt.cfg

[14:24:10] openhabian@openHABianPi:/etc/openhab2/services$ cat mqtt.cfg
pid:org.openhab.mqtt
mqtt:mysensor.url=tcp://192.168.0.6:1883
mqtt:mysensor.clientId=openhab
mqtt:mysensor.qos=1

i use binding-mqtt - 2.4.0

The goal is to have a switch (object) manageable with : mosquitto_pub -t “myswitch” -m “on”
or
mosquitto_pub -t “myswitch” -m “on”

Do you have an example to help me starting?

thx

When using this binding the file “mqtt.cfg” is NOT used!
Please read the documentation on the actualy used binding ( as posted above, the documentation is here).
Note that there are lots of forum post that relate to the older binding!