@@ -34,91 +34,9 @@ Configuration variables:
34
34
- **reboot_timeout ** (*Optional *, :ref: `time <config-time >`): The amount of time to wait before rebooting when no
35
35
client connects to the API. This is needed because sometimes the low level ESP functions report that
36
36
the ESP is connected to the network, when in fact it is not - only a full reboot fixes it.
37
- Can be disabled by setting this to ``0s ``. Defaults to ``5min ``.
37
+ Can be disabled by setting this to ``0s ``. Defaults to ``15min ``.
38
38
- **id ** (*Optional *, :ref: `config-id `): Manually specify the ID used for code generation.
39
39
40
- .. _api-mqtt_to_native :
41
-
42
- Migrating from MQTT to Native API Setup in Home Assistant
43
- ---------------------------------------------------------
44
-
45
- The native API is the best way to use ESPHome together with Home Assistant - it's fast,
46
- highly efficient and requires almost zero setup (whereas MQTT requires you to set up an MQTT broker first).
47
-
48
- If you've previously used ESPHome with Home Assistant via MQTT and have enabled MQTT discovery,
49
- the upgrade process is unfortunately not just swapping out the ``mqtt `` for ``api `` in your configuration:
50
- Home Assistant's `entity registry <https://developers.home-assistant.io/docs/en/entity_registry_index.html >`__ complicates
51
- things a bit. If you don't follow these steps, all your new native API entities will have a trailing
52
- ``_2 `` at the end of the entity ID.
53
-
54
- You can repeat these steps for all your nodes, or convert them over to the new native API one by one.
55
-
56
- 1. Disable MQTT discovery on ESP side. In your ESPHome configuration, set a special "clean" discovery flag:
57
-
58
- .. code-block :: yaml
59
-
60
- # In your ESPHome configuration! Not HA config!
61
- mqtt :
62
- # Other settings ...
63
- discovery : clean
64
-
65
- 2. Compile and upload this new firmware. All entities should now be gone from Home Assistant.
66
-
67
- 3. Go to your Home Assistant configuration folder and go to the ``.storage `` folder (might be hidden
68
- depending on your operating system). In there you will find a file called ``core.entity_registry `` - open
69
- the file with a text editor and paste the contents below
70
-
71
-
72
- .. raw :: html
73
-
74
- <textarea rows =" 10" cols =" 50" id =" entity-reg-converter" ></textarea >
75
- <button type =" button" id =" entity-reg-button" >Convert Entity Registry</button >
76
- <script >
77
- var elem = document .getElementById (" entity-reg-converter" );
78
- elem .addEventListener (" click" , function () {
79
- elem .focus ();
80
- elem .select ();
81
- });
82
- document .getElementById (" entity-reg-button" ).addEventListener (" click" , function () {
83
- try {
84
- data = JSON .parse (elem .value );
85
- } catch (e) {
86
- alert (e);
87
- }
88
- var entities = data .data .entities ;
89
- var newEntities = [];
90
- for (var i = 0 ; i < entities .length ; i++ ) {
91
- var entity = entities[i];
92
- if (entity .platform != " mqtt" ) {
93
- newEntities .push (entity);
94
- }
95
- }
96
- data .data .entities = newEntities;
97
- elem .value = JSON .stringify (data, null , 4 );
98
- });
99
- </script >
100
-
101
- 4. Stop Home Assistant - this is necessary for the entity registry changes not to become overriden.
102
-
103
- 5. Convert the Entity Registry file above using the "Convert Entity Registry Button", and
104
- override the ``.storage/core.entity_registry `` file with the new contents.
105
-
106
- 6. Start Home Assistant.
107
-
108
- 7. Now you can enable the ESPHome native API (and upload the new firmware)
109
-
110
- .. code-block :: yaml
111
-
112
- # Example configuration entry
113
- api :
114
-
115
- 8. In Home Assistant, go to "Configuration" -> "Integrations" - if you've set up the ``discovery: `` component,
116
- you'll already see the ESP as a suggestion to be configured. But if you're having issues with that, you can
117
- always manually set up an ESPHome device using "Set up a new integration" -> "ESPHome".
118
-
119
- 9. Now you can remove ``mqtt: `` from your ESPHome configuration. You don't have to, but doing so will
120
- free up resources (of which these ESPs don't have too much).
121
-
122
40
.. _api-homeassistant_service_action :
123
41
124
42
``homeassistant.service `` Action
@@ -220,6 +138,11 @@ There are currently 4 types of variables:
220
138
- float: A floating point number. C++ type: ``float ``
221
139
- string: A string. C++ type: ``std::string ``
222
140
141
+ Each of these also exist in array form:
142
+
143
+ - bool[]: An array of boolean values. C++ type: ``std::vector<bool> ``
144
+ - ... - Same for other types.
145
+
223
146
.. _api-connected_condition :
224
147
225
148
``api.connected `` Condition
@@ -257,6 +180,34 @@ never be removed. Features of native API (vs. MQTT):
257
180
- **Low Latency: ** The native API is optimized for very low latency, usually this is only
258
181
a couple of milliseconds and far less than can be noticed by the eye.
259
182
183
+
184
+ .. _api-homeassistant_event_action :
185
+
186
+ ``homeassistant.event `` Action
187
+ ------------------------------
188
+
189
+ When using the native API with Home Assistant, you can create events in the Home Assistant event bus
190
+ straight from ESPHome :ref: `Automations <automation >`.
191
+
192
+ .. code-block :: yaml
193
+
194
+ # In some trigger
195
+ on_... :
196
+ # Simple
197
+ - homeassistant.event :
198
+ event : esphome.button_pressed
199
+ data :
200
+ title : Button was pressed
201
+
202
+ Configuration options:
203
+
204
+ - **event ** (**Required **, string): The event to create - must begin with ``esphome. ``
205
+ - **data ** (*Optional *, mapping): Optional *static * data to pass along with the event.
206
+ - **data_template ** (*Optional *, mapping): Optional template data to pass along with the event.
207
+ This is evaluated on the Home Assistant side with Home Assistant's templating engine.
208
+ - **variables ** (*Optional *, mapping): Optional variables that can be used in the ``data_template ``.
209
+ Values are :ref: `lambdas <config-lambda >` and will be evaluated before sending the request.
210
+
260
211
See Also
261
212
--------
262
213
0 commit comments