myhomeiot / esphome-components

A collection of my ESPHome components
Other
257 stars 25 forks source link

Example of Direct Service Call #9

Closed efaden closed 2 years ago

efaden commented 2 years ago

Is there an example of using a direct HA service call instead of an automation?

Would it be? Is there an advantage to one or the other?

on_ble_advertise:
  then:
    homeassistant.service:
      event: ble_monitor.parse_data
      data:
        packet: !lambda return packet;
myhomeiot commented 2 years ago

Example of service call you can find in ESPHome documentation here

  on_ble_advertise:
    then:
      homeassistant.service:
        service: ble_monitor.parse_data
        data:
          packet: !lambda return packet;

If you are using direct service call it's make call faster but you need to recompile ESP firmware if, for example, you need to temporarily turn off the processing of BLE Advertisement.

If you are using event and automation it's make call slower but it's more flexible, you can disable automation for example in order to stop processing BLE Advertisement from all ESP devices or make condition and allow processing only from specific devices, add packet counter, etc.

efaden commented 1 year ago

Got it. Thanks!

On Sun, Apr 10, 2022, 07:33 myhomeiot @.***> wrote:

Example of service call you can find in ESPHome documentation here https://esphome.io/components/api.html#homeassistant-service-action

on_ble_advertise: then: homeassistant.service: service: ble_monitor.parse_data data: packet: !lambda return packet;

If you are using direct service call it's make call faster but you need to recompile ESP firmware if, for example you need to temporarily turn processing of BLE Advertisement.

If you are using event and automation it's make call slower but it's more flexible, you can disable automation for example in order to stop processing BLE Advertisement from all ESP devices or make condition and allow processing only from specific devices, add packet counter, etc.

— Reply to this email directly, view it on GitHub https://github.com/myhomeiot/esphome-components/issues/9#issuecomment-1094251226, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADAEABA6LYZ3IZYXKG4MIQTVEK36ZANCNFSM5S655WKQ . You are receiving this because you authored the thread.Message ID: @.***>