Issue with sending datas to script

Hi there,

I try to do a Shopping list with a Waveshare 7" display with dynamically created checkboxes. I manage to create the checkboxes and I can get the item checked but impossible to modify it in Home assistant. I was never able to get my Esphome compile if I try to send the action in a function so I created a script but it still doesn’t work because of an argument type issue.

To explain : I create dynamically a checkbox with an event which fires a function :

static void event_check(lv_event_t * e)
{
    LV_LOG_USER("Clicked");
    lv_obj_t * cb = lv_event_get_target(e);
    const char * list_item = lv_checkbox_get_text(cb);
    LV_LOG_USER(list_item);
    id(enleve_liste).execute(list_item);      
}

This works as expected and I can see in the log the item I cliked on.

The function fires a script :

script:
  - id: enleve_liste
    parameters:
      list_item: string
    then:
      - logger.log: 
          format: "Item recu : %s"
          args: "list_item"
          
      - homeassistant.service:
          service: shopping_list.remove_item
          data:
            entity_id: todo_taches
            value: list_item;

Nothing happens in Home assistant and the log shows strange variable : Item recu : X\xde\xce?

I cannot understand what happens. I think this is an c++ issue but I can’t fix it. Any idea ?

I managed to get the right message :

script:
  - id: enleve_liste
    parameters:
      list_item: string
    then:
      - logger.log: 
          format: "Item recu : %s"
          args: list_item.c_str()
          
      - homeassistant.service:
          service: shopping_list.remove_item
          data:
            entity_id: todo_taches
            value: list_item.c_str()

and the function :

{
    LV_LOG_USER("Clicked");
    lv_obj_t * cb = lv_event_get_target(e);
    const char * label = lv_checkbox_get_text(cb);
    id(enleve_liste).execute(label);      
}

But Home assistant doesn’t do anything so I need to modify the homeassistant.service part.

Here is the working script :

script:
  - id: enleve_liste
    parameters:
      list_item: string
    then:
      - logger.log: 
          format: "Item recu : %s"
          args: list_item.c_str()
          
      - homeassistant.service:
          service: shopping_list.remove_item
          data:
            name: !lambda 'return list_item;'