esphome-docs/cookbook/dual-r2-cover.rst

102 lines
3.2 KiB
ReStructuredText
Raw Normal View History

Dual relay cover motor control
==============================
2018-11-14 22:12:27 +01:00
.. seo::
2019-02-16 23:25:23 +01:00
:description: An example of how to integrate covers that are controlled by two relays into ESPHome.
2018-11-14 22:12:27 +01:00
:image: sonoff_dual_r2.jpg
:keywords: Relay, Sonoff Dual R2, Cover
2018-11-04 22:19:14 +01:00
The following is a possible configuration file for common covers that use a motor with 2 inputs.
Only one should be powered at a time (interlocking) to either move the cover up or down. For this
the `Sonoff Dual R2 <https://www.itead.cc/sonoff-dual.html>`__ can be used which has two independent
relays. Additionally this configuration allows the single button on the Sonoff to control the motion
by cycling between: open->stop->close->stop->...
2018-11-04 22:19:14 +01:00
These kind of motors automatically stop when the end of the cover movement is reached. However,
to be safe, this automation stops powering the motor after 1 minute of movement. In the rare case
of the end-stop switch in the motor failing this will reduce the risk for damage or fire.
2018-11-04 22:19:14 +01:00
Of the four main components (button sensor, 2 relays switches and the cover), only the cover will be
visible to the end-user. The other three are hidden by means of not including a ``name``. This is to
2019-02-17 12:28:17 +01:00
prevent accidentally switching on both relays simultaneously from Home Assistant as that might be harmful
2018-11-04 22:19:14 +01:00
for some motors.
.. note::
2018-11-04 22:19:14 +01:00
Controlling the cover to quickly (sending new open/close commands within a minute of previous commands)
might cause unexpected behaviour (eg: cover stopping halfway). This is because the delayed relay off
2019-10-21 20:35:56 +02:00
feature is implemented using asynchronous automations. So every time an open/close command is sent a
2018-11-04 22:19:14 +01:00
delayed relay off command is added and old ones are not removed.
.. code-block:: yaml
2019-02-27 18:32:47 +01:00
esphome:
2019-03-11 13:18:15 +01:00
name: cover
2022-02-10 23:10:43 +01:00
esp8266:
2019-03-11 13:18:15 +01:00
board: esp01_1m
2019-02-27 18:32:47 +01:00
wifi:
2022-02-10 23:10:43 +01:00
ssid: !secret wifi_ssid
password: !secret wifi_password
2019-02-27 18:32:47 +01:00
api:
2019-02-27 18:32:47 +01:00
logger:
2019-02-27 18:32:47 +01:00
ota:
2019-02-27 18:32:47 +01:00
binary_sensor:
- platform: gpio
pin:
2019-03-11 13:18:15 +01:00
number: GPIO10
inverted: true
id: button
on_press:
then:
# logic for cycling through movements: open->stop->close->stop->...
- lambda: |
2019-05-31 21:29:38 +02:00
if (id(my_cover).current_operation == COVER_OPERATION_IDLE) {
// Cover is idle, check current state and either open or close cover.
if (id(my_cover).is_fully_closed()) {
id(my_cover).open();
} else {
2019-05-31 21:29:38 +02:00
id(my_cover).close();
}
} else {
2019-05-31 21:29:38 +02:00
// Cover is opening/closing. Stop it.
id(my_cover).stop();
}
2019-02-27 18:32:47 +01:00
switch:
- platform: gpio
2019-03-11 13:18:15 +01:00
pin: GPIO12
2019-05-31 21:29:38 +02:00
interlock: &interlock [open_cover, close_cover]
id: open_cover
- platform: gpio
2019-03-11 13:18:15 +01:00
pin: GPIO5
2019-05-31 21:29:38 +02:00
interlock: *interlock
id: close_cover
2019-02-27 18:32:47 +01:00
cover:
2019-05-12 22:44:59 +02:00
- platform: time_based
name: "Cover"
2019-05-31 21:29:38 +02:00
id: my_cover
open_action:
2019-05-31 21:29:38 +02:00
- switch.turn_on: open_cover
2019-05-12 22:44:59 +02:00
open_duration: 60s
close_action:
2019-05-31 21:29:38 +02:00
- switch.turn_on: close_cover
2019-05-12 22:44:59 +02:00
close_duration: 60s
stop_action:
2019-05-31 21:29:38 +02:00
- switch.turn_off: open_cover
- switch.turn_off: close_cover
See Also
2018-08-24 22:44:01 +02:00
--------
- :doc:`/guides/automations`
2019-05-12 22:44:59 +02:00
- :doc:`/components/cover/time_based`
- :doc:`/devices/sonoff`
- :ghedit:`Edit`