Native API Component - Custom Host URL?

Can someone educate me a little further on the Native API Component — ESPHome

Following up from my other post (Use Nabu Casa URL to use HA API?) I was wondering if it was possible to have this type of config on the ESP to connect remotely to the Home Assistant API?

Example:

# Example configuration entry
api:
  password: 'MyPassword'
  NabuCasa: https://YOUR_NABU_CASA_URL_HERE.ui.nabu.casa #else from secrets.yaml
  LongLivedToken: ******************* #else from secrets.yaml

Is this possible?

Not possible as it’s HA that initiates the connection at the ESP and not the reverse :wink:

1 Like

Thanks for clarifying that :slight_smile:

So I suppose I would need to engineer another way to easily add this to each sensor on my ESPs.
Could you recommend any other features to do so?

Thinking something along the lines of having majority of the HTTP command script in another file using Includes - Then each node can be edited to include that file.

For the sensors, would that need some experienced templating?
So I could include the core of the HTTP Request, then template each sensor on each node…?

Sorry for the lack of knowledge - just using the example from my previous post…

button:
  # Button on press calls the http command
  - platform: template
    name: $BearerSensorName
    on_press:
        then:
        - http_request.post:
              method: POST
              ####
              ## Change IP and Sensor name within the substitutions
              ## You can use the local or remote IP
              ## Remember the URL has /api/states/ hard coded
              ####
              url: $NabuCasaAddress/api/states/$BearerSensorName
              headers:
                Authorization: !secret bearer_token
                Content-Type: application/json
              verify_ssl: false
              json:
              ####
              ## You can customize this part but remember to include 'state'
               root["state"] = id(uptime_human).state;
               ####
               ## Add more data / attributes here
               ## Refer to Home Assistant API Docs
               ## https://developers.home-assistant.io/docs/api/rest/
               ####

Why not use MQTT?

1 Like

Everything points to MQTT however I think if something similar is built in, I’d rather use that.

MQTT feels like a ‘middle man’ when this does the same?