Skip to content

Commit 5c78504

Browse files
kbx81coderabbitai[bot]jesserockz
authored
Break apart automations doc (#3957)
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Jesse Hills <[email protected]>
1 parent e8deeda commit 5c78504

18 files changed

+1604
-1033
lines changed

Diff for: all_automations.json

+421
Large diffs are not rendered by default.

Diff for: automations/actions.rst

+558
Large diffs are not rendered by default.

Diff for: automations/all_actions.rst

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
- **ags10:** ``new_i2c_address``, ``set_zero_point``
2+
- **alarm_control_panel:** ``arm_away``, ``arm_home``, ``arm_night``, ``chime``, ``disarm``, ``pending``, ``ready``, ``triggered``
3+
- **animation:** ``next_frame``, ``prev_frame``, ``set_frame``
4+
- **at581x:** ``reset``, ``settings``
5+
- **ble:** ``disable``, ``enable``
6+
- **ble_client:** ``ble_write``, ``connect``, ``disconnect``, ``numeric_comparison_reply``, ``passkey_reply``, ``remove_bond``
7+
- **bluetooth_password:** ``set``
8+
- **button:** ``press``
9+
- **canbus:** ``send``
10+
- **climate:** ``control``
11+
- **component:** ``resume``, ``suspend``, ``update``
12+
- **cover:** ``close``, ``control``, ``open``, ``stop``, ``toggle``
13+
- **cs5460a:** ``restart``
14+
- **deep_sleep:** ``allow``, ``enter``, ``prevent``
15+
- **dfplayer:** ``pause``, ``play``, ``play_folder``, ``play_mp3``, ``play_next``, ``play_previous``, ``random``, ``reset``, ``set_device``, ``set_eq``, ``set_volume``, ``sleep``, ``start``, ``stop``, ``volume_down``, ``volume_up``
16+
- **dfrobot_sen0395:** ``reset``, ``settings``
17+
- **display_menu:** ``down``, ``enter``, ``hide``, ``left``, ``right``, ``show``, ``show_main``, ``up``
18+
- **ds1307:** ``read_time``, ``write_time``
19+
- **esp32_ble_tracker:** ``start_scan``, ``stop_scan``
20+
- **event:** ``trigger``
21+
- **ezo_pmp:** ``arbitrary_command``, ``change_i2c_address``, ``clear_calibration``, ``clear_total_volume_dosed``, ``dose_continuously``, ``dose_volume``, ``dose_volume_over_time``, ``dose_with_constant_flow_rate``, ``find``, ``pause_dosing``, ``set_calibration_volume``, ``stop_dosing``
22+
- **fan:** ``cycle_speed``, ``toggle``, ``turn_off``, ``turn_on``
23+
- **fingerprint_grow:** ``aura_led_control``, ``cancel_enroll``, ``delete``, ``delete_all``, ``enroll``, ``led_control``
24+
- **globals:** ``set``
25+
- **grove_tb6612fng:** ``break``, ``change_address``, ``no_standby``, ``run``, ``standby``, ``stop``
26+
- **homeassistant:** ``event``, ``service``, ``tag_scanned``
27+
- **http_request:** ``get``, ``post``, ``send``
28+
- **htu21d:** ``set_heater``, ``set_heater_level``
29+
- **light:** ``addressable_set``, ``control``, ``dim_relative``, ``toggle``, ``turn_off``, ``turn_on``
30+
- **lightwaverf:** ``send_raw``
31+
- **lock:** ``lock``, ``open``, ``unlock``
32+
- **logger:** ``log``
33+
- **max6956:** ``set_brightness_global``, ``set_brightness_mode``
34+
- **media_player:** ``pause``, ``play``, ``play_media``, ``stop``, ``toggle``, ``volume_down``, ``volume_set``, ``volume_up``
35+
- **mhz19:** ``abc_disable``, ``abc_enable``, ``calibrate_zero``
36+
- **micro_wake_word:** ``start``, ``stop``
37+
- **microphone:** ``capture``, ``stop_capture``
38+
- **midea_ac:** ``beeper_off``, ``beeper_on``, ``display_toggle``, ``follow_me``, ``power_off``, ``power_on``, ``power_toggle``, ``swing_step``
39+
- **mqtt:** ``publish``, ``publish_json``
40+
- **number:** ``decrement``, ``increment``, ``operation``, ``set``, ``to_max``, ``to_min``
41+
- **output:** ``set_level``, ``turn_off``, ``turn_on``
42+
- **pcf85063:** ``read_time``, ``write_time``
43+
- **pcf8563:** ``read_time``, ``write_time``
44+
- **pmwcs3:** ``air_calibration``, ``new_i2c_address``, ``water_calibration``
45+
- **pulse_counter:** ``set_total_pulses``
46+
- **pulse_meter:** ``set_total_pulses``
47+
- **pzemac:** ``reset_energy``
48+
- **pzemdc:** ``reset_energy``
49+
- **remote_transmitter:** ``transmit_abbwelcome``, ``transmit_aeha``, ``transmit_byronsx``, ``transmit_canalsat``, ``transmit_canalsatld``, ``transmit_coolix``, ``transmit_dish``, ``transmit_dooya``, ``transmit_drayton``, ``transmit_haier``, ``transmit_jvc``, ``transmit_keeloq``, ``transmit_lg``, ``transmit_magiquest``, ``transmit_midea``, ``transmit_mirage``, ``transmit_nec``, ``transmit_nexa``, ``transmit_panasonic``, ``transmit_pioneer``, ``transmit_pronto``, ``transmit_raw``, ``transmit_rc5``, ``transmit_rc6``, ``transmit_rc_switch_raw``, ``transmit_rc_switch_type_a``, ``transmit_rc_switch_type_b``, ``transmit_rc_switch_type_c``, ``transmit_rc_switch_type_d``, ``transmit_roomba``, ``transmit_samsung``, ``transmit_samsung36``, ``transmit_sony``, ``transmit_toshiba_ac``
50+
- **rf_bridge:** ``beep``, ``learn``, ``send_advanced_code``, ``send_code``, ``send_raw``, ``start_advanced_sniffing``, ``start_bucket_sniffing``, ``stop_advanced_sniffing``
51+
- **rtttl:** ``play``, ``stop``
52+
- **scd30:** ``force_recalibration_with_reference``
53+
- **scd4x:** ``factory_reset``, ``perform_forced_calibration``
54+
- **script:** ``execute``, ``stop``, ``wait``
55+
- **select:** ``first``, ``last``, ``next``, ``operation``, ``previous``, ``set``, ``set_index``
56+
- **sen5x:** ``start_fan_autoclean``
57+
- **senseair:** ``abc_disable``, ``abc_enable``, ``abc_get_period``, ``background_calibration``, ``background_calibration_result``
58+
- **servo:** ``detach``, ``write``
59+
- **sim800l:** ``connect``, ``dial``, ``disconnect``, ``send_sms``, ``send_ussd``
60+
- **speaker:** ``play``, ``stop``
61+
- **sprinkler:** ``clear_queued_valves``, ``next_valve``, ``pause``, ``previous_valve``, ``queue_valve``, ``resume``, ``resume_or_start_full_cycle``, ``set_divider``, ``set_multiplier``, ``set_repeat``, ``set_valve_run_duration``, ``shutdown``, ``start_from_queue``, ``start_full_cycle``, ``start_single_valve``
62+
- **sps30:** ``start_fan_autoclean``
63+
- **stepper:** ``report_position``, ``set_acceleration``, ``set_deceleration``, ``set_speed``, ``set_target``
64+
- **switch:** ``toggle``, ``turn_off``, ``turn_on``
65+
- **tag:** ``emulation_off``, ``emulation_on``, ``polling_off``, ``polling_on``, ``set_clean_mode``, ``set_emulation_message``, ``set_format_mode``, ``set_read_mode``, ``set_write_message``, ``set_write_mode``
66+
- **text:** ``set``
67+
- **tm1651:** ``set_brightness``, ``set_level``, ``set_level_percent``, ``turn_off``, ``turn_on``
68+
- **uart:** ``write``
69+
- **ufire_ec:** ``calibrate_probe``, ``reset``
70+
- **ufire_ise:** ``calibrate_probe_high``, ``calibrate_probe_low``, ``reset``
71+
- **update:** ``perform``
72+
- **valve:** ``close``, ``control``, ``open``, ``stop``, ``toggle``
73+
- **voice_assistant:** ``start``, ``start_continuous``, ``stop``
74+
- **wifi:** ``disable``, ``enable``
75+
- **wireguard:** ``disable``, ``enable``
76+

Diff for: automations/all_conditions.rst

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
- **alarm_control_panel:** ``is_armed``, ``ready``
2+
- **api:** ``connected``
3+
- **binary_sensor:** ``is_off``, ``is_on``
4+
- **ble:** ``enabled``
5+
- **dfplayer:** ``is_playing``
6+
- **display:** ``is_displaying_page``
7+
- **display_menu:** ``is_active``
8+
- **fan:** ``is_off``, ``is_on``
9+
- **light:** ``is_off``, ``is_on``
10+
- **lock:** ``is_locked``, ``is_unlocked``
11+
- **media_player:** ``is_idle``, ``is_playing``
12+
- **micro_wake_word:** ``is_running``
13+
- **microphone:** ``is_capturing``
14+
- **mqtt:** ``connected``
15+
- **number:** ``in_range``
16+
- **pn532:** ``is_writing``
17+
- **pn7150:** ``is_writing``
18+
- **pn7160:** ``is_writing``
19+
- **rtttl:** ``is_playing``
20+
- **script:** ``is_running``
21+
- **sensor:** ``in_range``
22+
- **speaker:** ``is_playing``
23+
- **sun:** ``is_above_horizon``, ``is_below_horizon``
24+
- **switch:** ``is_off``, ``is_on``
25+
- **text_sensor:** ``state``
26+
- **time:** ``has_time``
27+
- **update:** ``is_available``
28+
- **voice_assistant:** ``connected``, ``is_running``
29+
- **wifi:** ``connected``, ``enabled``
30+
- **wireguard:** ``enabled``, ``peer_online``
31+

Diff for: automations/index.rst

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
.. _automation:
2+
3+
Automation
4+
==========
5+
6+
.. seo::
7+
:description: Getting started guide for automations in ESPHome
8+
:image: auto-fix.svg
9+
10+
Automations are a very powerful aspect of ESPHome; they allow you to easily perform actions given some condition(s).
11+
12+
When you want your ESPHome device to respond to its environment, you use an automation. Here are some examples:
13+
14+
- Switch on a light when the cover is opened
15+
- Transmit an infrared (IR) code when I press this button
16+
- Turn on the heat when the temperature drops
17+
18+
This page serves as an index which will walk to through the process of using ESPHome automations--actions, triggers,
19+
templates, and more--to customize your ESPHome device just how you like it.
20+
21+
- :doc:`actions`
22+
- :doc:`templates`
23+
- :doc:`/components/globals`
24+
- :doc:`/components/script`
25+
- :doc:`/components/interval`
26+
27+
.. toctree::
28+
:glob:
29+
:maxdepth: 1
30+
:hidden:
31+
32+
*

Diff for: automations/templates.rst

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
.. _config-lambda:
2+
3+
Templates
4+
=========
5+
6+
.. seo::
7+
:description: Guide for using templates in ESPHome
8+
:image: auto-fix.svg
9+
10+
*Templates* (also known as *lambdas*) allow you to do almost *anything* in ESPHome. For example, if you want to only
11+
perform a certain automation if a certain complex formula evaluates to true, you can do that with templates. Let's look
12+
at an example first:
13+
14+
.. code-block:: yaml
15+
16+
binary_sensor:
17+
- platform: gpio
18+
name: "Cover End Stop"
19+
id: top_end_stop
20+
cover:
21+
- platform: template
22+
name: Living Room Cover
23+
lambda: !lambda |-
24+
if (id(top_end_stop).state) {
25+
return COVER_OPEN;
26+
} else {
27+
return COVER_CLOSED;
28+
}
29+
30+
What's happening here? First, we define a binary sensor (notably with ``id: top_end_stop``) and then a
31+
:doc:`template cover </components/cover/template>`. (If you're new to Home Assistant, a 'cover' is something like a
32+
window blind, a roller shutter, or a garage door.) The *state* of the template cover is controlled by a template, or
33+
"lambda". In lambdas, you're just writing C++ code and therefore the name lambda is used instead of Home Assistant's
34+
"template" lingo to avoid confusion. Regardless, don't let lambdas scare you just because you saw "C++" -- writing
35+
lambdas is not that hard! Here's a bit of a primer:
36+
37+
First, you might have already wondered what the ``lambda: !lambda |-`` part is supposed to mean. ``!lambda`` tells
38+
ESPHome that the following block is supposed to be interpreted as a lambda, or C++ code. Note that here, the
39+
``lambda:`` key would actually implicitly make the following block a lambda, so in this context, you could also have
40+
written ``lambda: |-``.
41+
42+
Next, there's the weird ``|-`` character combination. This tells the YAML parser to treat the following **indented**
43+
block as plaintext. Without it, the YAML parser would attempt to read the following block as if it were made up of YAML
44+
keys like ``cover:`` for example. (You may also have seen variations of this like ``>-`` or just ``|`` or ``>``. There
45+
is a slight difference in how these different styles deal with whitespace, but for our purposes we can ignore that).
46+
47+
With ``if (...) { ... } else { ... }`` we create a *condition*. What this effectively says that if the thing inside the
48+
first parentheses evaluates to ``true`` then execute the first block (in this case ``return COVER_OPEN;``, or else
49+
evaluate the second block. ``return ...;`` makes the code block give back a value to the template. In this case, we're
50+
either *returning* ``COVER_OPEN`` or ``COVER_CLOSED`` to indicate that the cover is closed or open.
51+
52+
Finally, ``id(...)`` is a helper function that makes ESPHome fetch an object with the supplied ID (which you defined
53+
somewhere else, like ``top_end_stop``) and lets you call any of ESPHome's many APIs directly. For example, here we're
54+
retrieving the current state of the end stop using ``.state`` and using it to construct our cover state.
55+
56+
.. note::
57+
58+
ESPHome does not check the validity of lambda expressions you enter and will blindly copy them into the generated
59+
C++ code. If compilation fails or something else is not working as expected with lambdas, it's always best to look
60+
at the generated C++ source file under ``<NODE_NAME>/src/main.cpp``.
61+
62+
.. tip::
63+
64+
To store local variables inside lambdas that retain their value across executions, you can create ``static``
65+
variables as shown in the example below. Here, the variable ``num_executions`` is incremented by one each time the
66+
lambda is executed and the current value is logged.
67+
68+
.. code-block:: yaml
69+
70+
lambda: |-
71+
static int num_executions = 0;
72+
ESP_LOGD("main", "I am at execution number %d", num_executions);
73+
num_executions += 1;
74+
75+
.. _config-templatable:
76+
77+
Templating Actions
78+
------------------
79+
80+
ESPHome allows you to template most parameters for actions used in automations. For example, if you have a light and
81+
want to set it to a pre-defined color when a button is pressed, you can do this:
82+
83+
.. code-block:: yaml
84+
85+
on_press:
86+
then:
87+
- light.turn_on:
88+
id: some_light_id
89+
transition_length: 0.5s
90+
red: 0.8
91+
green: 1.0
92+
blue: !lambda |-
93+
// The sensor outputs values from 0 to 100. The blue
94+
// part of the light color will be determined by the sensor value.
95+
return id(some_sensor).state / 100.0;
96+
97+
When you see the label "templatable" in the documentation for a given action, it can be templated as in this example,
98+
using the lambda syntax as described/shown above.
99+
100+
All Lambda Calls
101+
----------------
102+
103+
- :ref:`Sensor <sensor-lambda_calls>`
104+
- :ref:`Binary Sensor <binary_sensor-lambda_calls>`
105+
- :ref:`Switch <switch-lambda_calls>`
106+
- :ref:`Display <display-engine>`
107+
- :ref:`Cover <cover-lambda_calls>`
108+
- :ref:`Text Sensor <text_sensor-lambda_calls>`
109+
- :ref:`Stepper <stepper-lambda_calls>`
110+
- :ref:`Number <number-lambda_calls>`
111+
112+
See Also
113+
--------
114+
115+
- :doc:`index`
116+
- :doc:`actions`
117+
- :ghedit:`Edit`

Diff for: build_automations_pages.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import json
5+
6+
if __name__ == "__main__":
7+
file_name = "all_automations.json"
8+
arg_choices = ["actions", "conditions", "pin_providers"]
9+
10+
parser = argparse.ArgumentParser()
11+
parser.add_argument(
12+
"-t",
13+
"--type",
14+
choices=arg_choices,
15+
help="Automation type to extract ('actions', 'conditions', 'pin_providers')",
16+
)
17+
args = parser.parse_args()
18+
19+
with open(file_name) as json_file:
20+
raw_json = json.load(json_file)
21+
22+
if args.type not in arg_choices:
23+
print("Unrecognized automation type")
24+
exit()
25+
26+
automation_list = raw_json[args.type]
27+
28+
component_dict = {}
29+
30+
for item in automation_list:
31+
parts = item.split(".")
32+
if len(parts) == 2:
33+
if parts[0] not in component_dict:
34+
component_dict[parts[0]] = []
35+
component_dict[parts[0]].append(parts[1])
36+
37+
out_str = ""
38+
39+
for comp, autos in component_dict.items():
40+
out_str += f"- **{comp}:** "
41+
for item in autos:
42+
out_str += f"``{item}``, "
43+
out_str = out_str[:-2] + "\n"
44+
45+
print(out_str)

Diff for: components/button/template.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ Configuration variables:
2727
See Also
2828
--------
2929

30-
- :doc:`/guides/automations`
30+
- :doc:`/automations/index`
3131
- :doc:`/components/button/index`
3232
- :ghedit:`Edit`

Diff for: components/event/template.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ Configuration variables:
2626
See Also
2727
--------
2828

29-
- :doc:`/guides/automations`
29+
- :doc:`/automations/index`
3030
- :doc:`/components/event/index`
3131
- :ghedit:`Edit`

0 commit comments

Comments
 (0)