Hello everyone,
to close properly the thread, I completed my testing and I came up with the solution
I setup the gpio needed as a binary sensor and I check for actions with the on_multi_click automation, for now I tested single click, double click, long click and hold presses.
I tried the template sensor, but it wasnāt suitable for my need, since to work properly I would need to reset the value after each action, and Home Assistant has some issues with this, at least in my tests.
I worked out a good solution using the homessistant.event automation, which simply creates an event in the HA bus, the event id has to begin with esphome. and can have or have not some data in it, I chose to do it, for better readability.
Plus I donāt need to create sensors of any kind, and also the binary sensors attached to the GPIOs can be internal to esphome, so there is less communication to and from HA and they donāt need to show up in HA dashboard
Anyway now I can fire any automation on HA from the esphome device buttons.
Thank you all for helping out.
Ciao
Claudio
Here is a sample binary sensor setup
- platform: gpio
pin:
number: GPIO25
mode: INPUT_PULLUP
inverted: True
name: "Puls_32_01_25"
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"
- homeassistant.event:
event: esphome.puls_32_01_25
data:
title: dbl_click
- timing:
- ON for 1s to 2s
- OFF for at least 0.5s
then:
- logger.log: "Single Long Clicked"
- homeassistant.event:
event: esphome.puls_32_01_25
data:
title: long_click
- timing:
- ON for at least 2.2s
then:
- logger.log: "Click and Hold"
- homeassistant.event:
event: esphome.puls_32_01_25
data:
title: hold
- timing:
- ON for at most 1s
- OFF for at least 0.5s
then:
- logger.log: "Single Short Clicked"
- homeassistant.event:
event: esphome.puls_32_01_25
data:
title: single_click
And here is a sample automation triggered from this custom event:
alias: 'Tastiera Sala TV p1'
trigger:
- platform: event
event_type: esphome.puls_32_01_25
event_data:
title: dbl_click
action:
service: script.turn_on
entity_id: script.hue_scena1