MQTT messages tha arrive from noware

Hi there all,
I have a Hassio installed on my Qnap like docker
and I used for some thinks

One of this is automation that open and close a chicken coop then the sun sunrise/set.

My big problem is that some time the automation is call to send MQTT message
but the sun is not sunrize and is not set.
Here is an example at 10:09 o clock:
2019-10-23 22:09:42 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on pollaio/switchStatus: b'1'

I also put the MQTT in debug mode but I still don’t know where the MQTT message comes from :frowning:
At last I like to know the IP of publisher.

Is there some possibility to know more information about the MQTT messages please ?

Thanks a lot
Denis

Seems to me that your device that is monitoring the switch status is dropping and reconnecting to mqtt with retained messages.

Is that really a problem or does it report wrong switch status?

I had a similar problem with an esp8266 connected to my gate. It would drop off the WiFi from time to time and everytime it reconnected it would trigger. I fixed it by adding a range extension outside.

Yes… the device (that is a NodeMCU) is connect to Hassio MQTT server every time that is powered on.
But when I make a test all work and all is ok.
I use a retained messages.

But if I let the switchStatus=0 and in the morning this status is 1 … who change it ?
Who send the 1 command to the NodeMCU ? …this is my problem.
I can’t undestand where or what I can do in order to monitor who’s the bad boy

Thanks all again
Denis

Hope this helps: https://www.youtube.com/watch?v=31IyfM1gygo
And this: https://www.youtube.com/watch?v=dbSw6VkI-x4

Cheers, Richard

What are you running on the nodemcu (config/code)? Details of your hw schematics?

Give us something more that “this doesn’t work” :slight_smile:

Dera all,
thanks for the help.

First of all I don’t know why I don’t receive a mail when somebody answer in my topics :frowning:

So… the hw that I use is a NodeMCU and a step motor that open and close the door.
Here is a picture :slight_smile:

I also use a program that I write using the Ardiono IDE and for the MQTT gestion I used the PubSubClient.

So like I read here on the Hassio site, if messages in this state_topic are published with RETAIN flag, the sensor will receive an instant update with last known value.

For this reason in the configuration.yaml I have set retain: true
but now that I so the video on youtube (thanks a lot for that) maybe I understand
that only the status topic must be retained… and no the command topic.
So for now I set retain: false in the configuration.yaml and I just test all.

The problem is that I use an internal switch flag (in the NodeMCU program)
in order to know the status of the door.This cause I also have a push button near the door.

This flag was set, when the NodeMCU is power on using the command retained topic that
now I have no more now.
I must understand how to get the status topic via PubSubClient when power on NodeMCU
in order to set this internal switch.

I have all day to work on this :slight_smile:

Thanks a lot again
Denis

@denisj
The retained message depends a bit on the use case. Light is an easy example. Lets say you have retained status and command. When new device subscribes to status topic it will receive the light status from the mqtt broker immeadiately and doesn’t have to wait for the light itself to update the topic (by changing the state).
Or if you sent turn_on command from homeassistant to command topic and the light would for some reason lose power. During the restart the light receives the retained command and turns on without separate turn_on command.

In your case your nodemcu receives the previous “turn_on” command when connecting back to mqtt broker. This retain should be taken away as you already did.

I didn’t quite yet understand what items you combine to be the state and what you listen on as command.

But to your internal flag, start up your program with default values having everythig in safe state and when connected listen to mqtt commands. Or block the sw as long as you have the connection. The latter part will prevent local control (if you have, the door button?).

I think I still miss something from your setup to fully understand it. Hope the pointers above are helpful :slight_smile:

Thanks a lot Taikapanu… I still not receive the email for the notify :frowning:

My wrong settings was that I retained all 2 topics… the command and the status.
Now that I retain only the status maybe will work ok.

For others… In order to receive the status retained topic, you just must to subscribe at that topic.
So in this case I’ll do 2 times the subscribe command… one for command and one for status topic.

When ths NodeMCU will subscribe and the MQTT broker have retained messages, it will (MQTT broker)
send the retained messages to all subscribers.
So when the NodeMCU will reset, the first think is to set the internal variable using the received status value via subscription command att the first call back.
For now all work.
I’ll see in next days.

Thanks all again
Denis