2018-05-13 11:37:02 +02:00
Web Server Component
====================
2018-11-14 22:12:27 +01:00
.. seo ::
2019-02-16 23:25:23 +01:00
:description: Instructions for setting up a web server in ESPHome.
2021-11-16 03:19:33 +01:00
:image: http.svg
2018-11-14 22:12:27 +01:00
:keywords: web server, http, REST API
2018-05-13 11:37:02 +02:00
The `` web_server `` component creates a simple web server on the node that can be accessed
2023-06-01 11:24:00 +02:00
through any browser and a simple :ref: `api-rest` . Please note that enabling this component
2023-06-01 13:14:44 +02:00
will take up *a lot* of memory and may decrease stability, especially on ESP8266.
2018-05-13 11:37:02 +02:00
2019-02-07 13:54:45 +01:00
.. figure :: /components/images/web_server.png
2023-06-01 16:03:01 +02:00
:align: center
:width: 86.0%
Web server version 1
2018-05-13 11:37:02 +02:00
2022-04-22 04:04:23 +02:00
.. figure :: /components/images/web_server-v2.png
2023-06-01 16:03:01 +02:00
:align: center
:width: 86.0%
Web server version 2
To navigate to the web server in your browser, either use the IP address of the node or
use `` <node_name>.local/ `` (note the trailing forward slash) via mDNS.
2022-03-08 03:02:30 +01:00
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
# Example configuration entry
web_server:
port: 80
2020-06-10 03:02:14 +02:00
2018-05-13 11:37:02 +02:00
Configuration variables:
2018-08-24 22:44:01 +02:00
------------------------
2018-05-13 11:37:02 +02:00
2018-06-01 18:10:00 +02:00
- **port** (*Optional* , int): The port the web server should open its socket on.
- **css_url** (*Optional* , url): The URL that should be used for the CSS stylesheet. Defaults
2020-02-20 13:06:26 +01:00
to https://esphome.io/_static/webserver-v1.min.css (updates will go to `` v2 `` , `` v3 `` , etc). Can be set to empty string.
2020-06-10 03:02:14 +02:00
- **css_include** (*Optional* , local file): Path to local file to be included in web server index page.
2020-02-20 13:06:26 +01:00
Contents of this file will be served as `` /0.css `` and used as CSS stylesheet by internal webserver.
Useful when building device without internet access, where you want to use built-in AP and webserver.
2018-06-01 18:10:00 +02:00
- **js_url** (*Optional* , url): The URL that should be used for the JS script. Defaults
2020-02-20 13:06:26 +01:00
to https://esphome.io/_static/webserver-v1.min.js. Can be set to empty string.
- **js_include** (*Optional* , local file): Path to local file to be included in web server index page.
Contents of this file will be served as `` /0.js `` and used as JS script by internal webserver.
Useful when building device without internet access, where you want to use built-in AP and webserver.
2023-06-01 16:03:01 +02:00
- **auth** (*Optional* ): Enables a simple *Digest* authentication with username and password.
2019-10-13 14:28:02 +02:00
- **username** (**Required** , string): The username to use for authentication.
- **password** (**Required** , string): The password to check for authentication.
2021-11-29 16:52:34 +01:00
- **include_internal** (*Optional* , boolean): Whether `` internal `` entities should be displayed on the
web interface. Defaults to `` false `` .
2022-04-03 09:30:25 +02:00
- **ota** (*Optional* , boolean): Turn on or off the OTA feature inside webserver. Strongly not suggested without enabled authentication settings. Defaults to `` true `` .
2018-06-01 18:10:00 +02:00
- **id** (*Optional* , :ref: `config-id` ): Manually specify the ID used for code generation.
2022-07-25 05:01:10 +02:00
- **local** (*Optional* , boolean): Include supporting javascript locally allowing it to work without internet access. Defaults to `` false `` .
2022-04-22 04:04:23 +02:00
- **version** (*Optional* , string): `` 1 `` or `` 2 `` . Version 1 displays as a table. Version 2 uses web components and has more functionality. Defaults to `` 2 `` .
2018-06-01 18:10:00 +02:00
2023-06-01 16:03:01 +02:00
To conserve flash size, the CSS and JS files used on the root page to show a simple user
interface are hosted by esphome.io. If you want to use your own service, use the
`` css_url `` and `` js_url `` options in your configuration.
2018-11-09 20:06:40 +01:00
2023-06-01 16:03:01 +02:00
Example configurations:
-----------------------
2019-10-13 14:28:02 +02:00
2023-06-01 16:03:01 +02:00
Enabling HTTP authentication:
2019-10-13 14:28:02 +02:00
2023-06-01 16:03:01 +02:00
.. code-block :: yaml
2022-04-22 04:04:23 +02:00
2023-06-01 16:03:01 +02:00
# Example configuration entry
web_server:
port: 80
auth:
username: !secret web_server_username
password: !secret web_server_password
2020-02-20 13:06:26 +01:00
2023-06-01 16:03:01 +02:00
Use version 1 user interface:
2020-02-20 13:06:26 +01:00
2023-06-01 16:03:01 +02:00
.. code-block :: yaml
2022-04-22 04:04:23 +02:00
2023-06-01 16:03:01 +02:00
# Example configuration entry
web_server:
port: 80
version: 1
2022-03-08 03:02:30 +01:00
2023-06-01 16:03:01 +02:00
No internet/intranet required on the clients (all assets are inlined, compressed and served from flash):
2022-03-08 03:02:30 +01:00
2023-06-01 16:03:01 +02:00
.. code-block :: yaml
2022-04-22 04:04:23 +02:00
2023-06-01 16:03:01 +02:00
# Example configuration entry
web_server:
local: true
2022-04-22 04:04:23 +02:00
2022-03-08 03:02:30 +01:00
2023-06-01 13:14:44 +02:00
Advanced usage
2023-06-01 16:03:01 +02:00
--------------
2022-04-22 04:04:23 +02:00
2022-03-08 03:02:30 +01:00
The following assume copies of the files with local paths - which are config dependant.
2023-06-01 13:14:44 +02:00
Example `` web_server `` version 1 configuration with CSS and JS included from esphome-docs.
2022-03-08 03:02:30 +01:00
CSS and JS URL's are set to empty value, so no internet access is needed for this device to show it's web interface.
Force to turn off OTA function because the missing authentication.
.. code-block :: yaml
web_server:
port: 80
2022-11-06 07:15:57 +01:00
version: 1
2022-03-08 03:02:30 +01:00
ota: false
css_include: "../../../esphome-docs/_static/webserver-v1.min.css"
2022-11-06 07:15:57 +01:00
css_url: ""
2022-03-08 03:02:30 +01:00
js_include: "../../../esphome-docs/_static/webserver-v1.min.js"
js_url: ""
2023-06-01 13:14:44 +02:00
Example `` web_server `` version 2 configuration with JS included from a local file.
2022-03-08 03:02:30 +01:00
CSS and JS URL's are set to empty value, so no internet access is needed for this device to show it's web interface.
V2 embeds the css within the js file so is not required, however you could include your own CSS.
.. code-block :: yaml
2023-06-01 13:14:44 +02:00
# Example configuration entry v2
2022-03-08 03:02:30 +01:00
web_server:
js_include: "./v2/www.js"
js_url: ""
version: 2
Copy https://oi.esphome.io/v2/www.js to a V2 folder in your yaml folder.
2022-04-22 04:04:23 +02:00
2020-02-20 13:06:26 +01:00
2018-06-01 18:10:00 +02:00
See Also
--------
2023-06-01 11:24:00 +02:00
- :ref: `api-event-source`
- :ref: `api-rest`
2019-05-12 22:44:59 +02:00
- :apiref: `web_server/web_server.h`
2020-07-27 12:06:56 +02:00
- :doc: `prometheus`
2019-02-07 13:54:45 +01:00
- :ghedit: `Edit`