How can a custom card talk to a custom add-on

How can a custom card talk to a custom addon? (like in HTTP or something…)

I know I can expose the addon server to a different port but then it will be publicly accessible without auth, and I don’t wanna implement auth on my own… (I know I can use the auth API but prefer to avoid it)

If you not exposing the port, it still can be accessed within the docker network.

yes, but how can I access it from the frontend

Cards should not talk to services.
That is a job for integrations.
Integrations run their code on the server so they can talk to the add-on directly.

How can they talk to the integration?

By using the docker hostname of the container running the add-on.

I don’t see it in the docs, do you have a reference?

There is no need to document that.
In the end it’s just a regular server.

But instead of putting in a public hostname or an IP to it, you use the hostname of the docker container.

Everything else is just as it would be any other service.
The adguard and zwave-js integrations both support talking to add-ons and other ways of running those services.

There is something I’m missing here, how can a front end call the hostname of the docker container? they are not in the same network (one is the network of the current device viewing the page while the other is the home assistant server and it’s internal docker network

(Note that I’m talking about frontend card communication with integration/addon)

You missed my first comment.

The card “talks” to the integration over the integrations API (REST/WS), the integration “talks” to the service over it’s API (REST/WS/socket).

1 Like

frontend cards are usually communicating with other systems using home assistant to eliminate network issues. Custom add-on or integration can register a web socket inside home assistant and front end can call it.

how can it register websocket inside home assistant? I can’t find it in the docs

I did not miss you comment, I just don’t understand how the card talk to the integration, what is the integration api I can’t find it

creating a WS endpoint from a custom integration: https://github.com/AlexxIT/WebRTC/blob/6cf4b37fe41ed79fe3780af88306d74a259bd795/custom_components/webrtc/__init__.py

calling it from front end card: https://github.com/AlexxIT/WebRTC/blob/6cf4b37fe41ed79fe3780af88306d74a259bd795/custom_components/webrtc/www/webrtc-camera.js#L144

1 Like
1 Like

I see in the docs that the addon can provide services but no example:

can I communicate through services? and if so, how?

(although creating integration is the preferred method, unfortunately, I’m not very good in Python and we can’t run docker container as integrations

Add-ons can not provide services to Home Assistant.
Only integrations can do that.

The services field of add-on configuration is to tell the supervisor what kind of service the add-on provides so it can be used by other add-ons like mqtt / mysql.

so how the mqtt / mysql addons can provide those? :thinking:

Those what?
mqtt / mysql are the “services” add-ons can provide/consume.
They are not add-ons themselves.

this example is about; add-on X is providing service Y. If any other add-on depends on service Y, it should start after add-on X.