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
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.
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?
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?
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.
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.
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.
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