Best way to expose multi click to HA

Hi,

Currently, I can see several ways to expose multi click to HA from ESPHome:

  • Using a binary sensor for each click type, and toggle them through on_multi_click
  • Publishing different events or one event with different parameters using homeassistant.event
  • Using a text sensor for each click type, and update its value
  • MQTT topics

What’s version will fit best with HA ?

I like the binary sensor one, because I can directly see the entities within the device dedicated page and it’s more user friendly when using the UI to create automation

But using YAML, I currently migrate to the event solution. It helps me to reduce some boilerplate and seems more intuitive.

Here a comparison with only 2 states.

trigger:
  platform: event
  event_type: esphome.event
  event_data:
    device_name: shelly_25_1
action:
  choose:
     conditions: "{{trigger.event.data.type == ’single’}}"
     sequence: 
         service: light.toggle
         target:
            entity_id: light.living_room
     conditions: "{{trigger.event.data.type == ’double’}}"
     sequence: 
         service: light.toggle
         target:
            area_id: house

vs

trigger:
  platform: state
  entities:
     - binary_sensor.shelly_25_1_single_click
     - binary_sensor.shelly_25_1_double_click
  to: "on"
action:
  choose:
     conditions: "{{trigger.entity_id == ’binary_sensor.shelly_25_1_single_click’}}"
     sequence: 
         service: light.toggle
         target:
            entity_id: light.living_room
     conditions: "{{trigger.entity_id  == ’binary_sensor.shelly_25_1_double_click’}}"
     sequence: 
         service: light.toggle
         target:
            area_id: house

What do you think?

1 Like

Events.

For example, the Philips Hue Dimmer Switch has four buttons and each button’s action (pressed, released, etc) is represented by a hue_event with a numeric value. The only entity that the Hue integration creates for a Dimmer Switch is a single sensor representing its battery level.

OMG I didn’t know that! it’s why I said it’s not easy to discover events.

Go to Developer Tools > Events and look at the list called Available Events on the right hand side. That’s a good place to start when attempting to discover what kind of events are available.

You can also enter * in “Listen to events”, click “Start listening” and then watch all the events as they occur.
Screenshot from 2021-09-10 15-55-25

If you were to press a Hue dimmer Switch’s button, you would see the event’s details reported. That’s how I learned all of its button events in order to create a diagnostic tool (see this post for the automation).