How to call a script from Lovelace / entity-button?

Hi,

I want to use the entity-button card to execute a script when I click on it (to activate a bunch of light scenes in different rooms).
But I just can’t get this to work - when configured like this, nothing happens when I click the button:

  - type: entity-button
    entity: script.night_mode_on
    tap_action: call_service
    service: script.turn_on
    icon: mdi:weather-night

Calling the script directly through the dev-service UI works as expected.
What am I missing?

Sebastian

Found my mistake: it’s call-service, not call_service

Sebastian

1 Like

hi! where to put code in home assistant foder/file?

  • type: entity-button
    entity: script.night_mode_on
    tap_action: call_service
    service: script.turn_on
    icon: mdi:weather-night

Thanks!

Hi,
that’s a configuration snippet for the Lovelace UI.
Assuming you’re using a fairly recent version of Home Assistant, open the UI in your web browser.
Then select “Configure UI” from the top right menu (the three dots),
In the bottom right, a large orange circle with a “+” sign appears, click that.
The card configuration menu pops up - choose “manual card” from the bottom right section.
That gives you the manual card config editor where you can enter the code.

Sebastian

1 Like


I have error, could you help me!

From what I can see, the indentation is wrong (action: needs to be indented one level).
Anyway, I suggest you just choose Entity Button from the card config menu, instead of manual configuration.
That way you can configure your button without having to worry too much about the YAML syntax.
You can access the raw code editor from there too, if you really need to.

Sebastin

1 Like

Thanks so much your quick reply! it’s work now!

Landed here as top result of google search. However I believe in the current version of HA this should be:

    tap_action:
      action: call-service
      target: {}
      perform_action: script.your_script_name