2022-01-21 15:01:10 +01:00
|
|
|
|
Getting Started with the ESPHome Command Line
|
|
|
|
|
=============================================
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
2018-11-14 22:12:27 +01:00
|
|
|
|
.. seo::
|
2019-02-16 23:25:23 +01:00
|
|
|
|
:description: Getting Started guide for installing ESPHome using the command line and creating a basic configuration.
|
2021-11-16 03:19:33 +01:00
|
|
|
|
:image: console.svg
|
2018-11-14 22:12:27 +01:00
|
|
|
|
|
2019-10-19 22:16:09 +02:00
|
|
|
|
ESPHome is the perfect solution for creating custom firmwares for
|
|
|
|
|
your ESP8266/ESP32 boards. In this guide we’ll go through how to set up a
|
2018-05-13 11:37:02 +02:00
|
|
|
|
basic “node” in a few simple steps.
|
|
|
|
|
|
|
|
|
|
Installation
|
2018-10-12 16:33:22 +02:00
|
|
|
|
------------
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
2022-01-21 15:01:10 +01:00
|
|
|
|
See :doc:`installing_esphome`.
|
2021-11-03 19:55:26 +01:00
|
|
|
|
|
2022-01-21 15:01:10 +01:00
|
|
|
|
If you're familiar with Docker, you can use that instead! Our image supports
|
|
|
|
|
AMD64, ARM and ARM64 (AARCH64), and can be downloaded with:
|
2021-07-14 11:21:09 +02:00
|
|
|
|
|
2018-11-19 18:32:16 +01:00
|
|
|
|
.. code-block:: bash
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
2022-01-21 15:01:10 +01:00
|
|
|
|
docker pull esphome/esphome
|
|
|
|
|
|
2022-02-15 23:14:33 +01:00
|
|
|
|
If you want to use `docker-compose` instead, here's a sample file:
|
|
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
|
|
version: '3'
|
|
|
|
|
services:
|
|
|
|
|
esphome:
|
|
|
|
|
container_name: esphome
|
|
|
|
|
image: esphome/esphome
|
|
|
|
|
volumes:
|
|
|
|
|
- /path/to/esphome/config:/config
|
|
|
|
|
- /etc/localtime:/etc/localtime:ro
|
|
|
|
|
restart: always
|
|
|
|
|
privileged: true
|
|
|
|
|
network_mode: host
|
|
|
|
|
|
|
|
|
|
|
2022-01-21 15:01:10 +01:00
|
|
|
|
Connecting the ESP Device
|
|
|
|
|
-------------------------
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
2022-01-21 15:01:10 +01:00
|
|
|
|
Follow the instructions in :doc:`physical_device_connection` to connect to your
|
|
|
|
|
ESP device.
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
2022-01-21 15:01:10 +01:00
|
|
|
|
.. note::
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
2022-01-21 15:01:10 +01:00
|
|
|
|
The most difficult part of setting up a new ESPHome device is the initial
|
|
|
|
|
installation. Installation requires that your ESP device is connected with
|
|
|
|
|
a cable to a computer. Later updates can be installed wirelessly.
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
2019-10-18 09:22:48 +02:00
|
|
|
|
Creating a Project
|
2018-10-12 16:33:22 +02:00
|
|
|
|
------------------
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
2019-02-16 23:25:23 +01:00
|
|
|
|
Now let’s setup a configuration file. Fortunately, ESPHome has a
|
2018-05-13 11:37:02 +02:00
|
|
|
|
friendly setup wizard that will guide you through creating your first
|
|
|
|
|
configuration file. For example, if you want to create a configuration
|
|
|
|
|
file called ``livingroom.yaml``:
|
|
|
|
|
|
2018-11-19 18:32:16 +01:00
|
|
|
|
.. code-block:: bash
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
2021-06-28 21:49:25 +02:00
|
|
|
|
esphome wizard livingroom.yaml
|
2018-05-13 11:37:02 +02:00
|
|
|
|
# On Docker:
|
2021-06-08 01:21:53 +02:00
|
|
|
|
docker run --rm -v "${PWD}":/config -it esphome/esphome wizard livingroom.yaml
|
2018-06-01 18:10:00 +02:00
|
|
|
|
|
2018-05-13 11:37:02 +02:00
|
|
|
|
At the end of this step, you will have your first YAML configuration
|
2018-06-01 18:10:00 +02:00
|
|
|
|
file ready. It doesn't do much yet and only makes your device connect to
|
2019-02-16 23:25:23 +01:00
|
|
|
|
the WiFi network, but still it’s a first step.
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
|
|
|
|
Adding some features
|
2018-10-12 16:33:22 +02:00
|
|
|
|
--------------------
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
|
|
|
|
So now you should have a file called ``livingroom.yaml`` (or similar).
|
2018-06-01 18:10:00 +02:00
|
|
|
|
Go open that file in an editor of your choice and let’s add a :doc:`simple
|
2019-02-07 13:54:45 +01:00
|
|
|
|
GPIO switch </components/switch/gpio>` to our app.
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
2018-11-19 18:32:16 +01:00
|
|
|
|
.. code-block:: yaml
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
|
|
|
|
switch:
|
|
|
|
|
- platform: gpio
|
2018-10-20 15:10:26 +02:00
|
|
|
|
name: "Living Room Dehumidifier"
|
2018-05-13 11:37:02 +02:00
|
|
|
|
pin: 5
|
|
|
|
|
|
|
|
|
|
The configuration format should hopefully immediately seem similar to
|
2019-02-16 23:25:23 +01:00
|
|
|
|
you. ESPHome has tried to keep it as close to Home Assistant’s
|
2018-10-26 23:14:31 +02:00
|
|
|
|
``configuration.yaml`` schema as possible. In the above example, we’re
|
|
|
|
|
simply adding a switch that’s called “Living Room Dehumidifier” (could control
|
2018-05-13 11:37:02 +02:00
|
|
|
|
anything really, for example lights) and is connected to pin ``GPIO5``.
|
2019-02-16 23:25:23 +01:00
|
|
|
|
The nice thing about ESPHome is that it will automatically also try
|
2018-10-26 23:14:31 +02:00
|
|
|
|
to translate pin numbers for you based on the board. For example in the
|
2018-05-13 11:37:02 +02:00
|
|
|
|
above configuration, if using a NodeMCU board, you could have just as
|
|
|
|
|
well set ``D1`` as the ``pin:`` option.
|
|
|
|
|
|
2019-10-18 09:22:48 +02:00
|
|
|
|
First uploading
|
2018-10-12 16:33:22 +02:00
|
|
|
|
---------------
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
|
|
|
|
Now you can go ahead and add some more components. Once you feel like
|
|
|
|
|
you have something you want to upload to your ESP board, simply plug in
|
|
|
|
|
the device via USB and type the following command (replacing
|
|
|
|
|
``livingroom.yaml`` with your configuration file):
|
|
|
|
|
|
2018-11-19 18:32:16 +01:00
|
|
|
|
.. code-block:: bash
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
2021-06-08 01:21:53 +02:00
|
|
|
|
esphome run livingroom.yaml
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
2019-02-16 23:25:23 +01:00
|
|
|
|
You should see ESPHome validating the configuration and telling you
|
|
|
|
|
about potential problems. Then ESPHome will proceed to compile and
|
|
|
|
|
upload the custom firmware. You will also see that ESPHome created a
|
2020-05-10 21:27:59 +02:00
|
|
|
|
new folder with the name of your node. This is a new PlatformIO project
|
2018-05-13 11:37:02 +02:00
|
|
|
|
that you can modify afterwards and play around with.
|
|
|
|
|
|
2018-10-04 17:25:14 +02:00
|
|
|
|
If you are running docker on Linux you can add ``--device=/dev/ttyUSB0``
|
|
|
|
|
to your docker command to map a local USB device.
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
2018-11-19 18:32:16 +01:00
|
|
|
|
.. code-block:: bash
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
2021-06-08 01:21:53 +02:00
|
|
|
|
docker run --rm -v "${PWD}":/config --device=/dev/ttyUSB0 -it esphome/esphome run livingroom.yaml
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
2019-02-16 23:25:23 +01:00
|
|
|
|
Now when you go to the Home Assistant "Integrations" screen (under "Configuration" panel), you
|
2019-10-18 09:22:48 +02:00
|
|
|
|
should see the ESPHome device show up in the discovered section (although this can take up to 5 minutes).
|
2019-02-16 23:25:23 +01:00
|
|
|
|
Alternatively, you can manually add the device by clicking "CONFIGURE" on the ESPHome integration
|
|
|
|
|
and entering "<NODE_NAME>.local" as the host.
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
2019-02-07 13:54:45 +01:00
|
|
|
|
.. figure:: /components/switch/images/gpio-ui.png
|
2018-06-01 18:10:00 +02:00
|
|
|
|
:align: center
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
|
|
|
|
After the first upload, you will probably never need to use the USB
|
2019-02-16 23:25:23 +01:00
|
|
|
|
cable again, as all features of ESPHome are enabled remotely as well.
|
2018-05-13 11:37:02 +02:00
|
|
|
|
No more opening hidden boxes stowed in places hard to reach. Yay!
|
|
|
|
|
|
|
|
|
|
Adding A Binary Sensor
|
2018-10-12 16:33:22 +02:00
|
|
|
|
----------------------
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
|
|
|
|
Next, we’re going to add a very simple binary sensor that periodically
|
2019-10-18 09:22:48 +02:00
|
|
|
|
checks if a particular GPIO pin is pulled high or low - the :doc:`GPIO Binary
|
2019-02-07 13:54:45 +01:00
|
|
|
|
Sensor </components/binary_sensor/gpio>`.
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
2018-11-19 18:32:16 +01:00
|
|
|
|
.. code-block:: yaml
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
|
|
|
|
binary_sensor:
|
|
|
|
|
- platform: gpio
|
|
|
|
|
name: "Living Room Window"
|
|
|
|
|
pin:
|
|
|
|
|
number: 16
|
2021-07-28 23:56:11 +02:00
|
|
|
|
inverted: true
|
2021-11-03 19:55:26 +01:00
|
|
|
|
mode:
|
|
|
|
|
input: true
|
|
|
|
|
pullup: true
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
2019-02-16 23:25:23 +01:00
|
|
|
|
This is an advanced feature of ESPHome. Almost all pins can
|
2018-05-13 11:37:02 +02:00
|
|
|
|
optionally have a more complicated configuration schema with options for
|
2018-06-01 18:10:00 +02:00
|
|
|
|
inversion and pinMode - the :ref:`Pin Schema <config-pin_schema>`.
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
|
|
|
|
This time when uploading, you don’t need to have the device plugged in
|
|
|
|
|
through USB again. The upload will magically happen “over the air”.
|
2019-02-16 23:25:23 +01:00
|
|
|
|
Using ESPHome directly, this is the same as from a USB cable, but
|
2018-05-13 11:37:02 +02:00
|
|
|
|
for docker you need to supply an additional parameter:
|
|
|
|
|
|
2018-11-19 18:32:16 +01:00
|
|
|
|
.. code-block:: bash
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
2019-02-16 23:25:23 +01:00
|
|
|
|
esphome livingroom.yaml run
|
2018-05-13 11:37:02 +02:00
|
|
|
|
# On docker
|
2021-06-08 01:21:53 +02:00
|
|
|
|
docker run --rm -v "${PWD}":/config -it esphome/esphome run livingroom.yaml
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
2019-02-07 13:54:45 +01:00
|
|
|
|
.. figure:: /components/binary_sensor/images/gpio-ui.png
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
|
|
|
|
Where To Go Next
|
2018-10-12 16:33:22 +02:00
|
|
|
|
----------------
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
2019-10-19 22:16:09 +02:00
|
|
|
|
Great 🎉! You’ve now successfully set up your first ESPHome project
|
2019-02-16 23:25:23 +01:00
|
|
|
|
and uploaded your first ESPHome custom firmware to your node. You’ve
|
2018-05-13 11:37:02 +02:00
|
|
|
|
also learned how to enable some basic components via the configuration
|
|
|
|
|
file.
|
|
|
|
|
|
2019-02-07 13:54:45 +01:00
|
|
|
|
So now is a great time to go take a look at the :doc:`Components Index </index>`.
|
2019-10-19 22:16:09 +02:00
|
|
|
|
Hopefully you’ll find all sensors/outputs/etc. you’ll need in there. If you’re having any problems or
|
2018-05-13 11:37:02 +02:00
|
|
|
|
want new features, please either create a new issue on the `GitHub issue
|
2019-02-16 23:25:23 +01:00
|
|
|
|
tracker <https://github.com/esphome/issues/issues>`__ or find us on the
|
|
|
|
|
`Discord chat <https://discord.gg/KhAMKrd>`__ (also make sure to read the :doc:`FAQ <faq>`).
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
2019-02-16 23:25:23 +01:00
|
|
|
|
Bonus: ESPHome dashboard
|
|
|
|
|
------------------------
|
2018-06-01 18:10:00 +02:00
|
|
|
|
|
2019-02-16 23:25:23 +01:00
|
|
|
|
ESPHome features a dashboard that you can use to easily manage your nodes
|
|
|
|
|
from a nice web interface. It was primarily designed for
|
2021-05-20 16:36:42 +02:00
|
|
|
|
:doc:`the Home Assistant add-on <getting_started_hassio>`, but also works with a simple command on
|
2019-02-16 23:33:36 +01:00
|
|
|
|
\*nix machines (sorry, no windows).
|
2018-06-01 18:10:00 +02:00
|
|
|
|
|
2019-02-16 23:25:23 +01:00
|
|
|
|
To start the ESPHome dashboard, simply start ESPHome with the following command
|
2018-06-01 18:10:00 +02:00
|
|
|
|
(with ``config/`` pointing to a directory where you want to store your configurations)
|
|
|
|
|
|
2018-11-19 18:32:16 +01:00
|
|
|
|
.. code-block:: bash
|
2018-06-01 18:10:00 +02:00
|
|
|
|
|
|
|
|
|
# Install dashboard dependencies
|
2019-10-19 22:16:09 +02:00
|
|
|
|
pip install tornado esptool
|
2021-06-08 01:21:53 +02:00
|
|
|
|
esphome dashboard config/
|
2018-06-01 18:10:00 +02:00
|
|
|
|
|
2019-10-19 22:16:09 +02:00
|
|
|
|
# On Docker, host networking mode is required for online status indicators
|
2019-02-16 23:25:23 +01:00
|
|
|
|
docker run --rm --net=host -v "${PWD}":/config -it esphome/esphome
|
2018-06-01 18:10:00 +02:00
|
|
|
|
|
2020-09-15 17:45:19 +02:00
|
|
|
|
# On Docker with MacOS, the host networking option doesn't work as expected. An
|
|
|
|
|
# alternative is to use the following command if you are a MacOS user.
|
|
|
|
|
docker run --rm -p 6052:6052 -e ESPHOME_DASHBOARD_USE_PING=true -v "${PWD}":/config -it esphome/esphome
|
|
|
|
|
|
|
|
|
|
|
2018-06-01 18:10:00 +02:00
|
|
|
|
After that, you will be able to access the dashboard through ``localhost:6052``.
|
|
|
|
|
|
2022-01-20 23:16:50 +01:00
|
|
|
|
.. figure:: images/dashboard_states.png
|
2018-06-01 18:10:00 +02:00
|
|
|
|
|
|
|
|
|
See Also
|
2018-10-12 16:33:22 +02:00
|
|
|
|
--------
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
2021-01-13 17:32:31 +01:00
|
|
|
|
- :doc:`cli`
|
2019-02-07 13:54:45 +01:00
|
|
|
|
- :doc:`ESPHome index </index>`
|
2018-06-01 18:10:00 +02:00
|
|
|
|
- :doc:`getting_started_hassio`
|
2019-02-07 13:54:45 +01:00
|
|
|
|
- :ghedit:`Edit`
|