Mqtt sending several publishes of same event

Hi,

I have an issue where the same event is being sent to home assistant several times.
The MQTT topic is retained by design, and the json within the topic is static

{
  "event": "button pressed",
  "inputId": "48402;3"
}

So it’s not a on or off message, but rather just a push of a button.

This is my trigger (Created with GUI editor)

alias: boolean Bedroom
description: ''
trigger:
  - platform: mqtt
    topic: homeassistant/device_automation/48402_3/event
condition: []
action:
  - service: automation.turn_off
    target:
      entity_id: automation.bedroom
    data:
      stop_actions: false
  - service: input_boolean.toggle
    target:
      entity_id: input_boolean.bedroom
  - delay:
      hours: 0
      minutes: 0
      seconds: 4
      milliseconds: 0
  - service: automation.turn_on
    target:
      entity_id: automation.bedroom
mode: single

The thing is when used, the lights just turn on and off,
so I setup an MQTT server with full debug logs, and it seems when I receive a button press from the component, I receive hundreds of published to Home Assistant.

Anyone got an idea?
I have reached out to the support, and requested them to remove the retain flag, as that doesn’t seem to make sense, but I am not sure why that would cause MQTT server to resend the same message hundred of times?
(well, at least it only sent once to mqtt-explorer :smile: )

edit
After posting this, did the component even sent retain flag as on? (r0)
but suddenly after a while, retain flag is set?

7daebb60676c4882b584bfac16e7b131 = is the component
2UokJOjH1QOM1JMskPQOio = is home assistant

2021-09-28T20:32:43: Received PUBLISH from 7daebb60676c4882b584bfac16e7b131 (d0, q1, r0, m31475, 'homeassistant/device_automation/48402_3/event', ... (46 bytes))
2021-09-28T20:32:43: Sending PUBLISH to 2UokJOjH1QOM1JMskPQOio (d0, q0, r0, m0, 'homeassistant/device_automation/48402_3/event', ... (46 bytes))
2021-09-28T20:32:43: Sending PUBLISH to mqtt-explorer-3c0db0a3 (d0, q0, r0, m0, 'homeassistant/device_automation/48402_3/event', ... (46 bytes))
2021-09-28T20:32:44: Sending PUBLISH to 2UokJOjH1QOM1JMskPQOio (d0, q0, r1, m0, 'homeassistant/device_automation/48402_3/event', ... (46 bytes))
2021-09-28T20:32:44: Sending PUBLISH to 2UokJOjH1QOM1JMskPQOio (d0, q0, r1, m0, 'homeassistant/device_automation/48402_3/event', ... (46 bytes))
2021-09-28T20:32:45: Sending PUBLISH to 2UokJOjH1QOM1JMskPQOio (d0, q0, r1, m0, 'homeassistant/device_automation/48402_3/event', ... (46 bytes))
2021-09-28T20:32:46: Sending PUBLISH to 2UokJOjH1QOM1JMskPQOio (d0, q0, r1, m0, 'homeassistant/device_automation/48402_3/event', ... (46 bytes))
2021-09-28T20:32:47: Sending PUBLISH to 2UokJOjH1QOM1JMskPQOio (d0, q0, r1, m0, 'homeassistant/device_automation/48402_3/event', ... (46 bytes))
2021-09-28T20:32:47: Sending PUBLISH to 2UokJOjH1QOM1JMskPQOio (d0, q0, r1, m0, 'homeassistant/device_automation/48402_3/event', ... (46 bytes))
2021-09-28T20:32:47: Sending PUBLISH to 2UokJOjH1QOM1JMskPQOio (d0, q0, r1, m0, 'homeassistant/device_automation/48402_3/event', ... (46 bytes))
2021-09-28T20:32:48: Sending PUBLISH to 2UokJOjH1QOM1JMskPQOio (d0, q0, r1, m0, 'homeassistant/device_automation/48402_3/event', ... (46 bytes))
2021-09-28T20:32:48: Sending PUBLISH to 2UokJOjH1QOM1JMskPQOio (d0, q0, r1, m0, 'homeassistant/device_automation/48402_3/event', ... (46 bytes))
2021-09-28T20:32:48: Sending PUBLISH to 2UokJOjH1QOM1JMskPQOio (d0, q0, r1, m0, 'homeassistant/device_automation/48402_3/event', ... (46 bytes))
2021-09-28T20:32:49: Sending PUBLISH to 2UokJOjH1QOM1JMskPQOio (d0, q0, r1, m0, 'homeassistant/device_automation/48402_3/event', ... (46 bytes))
2021-09-28T20:32:49: Sending PUBLISH to 2UokJOjH1QOM1JMskPQOio (d0, q0, r1, m0, 'homeassistant/device_automation/48402_3/event', ... (46 bytes))
2021-09-28T20:32:50: Sending PUBLISH to 2UokJOjH1QOM1JMskPQOio (d0, q0, r1, m0, 'homeassistant/device_automation/48402_3/event', ... (46 bytes))
2021-09-28T20:32:50: Sending PUBLISH to 2UokJOjH1QOM1JMskPQOio (d0, q0, r1, m0, 'homeassistant/device_automation/48402_3/event', ... (46 bytes))

