esphome-docs/guides/getting_started_command_line.rst

236 lines
8.3 KiB
ReStructuredText
Raw Normal View History

2018-05-13 11:37:02 +02:00
Getting Started with esphomeyaml
================================
2018-11-14 22:12:27 +01:00
.. seo::
:description: Getting Started guide for installing esphomeyaml using the command line and creating a basic configuration.
:image: console.png
2018-11-14 22:12:27 +01:00
2018-05-13 11:37:02 +02:00
esphomeyaml is the perfect solution for creating custom firmwares for
your ESP8266/ESP32 boards. In this guide well go through how to setup a
basic “node” in a few simple steps.
Installation
2018-10-12 16:33:22 +02:00
------------
2018-05-13 11:37:02 +02:00
2018-10-20 15:10:26 +02:00
Installing esphomeyaml is very easy. All you need to do is have `Python
2018-05-13 11:37:02 +02:00
2.7 <https://www.python.org/download/releases/2.7/>`__ installed
(because of platformio 😕) and install the console script script through
``pip``.
.. code-block:: bash
2018-05-13 11:37:02 +02:00
pip install esphomeyaml
Alternatively, theres also a docker image available for easy
installation (the docker hub image is only available for amd64 right now; if you have
2018-11-26 16:50:50 +01:00
an RPi, please install esphomelib through ``pip`` or use :doc:`the Hass.io add-on <getting_started_hassio>`:
2018-05-13 11:37:02 +02:00
.. code-block:: bash
2018-05-13 11:37:02 +02:00
docker pull ottowinter/esphomeyaml
Creating A Project
2018-10-12 16:33:22 +02:00
------------------
2018-05-13 11:37:02 +02:00
Now lets setup a configuration file. Fortunately, esphomeyaml has a
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``:
.. code-block:: bash
2018-05-13 11:37:02 +02:00
esphomeyaml livingroom.yaml wizard
# On Docker:
docker run --rm -v ${PWD}:/config -it ottowinter/esphomeyaml livingroom.yaml wizard
2018-05-13 11:37:02 +02:00
2018-06-01 18:10:00 +02:00
.. note::
If you have trouble with installing esphomeyaml and see errors like "command not found",
try running ``python2 -m esphomeyaml livingroom.yaml wizard``.
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
2018-05-13 11:37:02 +02:00
the WiFi network and MQTT broker, but still its a first step.
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 lets add a :doc:`simple
GPIO switch </components/switch/gpio>` to our app.
2018-05-13 11:37:02 +02: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
you. esphomeyaml has tried to keep it as close to Home Assistants
``configuration.yaml`` schema as possible. In the above example, were
simply adding a switch thats 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``.
The nice thing about esphomeyaml is that it will automatically also try
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.
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):
.. code-block:: bash
2018-05-13 11:37:02 +02:00
esphomeyaml livingroom.yaml run
You should see esphomeyaml validating the configuration and telling you
about potential problems. Then esphomeyaml will proceed to compile and
upload the custom firmware. You will also see that esphomeyaml created a
new folder with the name of your node. This is a new platformio project
that you can modify afterwards and play around with.
On docker, the first upload is a bit more complicated, either you manage
to map the serial device into docker with the ``-v`` option, or you just
call ``compile`` within the container and let platformio do the
uploading on the host system.
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
.. code-block:: bash
2018-05-13 11:37:02 +02:00
docker run --rm -v "`pwd`":/config -it ottowinter/esphomeyaml livingroom.yaml compile
platformio run -d livingroom -t upload
Now if you have `MQTT
Discovery <https://www.home-assistant.io/docs/mqtt/discovery/>`__
enabled in your Home Assistant configuration, the switch should already
be automatically be added 🎉 (Make sure youve added it to a view too.)
.. 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
cable again, as all features of esphomelib are enabled remotely as well.
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, were going to add a very simple binary sensor that periodically
2018-06-01 18:10:00 +02:00
checks a GPIO pin whether its pulled high or low - the :doc:`GPIO Binary
Sensor </components/binary_sensor/gpio>`.
2018-05-13 11:37:02 +02:00
.. code-block:: yaml
2018-05-13 11:37:02 +02:00
binary_sensor:
- platform: gpio
name: "Living Room Window"
pin:
number: 16
inverted: True
mode: INPUT_PULLUP
This is an advanced feature of esphomeyaml. 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 dont need to have the device plugged in
through USB again. The upload will magically happen “over the air”.
Using esphomeyaml directly, this is the same as from a USB cable, but
for docker you need to supply an additional parameter:
.. code-block:: bash
2018-05-13 11:37:02 +02:00
esphomeyaml livingroom.yaml run
# On docker
docker run --rm -p 6123:6123 -v "`pwd`":/config -it ottowinter/esphomeyaml livingroom.yaml run
.. 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
Great 🎉! Youve now successfully setup your first esphomeyaml project
and uploaded your first esphomelib custom firmware to your node. Youve
also learned how to enable some basic components via the configuration
file.
So now is a great time to go take a look at the :doc:`Components Index </index>`.
Hopefully youll find all sensors/outputs/… youll need in there. If youre 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
tracker <https://github.com/OttoWinter/esphomeyaml/issues>`__ or contact
me via the `Discord chat <https://discord.gg/KhAMKrd>`__.
2018-06-01 18:10:00 +02:00
Bonus: esphomeyaml dashboard
2018-10-12 16:33:22 +02:00
----------------------------
2018-06-01 18:10:00 +02:00
Starting with version 1.6.0, esphomeyaml features a dashboard that you can use to
2018-06-01 18:10:00 +02:00
easily manage your nodes from a nice web interface. It was primarily designed for
2018-11-26 16:50:50 +01:00
:doc:`the Hass.io add-on <getting_started_hassio>`, but also works with a simple command.
2018-06-01 18:10:00 +02:00
To start the esphomeyaml dashboard, simply start esphomeyaml with the following command
(with ``config/`` pointing to a directory where you want to store your configurations)
.. code-block:: bash
2018-06-01 18:10:00 +02:00
# Install dashboard dependencies
pip2 install tornado esptool
esphomeyaml config/ dashboard
# On docker
docker run --rm -p 6052:6052 -p 6123:6123 -v "`pwd`":/config -it ottowinter/esphomeyaml /config dashboard
After that, you will be able to access the dashboard through ``localhost:6052``.
.. figure:: images/dashboard.png
2018-05-13 11:37:02 +02:00
Using Custom components
2018-10-12 16:33:22 +02:00
-----------------------
2018-05-13 11:37:02 +02:00
esphomelibs powerful core makes it easy to create own custom sensors.
Please first follow the `Custom Sensor Component
Guide <https://github.com/OttoWinter/esphomelib/wiki/Custom-Sensor-Component>`__
to see how this can be done. For using custom components with
esphomeyaml you only need to open up the auto-generated ``src/main.cpp``
file in the platformio project folder. The lines in between
``AUTO GENERATED CODE BEGIN`` and ``AUTO GENERATED CODE END`` should not
be edited and all changes in there will be overriden, but outside of
those comments you can safely create custom sensors while still using
esphomeyamls great configuration options.
.. code-block:: cpp
2018-05-13 11:37:02 +02:00
// Auto generated code by esphomeyaml
#include "esphomelib/application.h"
using namespace esphomelib;
void setup() {
// ===== DO NOT EDIT ANYTHING BELOW THIS LINE =====
// ========== AUTO GENERATED CODE BEGIN ===========
App.set_name("cabinet");
// ...
// =========== AUTO GENERATED CODE END ============
// ========= YOU CAN EDIT AFTER THIS LINE =========
App.setup();
}
void loop() {
App.loop();
}
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
- :doc:`ESPHome index </index>`
2018-06-01 18:10:00 +02:00
- :doc:`getting_started_hassio`
- :ghedit:`Edit`
2018-10-12 16:33:22 +02:00
.. disqus::