Binary Sensor automation question

I am setting up a Wemos D1 Mini that I ultimately want to use as a dimmer for lights defined on HASS but I’m struggling to understand the logic.

The test ESPHome code for the D1 Mini is:

esphome:
  name: test2
  platform: ESP8266
  board: d1_mini

    wifi:
  ssid: "Secret"
  password: "VerySecret"

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

binary_sensor:
  - platform: gpio
    pin:
      number: D1
      mode: INPUT_PULLUP
      inverted: TRUE
    name: "Up"
    device_class: door
  - platform: gpio
    pin:
      number: D2
      mode: INPUT_PULLUP
      inverted: TRUE
    name: "Down"
    device_class: door

This works and I can use the state changes in HASS to switch lights on and off. I now want to differentiate between long and short presses of the switches and found the ESPHome automation page and code on the binary sensor page https://esphome.io/components/binary_sensor/index.html

I understand that the automation code runs on the ESP device itself, not HASS like this sample code

on_multi_click:
    - timing:
        - ON for at most 1s
        - OFF for at most 1s
        - ON for at most 1s
        - OFF for at least 0.2s
      then:
        - logger.log: "Double Clicked"
    - timing:
        - ON for 1s to 2s
        - OFF for at least 0.5s
      then:
        - logger.log: "Single Long Clicked"
    - timing:
        - ON for at most 1s
        - OFF for at least 0.5s
      then:
        - logger.log: "Single Short Clicked"

That logger.log command runs on the ESP8266 as far as I can tell. Is it possible to use this approach to run differing automations on HASS? If so, any pointers would be much appreciated.
Thanks.

Richard

If I understand your question right, have a look at homeassistant.service Action.

p.s I think it was enough just to post a link to the example on on_multi_click as that’s not relevant here…

Thank you, @AhmadK, that was the pointer I needed.

Yes, agree I could have been sharper in my question - it was late and I was tired and frustrated… Apologies.

1 Like