Turning on a scene directly from a Lovelace button

I have created some scenes and would like to activate them with a tap from a Lovelace dashboard. I’ve found the documentation about calling services generally and quite a few discussions which are about activating scenes from glance cards, but I’m still stuck:

  • My first attempt was to create a button using the UI. I added a Button to a card and selected the scene as the Entity. I set the tap action to Default Action. However this pops up a dialogue with an activate button. I would like to avoid that extra step.

  • My second attempt was to set the tap action to call_service which required a little YAML, which I worked out from some of the documents and forums. Here’s my code, which results in an error message:

type: button
entity: scene.morning_full_lights
name: Full brightness v2
tap_action:
  action: call-service
  service: scene.turn_on
  service_data: scene.morning_full_lights

This is the error message which appears in the dashboard when the button is clicked:

Failed to call service scene/turn_on. expected dict for dictionary value @ data['service_data']. Got 'scene.morning_full_lights'

Do I need to change the syntax for the service_data? Or am I trying to do something that fundamentally doesn’t work with Home Assistant?

Any help or advice appreciated!

5 Likes

You can add a scene as entity to the UI and it will be displayed by name and an „activate“ button.

1 Like

Your last line (service_data part) was wrong and that’s why it was throwing the error.

It should look like this:

type: button
entity: scene.morning_full_lights
name: Full brightness v2
tap_action:
  action: call-service
  service: scene.turn_on
  service_data:
    entity_id: scene.morning_full_lights
15 Likes

Thank you very much, @SeanM, that has solved it!

1 Like

This helped me when trying to create a button for scene activation in Lovelace. Thanks!

Amazing thank you!

Anyway to have it toggle off?

There is only activate. For scenes you seem to require the opposite desired state as an additional scene for “off”

Adding to this because I wanted to set up a button that turns on a scene from the UI Lovelace editor:

Set the tap action to ‘Call Service’.
Set the service to ‘scene.turn_on’.
Add an entity and use the auto-complete to find your scenes (start typing scene.____ and find your scene here).

Here’s a screenshot for my kitchen counter lighting:

5 Likes

Im looking to do something similar but with blinds… Im basically using the same code as @SeanM, when II press the button to toggle it on, it opens the blinds, but when I toggle it off, it doesnt do anything. Id like it to close the blinds.