Passing a variable to a script in lovelace with entity-button

I have a script which I can call from automations, etc. with

    - service: script.debug_msg
      data:
        message: "foobar"

and the script itself:

debug_msg:
  sequence:
    - service: persistent_notification.create
      data_template:
        title: "debug"
        message: "{{ message }}"

I’m trying to use entity-button in lovelace to do the same thing. The editor accepts the following code, but the “message” value isn’t getting sent. The script is being called, however.

lovelace

type: entities
entities:
  - type: entity-button
    name: 30 seconds
    tap_action:
      action: call-service
      service: script.debug_msg
      service_data:
        message: 30
    show_icon: true
    icon: 'mdi:water'
    entity: script.debug_msg

It looks like your script definition is lacking the fields list. (See https://www.home-assistant.io/integrations/script/.) Without them, I believe your button can send the parameter (message), but the script drops it on the floor.

I’ve not tried using fields before. I took a stab at the following, but it doesn’t work.

debug_msg:
  description:  'Create a persistent notification debug message'
  fields:
    message:
      description: 'The message to send'
      example: 'Foobar'  
  sequence:
    - service: persistent_notification.create
      data_template:
        title: "debug"
        message: "{{message}}"

Turns out it’s working, but an entities lovelace bug.

Huh, well, there you go. Glad it’s “working”!

For what it’s worth, I now believe the fields: property is optional, and is probably only used to display help text. (Somewhere?) Or maybe it’s the equivalent of a structured comment.

I have two scripts that are nearly identical (arrival/departure notifications), but I forgot to copy/paste the fields: property from one to the other (for a message variable). And the one that omits fields: works just the same as the one that does.

The script integration doc doesn’t actually explain the purpose of the fields: property. It just describes it as an optional map, with a default value of {} (empty map). Based on my accidental experiment, it doesn’t appear to have an effect on actual script execution.

(If someone wants to answer a few questions, I’d be happy to augment the doc here.)