diff --git a/esphomeyaml/cookbook/dual-r2-cover.rst b/esphomeyaml/cookbook/dual-r2-cover.rst new file mode 100644 index 0000000000..f19a301647 --- /dev/null +++ b/esphomeyaml/cookbook/dual-r2-cover.rst @@ -0,0 +1,121 @@ +Dual relay cover motor control +============================== + +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 `__ 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->down->stop->... + +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. + +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 prevent accidentally switching on both relays simultaneously from MQTT/Home-assistant as that might be harmful for some motors. + +.. note:: + + 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 feature is implemented using asynchronous automations. So every time a open/close command is sent a delayed relay off command is added and old ones are not removed. + + + + +.. code:: yaml + + esphomeyaml: + name: cover + platform: espressif8266 + board: esp01_1m + board_flash_mode: dout + # required until next release (>1.6.2) + library_uri: 'https://github.com/OttoWinter/esphomelib.git' + + wifi: + ssid: '***' + password: '***' + + mqtt: + broker: 'mqtt' + username: '' + password: '' + + logger: + + ota: + + binary_sensor: + - platform: gpio + pin: + number: 10 + inverted: true + id: button + on_press: + then: + # logic for cycling through movements: open->stop->close->stop->... + - lambda: | + if (id(cover).state == cover::COVER_OPEN) { + if (id(open).value){ + // cover is in opening movement, stop it + id(cover).stop(); + } else { + // cover has finished opening, close it + id(cover).close(); + } + } else if (id(cover).state == cover::COVER_CLOSED) { + if (id(close).value){ + // cover is in closing movement, stop it + id(cover).stop(); + } else { + // cover has finished closing, open it + id(cover).open(); + } + } else { + // state of cover is not known + if (id(open).value || id(close).value){ + // cover is either opening or closing, stop it + id(cover).stop(); + } else { + id(cover).open(); + } + } + + switch: + - platform: gpio + pin: 12 + id: open + - platform: gpio + pin: 5 + id: close + + cover: + - platform: template + name: "Cover" + id: cover + open_action: + # cancel potential previous movement + - switch.turn_off: + id: close + # perform movement + - switch.turn_on: + id: open + # wait until cover is open + - delay: 60s + # turn of relay to prevent keeping the motor powered + - switch.turn_off: + id: open + close_action: + - switch.turn_off: + id: open + - switch.turn_on: + id: close + - delay: 60s + - switch.turn_off: + id: close + stop_action: + - switch.turn_off: + id: open + - switch.turn_off: + id: close + optimistic: true + +See Also +~~~~~~~~ + +- :doc:`/esphomeyaml/guides/automations` +- :doc:`/esphomeyaml/components/cover/template` +- :doc:`/esphomeyaml/devices/sonoff` +- `Edit this page on GitHub `__ diff --git a/esphomeyaml/cookbook/index.rst b/esphomeyaml/cookbook/index.rst index ece5ed9461..b524cf1bc8 100644 --- a/esphomeyaml/cookbook/index.rst +++ b/esphomeyaml/cookbook/index.rst @@ -9,3 +9,4 @@ Cookbook temt6000 relay power_meter + dual-r2-cover diff --git a/esphomeyaml/images/sonoff_dual_r2.jpg b/esphomeyaml/images/sonoff_dual_r2.jpg new file mode 100644 index 0000000000..8e0d1c8cd3 Binary files /dev/null and b/esphomeyaml/images/sonoff_dual_r2.jpg differ diff --git a/esphomeyaml/index.rst b/esphomeyaml/index.rst index e648932e34..0b68b5bcbc 100644 --- a/esphomeyaml/index.rst +++ b/esphomeyaml/index.rst @@ -513,6 +513,10 @@ This list contains items that are technically already supported by other compone |BRUH Multisensor|_ |TEMT6000|_ |Non-Invasive Power Meter|_ -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- `BRUH Multisensor`_ `TEMT6000`_ `Non-Invasive Power Meter`_ +-------------------------------------------------- -------------------------------------------------- -------------------------------------------------- +|Dual relay cover motor control|_ +-------------------------------------------------- -------------------------------------------------- -------------------------------------------------- +`Dual relay cover motor control`_ ================================================== ================================================== ================================================== .. |Garage Door| image:: /esphomeyaml/images/window-open.svg @@ -533,6 +537,9 @@ This list contains items that are technically already supported by other compone .. |Non-Invasive Power Meter| image:: /esphomeyaml/images/power_meter.jpg :class: component-image .. _Non-Invasive Power Meter: /esphomeyaml/cookbook/power_meter.html +.. |Dual relay cover motor control| image:: /esphomeyaml/images/sonoff_dual_r2.jpg + :class: component-image +.. _Dual relay cover motor control: /esphomeyaml/cookbook/dual-r2-cover.html Do you have other awesome automations or 2nd order components? Please feel free to add them to the documentation for others to copy. See :doc:`Contributing `.