ESPHome homeassistant.event

How do I create a homeassistant.event from a lambda expression (script) in Esphome? And how do I send the data with it?

Yes, I know about that method.
But I have a lambda (c++ code) in which I want to start an event. How do I do that?

Found it after a little digging in the source code files:

        auto capi = new esphome::api::CustomAPIDevice();
                                       {{"channel", ch},{"data", onoff}});

I don’t know if this is the official way, but it works.


@helgemor you are allocating memory from the heap, so don’t forget to free it by calling the delete operation. Or just declare the object on the stack. Otherwise, sooner or later you will be left without free memory and the device will reboot.

esphome::api::CustomAPIDevice capi;
      {{"channel", ch}, {"data", onoff}});