"ESP8266+OpenHAB" Getting Unwanted MQTT Message on ESP Boot

Hi… Im using MQTT on my ESP8266 that im flashing with Arduino IDE using PubSubClient library… When I boot the ESP8266 it always receives messages from my switch items in my sitemap even if i didnt changed them.

Im doing it simple, just subscribing 2 topics, one for each switch. But when it (ESP8266) connect to MQTT server, it receives 2 messages from the 2 topics saying 1.
I configured the bindings like this:



Its not supposed to receive because i didnt touch the switch… It was always off.
But i receive in my ESP8266 serial:

Connecting to PENSAO_ESTRELA <— my SSID

WiFi connected
IP address:
Attempting MQTT connection…connected
Message arrived [portaCasa/Topic] 1
Message arrived [portaPredio/Topic] 1

Why?! OpenHAB is publishing the switch state when ESP8266 subscribes to the topic?! Why?!

Is it possible you are configuring the topics to have “retained” messages? If so, when clients subscribe they will receive the last message published to the subscribed topic.

Thank You So Much Steve

How can I change that? Do you have any idea?

probably change this parameters i found on PubSubClient.h reference:

boolean connect (clientID, willTopic, willQoS, willRetain, willMessage)

Connects the client with a Will message specified.

clientID : the client ID to use when connecting to the server.
willTopic : the topic to be used by the will message (const char[])
willQoS : the quality of service to be used by the will message (int : 0,1 or 2)
willRetain : whether the will should be published with the retain flag (boolean)
willMessage : the payload of the will message (const char[])
false - connection failed.
true - connection succeeded

What can be the willMessage? do you know?

First, I should warn you that I’m not an expert on MQTT and it’s use in OH.

However, I believe those arguments are for the “last will and testament” message, which is something different.

When a message is published, the publisher sets a flag to indicate whether the message should be retained or not. In this case, OH is the publisher, right? There is a mqtt:.retain setting in openhab.cfg. If that is set to true, the messages will be published with the retain flag set.

I changed that in openhab.cfg. I set it false. And it keeps doing the same.

Everytime my ESP8266 reconnects to MQTT server. It receives the status of my switches.
Why? I don’t changed anything on the switch sides. It is supposed to receive the data (from my subscriptions) only when I change anything from the switch side (openHAB APP).

Isn’t it?