PushButton to send lambda command

Hello to everyone,
did someone could help me to create a virtual push button that when pressed, for example return a start command via lambda? this is the code:

Arduino Program:

ESPHome:

Best Regards
Stefano

You could use a template button and the on_press to trigger a lambda action.

button:
  - platform: template
    name: "Template Button"
    on_press:
      then:
        - lambda: |-
            id(some_binary_sensor).publish_state(false);

Thanks a lot @Mikefila for your reply :smiley:
sorry but i don’t understand how to pass the start command for example.
I can punt this in the yaml:

button:
  - platform: template
    name: "Template Button"
    on_press:
      then:
        - lambda: |-
            here i need to pass command start or stop or dock etc;

This is the code that must be executed when i press the button:

    void on_command(std::string command) {
        this->brc_wakeup();

        if (command == "turn_on" || command == "turn_off" || command == "start" || command == "stop")
            this->roomba.cover();
        else if (command == "dock" || command == "return_to_base")
            this->roomba.dock();
        else if (command == "locate")
            this->roomba.playSong(1);
        else if (command == "spot" || command == "clean_spot")
            this->roomba.spot();
        else if (command == "wakeup" || command == "brc_wakeup")
            this->brc_wakeup();
    }

So i need to simulate the on_command with the virtual button.

Thanks again a lot
Best Regards
Stefano

You would need to create a custom component, then you can call it in a lambda with on_press.

@Mikefila thanks a lot
i will study your hint :smiley:
Best regards
Stefano