Change HA entity from ESPhome

Hi, I have device with 3 buttons. It’s plus/minus/enter running on ESP8266 connected to ESPhome. I’m able to read buttons, make some action. For test, I make number helper in HA and this helper is readed in ESPhome code.

My question is how can I change value of number helper when I hit the button plus. I need increment number in HA by one step, or defined step (in example bellow it’s 0,1)?

Is it possible to make it in lambda?

My part of code:

sensor:
  - platform: homeassistant
    id: "my_value"
    entity_id: input_number.my_number
    internal: False

binary_sensor:
- platform: gpio
    pin: GPIO12
    id: plus
    on_press: 
      then:
       lambda: |-
            id(my_value) = id(my_value) + 0.1;
            id(my_value).publish_state(my_value);   
          

Thank you for reply.

As in HA itself, you cannot change the value of a sensor that way, you have to use an action.

See below to execute an HA action from ESPHome

Most straightforward would be using esphome number component instead of homeassistant sensor/number helper.

number:
  - platform: template
    name: "My Value"
    id: my_value
    optimistic: true
    min_value: 0.0
    max_value: 100.0
    step: 0.1
    initial_value: 0.0
    restore_value: true

binary_sensor:
  - platform: gpio
    pin: GPIO12
    id: plus
    on_press:
      then:
        - number.increment:
            id: my_value

Also, you should enable pullup and delayed on/off filters to your button code.