MQTT 2.5.1, with switch


I am experimenting with my new ESP8266 to start applying it to my projects.

I started simply by connecting a led but I had a problem related to the status.

When I change the switch from on to off, the LED turns on but the switch goes back to off, so I have to change the switch back to on, this does not affect the light of the LED, and for the off of the LED the same thing happens.

I’ve been reading that it could be that the status of the item is not updated or something related to that.

I leave you information about my code.


Bridge mqtt:broker:mosquitto "Mosquitto" @ "System" [ host="x.x.x.x", secure=false ]
    Thing topic prueba "S" {
            Type switch : verde1 [ commandTopic="esp8266/4", on="1", off="0"]


Switch Verde {channel="mqtt:topic:mosquitto:prueba:verde1"}


sitemap demo label="Menú"
    Frame label="Clima" {
		Switch		item=Verde

And in case you need part of the Arduino code that allows me to publish the status

      Serial.print("Changing GPIO 4 to ");
      if(messageTemp == "1"){
        digitalWrite(ledGPIO4, HIGH);
      else if(messageTemp == "0"){
        digitalWrite(ledGPIO4, LOW);
    if (client.connect("ESP8266Client")) {

Any help at all is welcome.


I believe the issue could be with not having a state topic aka response from arduino.

If I am reading correct you have a command sent from openHAB but no response coming back.

The thing for your device can have a state topic which is the response. Once you have this in your thing you need to add to arduino code.

Personally, I think it’s a defect in the MQTT binding. If no state update methods are defined in the channel, it should not be altering the linked Item. Write-only channels are allowed in openHAB in general.

(I think the binding actually interferes with autoupdate’s prediction rather than updating directly, but same principle.)

1 Like

@rossko57 this is a true statement that I did not think about. You can most certainly have a write only channel!

The OP probably does want to have his device publishing status and add stateTopic to his channel.
This was just a comment about the way it failed without.