AboutBlogContact

Internal Automations

Prepare some internal automations!

What are Internal Automations?

Internal automations are a powerful way to create simple, core automations that run directly on your boneIO ESP controller. This means they will work even if your main smart home hub (like Home Assistant) is offline. They are perfect for critical functions, like turning on a light with a wall switch.

Basic Automation: Toggling a Light

Let's start with a default configuration that links a button press to a light.

binary_sensor:
  - platform: gpio
    name: 'IN_01_Bedroom_Button1'
    id: in_01
    pin:
      pcf8574: pcf_inputs_1to14
      number: 0
      mode:
        input: true
      inverted: true
    on_press: # This is our automation trigger
      then:
        - light.toggle: light_01 # This is the action to perform

light:
  - platform: binary
    name: 'Light 01'
    output: out_01
    id: light_01

In the on_press: section, we define what happens when the button is pressed.
The action - light.toggle: light_01 will toggle the state of the light with the ID light_01.

The same logic applies to switches. The only difference is that the action would be - switch.toggle: switch_01. Simple!

Advanced Automation: Multi-Click

ESPHome allows you to define multiple actions for a single button based on how it's pressed (single, double, or long press). This is done using the on_multi_click component.

Let's configure one button (in_01) to control three different lights.

1. The Goal

  • Single Click: Toggle light_01.
  • Double Click: Toggle light_02.
  • Long Press: Toggle light_03.

2. The Configuration

First, ensure you have your lights defined. Then, in your binary_sensor configuration, replace on_press with on_multi_click.

# Ensure these lights are defined elsewhere in your config
light:
  - platform: binary
    name: 'Light 01'
    output: out_01
    id: light_01
  - platform: binary
    name: 'Light 02'
    output: out_02
    id: light_02
  - platform: binary
    name: 'Light 03'
    output: out_03
    id: light_03

# Now, configure the multi-click automation
binary_sensor:
  - platform: gpio
    name: 'IN_01_Multi_Click_Button'
    id: in_01
    pin:
      pcf8574: pcf_inputs_1to14
      number: 0
      mode:
        input: true
      inverted: true
    on_multi_click:
      # Note: The order matters! ESPHome checks from top to bottom.
      # It's best to define the most complex patterns (longest clicks) first.

      # 1. Long Click Action
      - timing:
          - ON for at least 1.4s
        then:
          - logger.log: 'Long Click Detected, toggling Light 3'
          - light.toggle: light_03

      # 2. Double Click Action
      - timing:
          - ON for at most 1s
          - OFF for at most 0.5s
          - ON for at most 1s
          - OFF for at least 0.2s
        then:
          - logger.log: 'Double Click Detected, toggling Light 2'
          - light.toggle: light_02

      # 3. Single Click Action
      - timing:
          - ON for at most 1s
          - OFF for at least 0.5s
        then:
          - logger.log: 'Single Click Detected, toggling Light 1'
          - light.toggle: light_01

3. How It Works

The on_multi_click automation checks a sequence of timing blocks from top to bottom. The first one that matches the user's button press pattern is executed.

  • timing: This defines the pattern of ON (pressed) and OFF (released) states. You can adjust the time values (e.g., at most 1s, at least 0.5s) to fine-tune the responsiveness, but the defaults are usually a good starting point.

  • then: This block contains the actions to be performed when the timing pattern is matched. We've included a logger.log action, which is very helpful for debugging your automations in the device logs.

By arranging the clicks from most complex (long press) to least complex (single press), you ensure that a long press doesn't also trigger the single press action.