Webhooks MQTT

Hello everybody.

In older versions of HA, before api_password was deprecated, I was able to send MQTT payloads to HA via IFTTT.
In this way:

How can I do now, considering that api_password is deprecated?

Thank you

You need to create a Long-lived Access Token and then follow the examples shown here:

To create the token, click on your username displayed at the bottom of the left-hand menu in the Lovelace UI. Scroll down until you see Long-Lived Access Tokens, then click Create Token then follow the instructions. Once that’s done, use the token (a long string of characters) with the HTTP request (as shown in the linked instructions above).

NOTE
The token is not used like the way you had used your api_password. In other words, you don’t put it directly within the URL. It’s a bit more complicated than that.

Thanks for your answer.
I have tried in every way and reading all the documentation, but I have not succeeded.
I also tried adding “” Authorization “:” Bearer … “” to the header, but I didn’t find the solution.
Is it possible that there is no example on how to publish MQTT through http or webhooks?
It would be enough for me to have a small example to understand.

This is an example of a curl command that can execute mqtt.publish.

To test it, replace ABCDEFGH with your Long-Lived Token and replace whatever with your system’s duckdns sub-domain name.

curl -X POST -H "Authorization: Bearer ABCDEFGH" \
     -H "Content-Type: application/json" \
     -d '{"payload": "su", "topic": "Taparella/2P/camera1"}' \
     http://whatever.duckdns.org:8123/api/services/mqtt/publish

So it performs an HTTP POST with a Content Header containing:

Authorization: Bearer ABCDEFGH
Content-Type: application/json

However, as far as I know, IFTTT’s Webhook service does not let you create a custom Content Header. It lets you specify Content Type: application/json but but not additional information like Authorization: Bearer ABCDEFGH.

So if your plan is to use IFTTT, you have to use a different technique. Here are two alternatives:

  1. This is a good summary of using the IFTTT integration: How to use services like IFTTT & Webhooks using new Authentication?

  1. A simpler alternative is to create an automation with a webhook trigger. Here’s a very good explanation:
    Webhooks from IFTTT - sending custom action and/or variables questions

Let me know which of the two alternatives you end up using.