[SOLVED] Why would `mqtt.publish` not be working?

I am trying to publish from my NUC to my Pi via an automation. It works via the NUC mqtt dev tools. Also, the automation trigger definitely works, as the 2nd action (a notification) works.

Action

{
  "payload": "on",
  "topic": "kitchen/switch/fan"
}

MQTT Dev Tools (this does work)

topic: "kitchen/switch/fan"
payload: "on"

So what doesn’t work?

I actually just figured it out.

Entering the automation on the Pi side via the UI added some extra quote marks (that could only be seen via the yaml).

the ui had entered it as:

- id: '1566653968614'
  alias: NUC Test - Nook Fan
  trigger:
  - payload: "'on'"
    platform: mqtt
    topic: "'kitchen/switch/fan'"
  condition: []
  action:
  - data:
      entity_id: switch.rf_outlet_2
    service: switch.turn_on

I just removed the single quotes from payload: "'on'" & topic: "'kitchen/switch/fan'" so the final automation was:

- id: '1566653968614'
  alias: NUC Test - Nook Fan
  trigger:
  - payload: "on"
    platform: mqtt
    topic: "kitchen/switch/fan"
  condition: []
  action:
  - data:
      entity_id: switch.rf_outlet_2
    service: switch.turn_on

My takeaway: don’t use the UI to write automations, or at least look at it after.

Thoroughly agree with your takeaway!

It’s too bad because I like that the UI will (usually) properly format things. Also for new users I can see this being a huge headache.

It happens exactly the same for me. The payload is for an RF Bridge and if the quotes are deleted (the UI is doing that) nothing works. This is valid also for scripts and cards action.
The good news is, editing those files with the File Editor add-on or the Configurer UI everithing is ok.