Internal Automations
Prepare some internal automations!
Internal Automations
The ESP Cover Mix allows for a wide range of internal automations, from simple toggles to advanced multi-click actions. This guide covers the most common use cases for both covers and relays.
Part 1: Automations for Covers
Advanced Control with on_multi_click
For the most intuitive control of venetian blinds (or standard shutters), you can use ESPHome's on_multi_click feature. This allows you to assign different actions to short and long presses of a momentary switch, giving you full control over movement and tilt with just two buttons.
binary_sensor:
# UP Button
- platform: gpio
name: 'IN_01'
id: in_01
on_multi_click:
- timing:
- ON for at least 2s # Long press
then:
- lambda: 'id(cover_01).make_call().set_command_open().perform();'
- timing:
- ON for at most 0.4s # Short press
then:
- lambda: 'id(cover_01).make_call().set_command_stop().perform();'
# DOWN Button
- platform: gpio
name: 'IN_02'
id: in_02
on_multi_click:
- timing:
- ON for at least 2s # Long press
then:
- lambda: 'id(cover_01).make_call().set_command_close().perform();'
- timing:
- ON for at most 0.4s # Short press
then:
- lambda: 'id(cover_01).make_call().set_command_stop().perform();'How It Works:
- Long Press: Fully opens or closes the cover.
- Short Press: Stops the cover at its current position.
The example above is simplified. For a more advanced version that includes tilt control for venetian blinds, please refer to the ESP Cover documentation.
Part 2: Automations for Relays
Automations for the general-purpose relays are typically simpler.
Simple Toggle with on_press
The most common automation is to toggle a light or a switch with a single button press.
binary_sensor:
- platform: gpio
name: 'Garden Light Switch'
id: in_17
pin:
pcf8574: pcf_inputs_15to32 # Or the correct PCF
number: 2 # Corresponds to IN_17
on_press:
then:
- light.toggle: light_17This configuration will turn light_17 on if it's off, and off if it's on, every time the button connected to IN_17 is pressed.
Using Bistable (On/Off) Switches
If you are using bistable (on/off) switches instead of momentary ones, you can define separate actions for on_press (when the switch is turned on) and on_release (when it's turned off).
binary_sensor:
- platform: gpio
name: 'Garage Power Switch'
id: in_18
on_press:
then:
- switch.turn_on: switch_18
on_release:
then:
- switch.turn_off: switch_18