How to call function in Custom Sensor

Hy everybody, I’m struggling with a Custom Sensor:

  - platform: custom
    id: custom_sensor
    lambda: |-
      auto sensor = new CustomSensor();
      sensor->custom_function(0);
      App.register_component(sensor);
      return {sensor->esphome_sensor};

Custom_function is public and executed once when the sensor is created, this is tested.

How can I recall this function in lamda in esphome for example at the press of
a button in order to update the value passed to the function itself?

After many attempts I can’t figure out how to do it.

Thanks in advance.

It should be this if I am not mistaken:

id(custom_sensor)->custom_function(0);

Edit: seems more complicated, see here for the suggested solution: Calling custom functions - #2 by FredTheFrog