esphome-docs/components/switch/gpio.rst

85 lines
2.6 KiB
ReStructuredText
Raw Normal View History

2018-05-13 11:37:02 +02:00
GPIO Switch
===========
2018-11-14 22:12:27 +01:00
.. seo::
:description: Instructions for setting up GPIO pin switches in esphomelib that control GPIO outputs.
:image: pin.png
2018-11-14 22:12:27 +01:00
2018-05-13 11:37:02 +02:00
The ``gpio`` switch platform allows you to use any pin on your node as a
switch. You can for example hook up a relay to a GPIO pin and use it
through this platform.
2018-06-01 18:10:00 +02:00
.. figure:: images/gpio-ui.png
:align: center
:width: 80.0%
2018-05-13 11:37:02 +02:00
.. code-block:: yaml
2018-05-13 11:37:02 +02:00
# Example configuration entry
switch:
- platform: gpio
pin: 25
name: "Living Room Dehumidifier"
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
- **pin** (**Required**, :ref:`Pin Schema <config-pin_schema>`): The
GPIO pin to use for the switch.
- **name** (**Required**, string): The name for the switch.
- **id** (*Optional*, :ref:`config-id`): Manually specify the ID used for code generation.
2019-01-06 18:56:14 +01:00
- **restore_mode** (*Optional*): Control how the GPIO Switch attempts to restore state on bootup.
- ``RESTORE_DEFAULT_OFF`` (Default) - Attempt to restore state and default to OFF if not possible to restore.
- ``RESTORE_DEFAULT_ON`` - Attempt to restore state and default to ON.
- ``ALWAYS_OFF`` - Always initialize the pin as OFF on bootup.
- ``ALWAYS_ON`` - Always initialize the pin as ON on bootup.
2018-06-01 18:10:00 +02:00
- All other options from :ref:`Switch <config-switch>` and :ref:`MQTT Component <config-mqtt-component>`.
2019-01-06 18:56:14 +01:00
To create an active-low switch (one that is turned off by default), use the :ref:`Pin Schema <config-pin_schema>`:
.. code-block:: yaml
# Example configuration entry
switch:
- platform: gpio
pin:
number: 25
inverted: yes
To create momentary switches, for example switches that toggle a pin for a moment, you can use :doc:`template switches <template>`.
An example that uses a single relay to activate a remote control button. The button can only start or stop the motor of the gate. In itself, the button or remote can not know if it opens or closes the gate. The relay simulates the button press for 500ms.
2019-01-06 18:56:14 +01:00
.. code-block:: yaml
2019-01-06 18:56:14 +01:00
# Example configuration entry
switch:
- platform: gpio
pin: 25
id: relay
- platform: template
name: "Gate Remote"
icon: "mdi:gate"
optimistic: no
2019-01-06 18:56:14 +01:00
turn_on_action:
- switch.turn_on: relay
- delay: 500ms
2019-01-06 18:56:14 +01:00
- switch.turn_off: relay
.. figure:: images/gate-remote-ui.png
:align: center
2018-06-01 18:10:00 +02:00
See Also
2018-08-24 22:44:01 +02:00
--------
2018-06-01 18:10:00 +02:00
- :doc:`index`
- :doc:`/components/output/gpio`
- :doc:`/components/cover/template`
- :doc:`/cookbook/garage-door`
- :apiref:`switch_/gpio_switch.h`
- :ghedit:`Edit`
2018-10-12 16:33:22 +02:00
.. disqus::