esphome / feature-requests

ESPHome Feature Request Tracker
https://esphome.io/
418 stars 26 forks source link

Expose binary sensor press/release/click/double_click/etc automations as HA events #467

Open brandond opened 4 years ago

brandond commented 4 years ago

Describe the problem you have/What new integration you would like I would like to be able to use different types of clicks as automation triggers in HA

Please describe your use case for this integration and alternatives you've tried: The HA Xiaomi Binary Sensor integration exposes button click details. The switches will all fire xiaomi_aqara.click events with a click_type field that can be used to determine the type of the button press - long_click_press, long_click_release, hold, single, double for single switches; or single, double, long, both, double_both, long_both for double-switch devices.

I would like to use similar functionality for ESPHome binary sensors, preferably without having to manually configure each individual click_type as a binary sensor automation. Since I am a MQTT user, I would like this to be supported for both connectivity types (MQTT and API).

Additional context https://www.home-assistant.io/integrations/binary_sensor.xiaomi_aqara/ https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/xiaomi_aqara/binary_sensor.py#L430

OttoWinter commented 4 years ago

Kind of a duplicate of https://github.com/esphome/esphome/issues/115

I don't think that solution would be true to ESPHome's idea of extensibility.

Yes, I understand being able to parse button press types is something useful, but:

brandond commented 4 years ago

I was hoping there was an existing JSON schema for sending events (as opposed to states) to HA's event bus via MQTT. If not I guess that would be something to put in a PR for in HA, and then use here? For the native API, homeassistant.event already does pretty much exactly what I want.

on_press:
  then:
    - mqtt.event: XXX
    - homeassistant.event: XXX

This is a bit repetitive to repeat for each sensor and trigger, but I can probably live with it.

brandond commented 4 years ago

Related: #472

bdr99 commented 10 months ago

Home Assistant now supports event entities as a cleaner and more user-friendly way to expose events. Event entities would be the best way to implement this feature.