edit 2
a more detailed mqtt log

2021-09-28T20:32:43: Received PUBLISH from 7daebb60676c4882b584bfac16e7b131 (d0, q1, r0, m31475, 'homeassistant/device_automation/48402_3/event', ... (46 bytes))
2021-09-28T20:32:43: Sending PUBLISH to 2UokJOjH1QOM1JMskPQOio (d0, q0, r0, m0, 'homeassistant/device_automation/48402_3/event', ... (46 bytes))
2021-09-28T20:32:43: Sending PUBLISH to mqtt-explorer-3c0db0a3 (d0, q0, r0, m0, 'homeassistant/device_automation/48402_3/event', ... (46 bytes))
2021-09-28T20:32:43: Sending PUBACK to 7daebb60676c4882b584bfac16e7b131 (m31475, rc0)
2021-09-28T20:32:44: Received SUBSCRIBE from 2UokJOjH1QOM1JMskPQOio
2021-09-28T20:32:44:    homeassistant/device_automation/48402_3/event (QoS 0)
2021-09-28T20:32:44: 2UokJOjH1QOM1JMskPQOio 0 homeassistant/device_automation/48402_3/event
2021-09-28T20:32:44: Sending SUBACK to 2UokJOjH1QOM1JMskPQOio
2021-09-28T20:32:44: Sending PUBLISH to 2UokJOjH1QOM1JMskPQOio (d0, q0, r1, m0, 'homeassistant/device_automation/48402_3/event', ... (46 bytes))
2021-09-28T20:32:44: Received SUBSCRIBE from 2UokJOjH1QOM1JMskPQOio
2021-09-28T20:32:44:    homeassistant/device_automation/36952_3/event (QoS 0)
2021-09-28T20:32:44: 2UokJOjH1QOM1JMskPQOio 0 homeassistant/device_automation/36952_3/event
2021-09-28T20:32:44: Sending SUBACK to 2UokJOjH1QOM1JMskPQOio
2021-09-28T20:32:44: Sending PUBLISH to 2UokJOjH1QOM1JMskPQOio (d0, q0, r1, m0, 'homeassistant/device_automation/36952_3/event', ... (46 bytes))
2021-09-28T20:32:44: Received SUBSCRIBE from 2UokJOjH1QOM1JMskPQOio
2021-09-28T20:32:44:    homeassistant/device_automation/48402_3/event (QoS 0)
2021-09-28T20:32:44: 2UokJOjH1QOM1JMskPQOio 0 homeassistant/device_automation/48402_3/event
2021-09-28T20:32:44: Sending SUBACK to 2UokJOjH1QOM1JMskPQOio
2021-09-28T20:32:44: Sending PUBLISH to 2UokJOjH1QOM1JMskPQOio (d0, q0, r1, m0, 'homeassistant/device_automation/48402_3/event', ... (46 bytes))

What is the “component” that is publishing the repeated payloads to the MQTT broker?

it’s just a “wall push button” whatever the correct name is :slight_smile:
I don’t want to call out the company name, as I am testing the product for them.

This unnamed device is responsible for publishing a stream of payloads to the broker so, given that you are testing it, you now have an issue to report to its manufacturer.

1 Like

Very likely the push button needs debouncing.

1 Like

I am not so sure the issue is on the device.
As if you see the logs, the device (7da…) Is only sending 1 message to mqtt, but mqtt is sending it hundreds of times to home assistant.
Or am I reading the logs wrong?

Yeah looking closer you are right.

One received message from the device, one publish to HA, one publish to MqttExplorer and one acknowledge back to the device.

The rest are subscription messages and acknowledgements.

So it all looks ok to me.

But why would Home Assistant subscribe so many times?
The issue is that the automation is being triggered several times a second (Every time Home Assistant is subscribing) which doesn’t seem right to me.

Hard to say without seeing the full payload.

hmm. MQTT explorer only provides the aforementioned payload,
not sure if I can increase the debugging level in Mosquitto to include payload,
will give it a go tonight when I return from work.
but still, the device only sent 1 message, so should also only be 1 payload I would assume.

It could be sending a discovery payload.

Random thought: I see automations being turned on and off.

If those are triggered by mqtt, I could imagine unsubscribe / subscribe being sent, and as messages are retained, they would be resent in a loop at each subscribe…

Create an automation with an MQTT Trigger that simply displays whatever it receives in a persistent notification. Now use an MQTT client, like MQTT Explorer or even Home Assistant’s own MQTT Publish service, to publish a payload to whatever topic you chose.

If there’s a systemic problem with Home Assistant’s operation with the broker, you will receive numerous notifications, just like the behavior with your unnamed device.

If you get only one notification, then the problem is limited to the unnamed device.

you got it.
and for some reason after I “stopped” stopping the automations, the retain flag disappeared.

Thank you