mirror of
https://github.com/esphome/esphome-docs.git
synced 2024-12-25 17:17:54 +01:00
parent
59f791e6c9
commit
3e5fb95498
@ -1,14 +1,14 @@
|
||||
Share data directly between ESPHome nodes
|
||||
=========================================
|
||||
|
||||
In certain special cases you might want to avoid placing any middleware like an MQTT or a home automation server just to transfer small bits of data from one node to another. Direct data polling is possibvle using HTTP, but beware that the involved components are resource hungry and may be less stable on long term than the usual methods. The webserver embedded in the node is not designed to constantly serve a large amount of requests.
|
||||
In certain special cases it might be desired to avoid placing any middleware like an MQTT or a home automation server just to transfer small bits of data from one node to another. Direct data polling is possibvle using HTTP, but beware that the involved components are resource hungry and may be less stable on long term. The webserver embedded in the node is not designed to constantly serve a large amount of requests.
|
||||
|
||||
The node holding the data we need to retrieve will be the server, and the others polling for it will be the clients (can be multiple).
|
||||
The primary node holding the data we need to retrieve from will be the server, and the others polling for it will be the clients (can be multiple).
|
||||
|
||||
Server part
|
||||
-----------
|
||||
|
||||
You must set up a webserver on your primary node to make available the required sensor data using the :doc:`/components/web_server`.
|
||||
Setting up a webserver using the :doc:`/components/web_server` on the primary node will make available the required sensor data through a :ref:`api-rest` interface.
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
@ -18,7 +18,7 @@ You must set up a webserver on your primary node to make available the required
|
||||
Client part
|
||||
-----------
|
||||
|
||||
On the client nodes we need a :doc:`/components/http_request` with an ``id`` set, and a :doc:`/components/sensor/template` to make it accessible locally.
|
||||
On the client nodes we need an :doc:`/components/http_request` with an ``id`` set, and a :doc:`/components/sensor/template` to make it accessible locally.
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
@ -35,13 +35,9 @@ On the client nodes we need a :doc:`/components/http_request` with an ``id`` set
|
||||
Pulling the data
|
||||
****************
|
||||
|
||||
To automate the request for data, we use an :ref:`interval` component requesting the URL pointing to the sensor id for which the state is needed. See :ref:`api-rest` on how to build up the URL for your sensors.
|
||||
To automate the request for data, we use an :ref:`interval` requesting the URL pointing to the sensor id for which the state is needed. See :ref:`api-rest` on how to build up the URL for your sensors.
|
||||
|
||||
.. note::
|
||||
|
||||
The domain is the type of the component, for example ``sensor`` or ``light``. ``id`` refers to the internal ID of the component - which is created from the name of the component, stripping out all non-alphanumeric characters, making everything lowercase and replacing all spaces by underscores. To confirm the corrrct ID to use, you can set the log level to VERY_VERBOSE on your server node and look for ``object_id:`` in the logs.
|
||||
|
||||
In the example below we pull the value of a sensor, and after parsing the resulted JSON string we publish it to the template sensor:
|
||||
In the example below we request the value of a sensor from the server node, and after parsing the resulted JSON string we publish it to the local template sensor:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
@ -65,14 +61,14 @@ Result
|
||||
:align: center
|
||||
:width: 95.0%
|
||||
|
||||
Server side real sensor.
|
||||
Server side real sensor
|
||||
|
||||
|
||||
.. figure:: images/clients.png
|
||||
:align: center
|
||||
:width: 95.0%
|
||||
|
||||
Client side template sensor.
|
||||
Client side template sensor
|
||||
|
||||
|
||||
See Also
|
||||
|
Loading…
Reference in New Issue
Block a user