[solved]How to publish to HA?

Hi,

I have been using esphome with mqtt and fhem for several years now.
Now I am trying HA as well.
I have many buttons implemented in esphome. Those buttons have click, double-click, long-press and so on actions.
When using mqtt I can simply publish like this:

binary_sensor:
  - platform: gpio
    id: tasteroben_button01
    pin: 
      number: GPIO13
      inverted: true
      mode:
        input: true
        pullup: true
    name: "tasteroben_button01"
    filters:
      - delayed_on: 30ms
    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"
        - mqtt.publish:
            topic: toben/state/btn_01
            payload: "doubleclick"
    - timing:
      - ON for 1s to 2s
      - OFF for at least 0.5s
      then:
        - logger.log: "Single Long Clicked"
        - mqtt.publish:
            topic: toben/state/btn_01
            payload: "longclick"
    - timing:
      - ON for at least 2.2s
      then:
        - logger.log: "Click and Hold"
        - mqtt.publish:
            topic: toben/state/btn_01
            payload: "clickhold"
    - timing:
      - ON for at most 1s
      - OFF for at least 0.5s
      then:
        - logger.log: "Single Short Clicked"
        - mqtt.publish:
            topic: toben/state/btn_01
            payload: "click"

But I am a little bit confused how to get this payloads directly to HA without using mqtt?
Probably this is a stupid question, but I did not really find anything on that…
Best regards and thanks in advance,
Otto

Generally speaking, you use the Native API component… but there are a number of methods to use.

One method would be to use an Event Action to publish to Home Assistant’s event bus.

For a multi-click button, another option would be to instantiate an entity in your ESPHome config such as a Text sensor and include a lambda call to set it’s state. With that you can use a simple State trigger in HA. Make sure you include a reset lambda call as well so you don’t miss button press sequences that match the prior sequence.

@Didgeridrew THANKS man!
this already helps a lot to my understanding.
I tried two things, both are working fine:

        - homeassistant.event:
            event: esphome.klovorne_links_click
        - homeassistant.service:
            service: input_boolean.turn_on
            data:
              entity_id: input_boolean.klovorne_taster_links_click
        - homeassistant.service:
            service: input_boolean.turn_off
            data:
              entity_id: input_boolean.klovorne_taster_links_click

(added the turn_off so the state of the input_boolean changes with each click)
for the service call it was necessary to enable it in the otions flow of the device, tough…
thanks to spook I found that easily :slight_smile:
Best regards and thanks again,
Otto

1 Like