Home Assistant not sending MQTT packets

For some reason I cannot get HA to send any mqtt packets from the “Overview” page or the “Services” page however, I have no problems from MQTT page or the Node-Red add-on.

On the “Overview” page my switches say “Unavailable” and the toggle does nothing. I setup an external Mosquitto server to see the tcp packets and I can see the HA connection packets but no other packets are sent or received when toggled “Overview” switch.

Note: Using any other MQTT client (mosquitto_sub & mosquitto_pub on the HA Pi or external , MQTTBox on desktop, MQTT Dash on Android, etc) work perfectly.

My setup:
Pi 3b
Hassos/Home Assistant 0.93.2
Sonoff 6.5.0
Mosquitto add-on and Mosquitto 1.5.8 on Centos7

My config:
switch:

  • platform: mqtt
    name: “Sonoff01”
    state_topic: “stat/sonoff01/POWER”
    command_topic: “cmnd/sonoff01/POWER”
    availability_topic: “tele/sonoff01/LWT”
    payload_on: “ON”
    payload_off: “OFF”
    state_on: “ON”
    state_off: “OFF”
    optimistic: false
    qos: 2
    retain: false

Thanks in advance.

I recently helped someone else solve the same problem. They could control the device via Home Assistant’s MQTT page (thereby confirming Home Assistant was connected to the MQTT broker) but could not via the MQTT Switch they configured.

The problem was they were not using standard single ' or double " quotes in the MQTT Switch’s configuration. They used fancy quotes “like this” which are invalid.

Hello 123, thank you for the speedy reply.

I can confirm they are standard double quotes ( " ). I have also tried single quotes ( ’ ) but the results were the same. Checking the configs via the GUI and ssh cli show no errors.

Thank you.

As I stated in the other post, “there’s a missing piece to the puzzle”.

This doesn’t add up:

  1. Home Assistant’s connection to the broker is functional.
  2. You can publish to topics using its MQTT page.
  3. Other MQTT clients confirm the payload was published.
  4. You report the MQTT Switch’s configuration (switch.sonoff01) is valid.
  5. Operating the MQTT Switch (switch.sonoff01) fails to publish anything.

Does not compute. Something must be wrong with the MQTT Switch’s configuration.

Please post a formatted version of the configuration for switch.sonoff01.

After many attempts, I finally figured out a solution.

Adding these 2 lines to my config seemed to fix the problem:
payload_available: “Online”
payload_not_available: “Offline”

Thank you for your assistants.

Like I said, “there’s a missing piece to the puzzle” and “Something must be wrong with the MQTT Switch’s configuration.”

You had specified an availability_topic but it was not using the default values of online and offline (see documentation).

For that matter, all of these entries are unnecessary because they are using the default values:

payload_on: 'ON'
payload_off: 'OFF'
state_on: 'ON'
state_off: 'OFF'
optimistic: false
retain: false

Therefore the MQTT Switch’s configuration is reduced to:

- platform: mqtt
  name: 'Sonoff01'
  state_topic: 'stat/sonoff01/POWER'
  command_topic: 'cmnd/sonoff01/POWER'
  availability_topic: 'tele/sonoff01/LWT'
  payload_available: 'Online'
  payload_not_available: 'Offline'
  qos: 2