MQTT Automation Trigger Problem

I am having a problem with an automation that does not trigger. Basicaly the automation is supposed to trigger when a status of ‘up’ is written to a specific topic.

I have tried a couple of different ways of doing this and I cant figure it - I think I am missing something obvious here but cant spot it.

Heres the automation yaml:

- alias: wled initialisation
  description: When WLED display starts and is available set parameter
  trigger:
  - payload: up
    platform: mqtt
    topic: /wled/intensity
  condition: []
  action:
  - data:
      payload_template: '0'
      topic: /wled/intensity
    service: mqtt.publish
  mode: single

Heres the output from MQTTFX

up

Any help welcomed!

I can’t spot it wither because I just confirmed it works perfectly on my test system. I published up to /wled/intensity and the automation triggered and published 0 to the same topic.

Screenshot from MQTT Explorer. On the right it shows I just published up and on the left it shows the payload is 0.
Screenshot from 2020-09-10 12-22-52

Let’s start with the basics:

  • Do you have the MQTT integration configured and functioning properly?
  • If you composed the automation using a text editor, did you execute Reload Automations afterwards?
  • Did you check Configuration > Automations and confirm the automation is on?

Let’s start with the basics:

Do you have the MQTT integration configured and functioning properly?

Yes , I have 18 other devices running very well for a number of years!!

If you composed the automation using a text editor, did you execute Reload Automations afterwards?

Yes

Did you check Configuration > Automations and confirm the automation is on?

Yes

Are you sure /wled/intensity can return both up and 0 ?

yeh, good point on that one the first topic should be /wled/status and the second /wled/intensity - my bad and a copy and paste error.

I tested it with actaully publishing ‘up’ to the topic a different client and flip flopping it with other values and I still cant get the automation to trigger?!?!?

I also trying escaping the payload in the automation with ‘up’ and “up” still no go and I have recreated the automation from scratch.

So why does it work on your setup and not mine - whats your base MQTT config look like?

Drop the leading “/” from your topics.

My config is unimportant, what’s key here is to confirm your instance of Home Assistant is properly connected to the MQTT Broker.

  1. Go to Configuration > Integrations > MQTT > Configure

  2. In Listen to a topic type test then click Start Listening

  3. In Publish a packet type test for the topic and hello world for the payload then click Publish.

You should immediately see the message (hello world) displayed at the bottom of the screen:

If this works as described, you’ve confirmed Home Assistant is connected to the MQTT broker and can both send and receive messages. If it fails, then you know you have to fix connectivity first.

Next step would be to use this same utility to publish the payload up to whichever topic your automation is using as a trigger (be it /wled/intensity or /wled/status or whatever). That should cause the automation to trigger.

Note

Many MQTT problems are simply due to “plumbing” issues: either not connected or misconnected.

removed leading ‘/’ and tested as you suggested result below…

I also have fired in various values with a 3rd part client (MQTTFX) and I can see them being received etc

and I have changed the automation to match - still no joy :frowning:

EDIT

I need to sharpen my reading skills; you did carry out the test.

Back to square one:

Assuming the automation now looks like this:

- alias: wled initialisation
  description: When WLED display starts and is available set parameter
  trigger:
  - payload: up
    platform: mqtt
    topic: wled/status
  condition: []
  action:
  - data:
      payload_template: '0'
      topic: wled/intensity
    service: mqtt.publish
  mode: single
  • Go to Configuration > Automations and confirm automation.wled_initialisation is on.
  • If it’s on execute the automation manually by clicking EXECUTE. It should publish 0 to wled/intensity.

ok… deep breath its working ???

changed the code to the following:

- alias: WLed Initial Boot
  initial_state: on
  trigger:
    platform: mqtt
    topic: wled/status
    payload: 'up'  
  condition: []
  action: 
  - data:
      payload_template: '0'
      topic: wled/intensity
    service: mqqt.publish
  mode: single

I removed the leading ‘/’ from the topics tested it and no change (not working)

I then changed the trigger section formating to put platform first, the topic followed by the payload and removed the ‘-’ from infront of payload and it works?!?!

Looks like the problem was a formating problem but I dont get why it worked ok on your instance?!?!?

I’m surprised to hear you say that works because it contains a spelling error. It refers to mqqt.publish (two q’s) when it should be mqtt.publish (two t’s).

The order of the options has no bearing on whether the automation triggers or not. That’s proven by the fact I copy-pasted your original automation verbatim and it worked perfectly on my test system. So, not a formatting problem.

Clearly, something else was responsible for the triggering failure (something that’s still unidentified). Whatever changes you made included some other step that corrected the problem, but it wasn’t the order of the options.

FWIW, for the sake of legibility, the common practice when creating a trigger is to start with the platform option. However, if you create an automation using the Automation Editor, it will store it with the options sorted. That makes it a bit less legible than the traditional way but also proves that the order of the options isn’t relevant.

Not for long. 0.115 removes the sort. (Or maybe that’s just for Lovelace?).

Some formating issues there for sure and again down to me.

The original automation I created in the Automation Editor (laziness) and the ripped it out and did it again in yaml manually (last code update) thats where the spelling mistake came in.

TBH I was never worried about action side as that always worked and I could manually trigger it so I could see it working - the problem was always the trigger.

I was methodical in changing the code over to yaml, testng and then modifying the order of the statments and removing the ‘-’. Im with you that it doesnt follow on the order which makes me think that there must have been either formating issue on my side or some hidden character in my yaml causing mayhem - this one is real head scratcher for sure!!!

Thank you for taking the time to look and helping out :+1:

1 Like