Button to run scenes

Hey,

Is it possible to have a button/switch in the Lovelace interface and

  • when you click it on, it runs scene 1
  • when you click it off, it runs scene 2

I know the first part is possible, but it’s a button to run my away scenes, but when I turn it off, I want my scene to run to set me back as home.

The button is as a back-up in case the automation didn’t work as expected.

Sounds like you could use a template switch for that, running one scene when turned on, and another when turned off.

That indeed seems to be exactly what I’m looking for! Thanks!

However it’s not yet working - no errors, but no results neither.
Here’s what I have so far.

switch:
  - platform: template
    switches:
      alarm:
        value_template: "{{ is_state('switch.ix4_300d_home_mode', 'off') }}"
        turn_on:
          service: switch.turn_on
          target:
            entity_id: scene.afwezig_van_huis
        turn_off:
          service: switch.turn_off
          target:
            entity_id: scene.aanwezig_in_huis

So when Home Mode is on, the Alarm should show as Off. And vice versa.
And when toggling the button it should fire the the according event. Which then toggles that state as well.

However it looks like my scenes don’t get triggered.

There’s your problem. You’re calling a switch service on a scene.

You need to use scene services on scene entities.

I’m afraid I’m a total newbie on HA.
What exactly should I change?

Change
service: switch.turn_on
to
service: scene.turn_on

:slight_smile:

Also there is no scene.turn_off service.

So this:

        turn_off:
          service: switch.turn_off
          target:
            entity_id: scene.aanwezig_in_huis

Needs tho be changed to:

        turn_off:
          service: scene.turn_on
          target:
            entity_id: scene.some_other_scene

Where scene.some_other_scene has the off states for your entities.

Ah yes, I read that somewhere indeed, that scenes only have turn_on!
But luckily the switch does have turn off.

Thank you, guys, for the input!!!

Unfortunately, nothing is happening yet…

switch:
  - platform: template
    switches:
      alarm:
        value_template: "{{ is_state('switch.ix4_300d_home_mode', 'off') }}"
        turn_on:
          service: switch.turn_on
          target:
            entity_id: scene.afwezig_van_huis
        turn_off:
          service: switch.turn_on
          target:
            entity_id: scene.aanwezig_in_huis

Because you have not listened or understood the advice you were given. You are still using the switch turn on/off service to try to control scene entities.

switch:
  - platform: template
    switches:
      alarm:
        value_template: "{{ is_state('switch.ix4_300d_home_mode', 'off') }}"
        turn_on:
          service: scene.turn_on  # You must use this service because...
          target:
            entity_id: scene.afwezig_van_huis # this is a scene.
        turn_off:
          service: scene.turn_on # You must use this service because...
          target:
            entity_id: scene.some_other_scene # this is a scene and there is no scene.turn_off service.
1 Like

Now, that was just plain stupid of me…
Thanks, man!!

You should think about the whole construct, you’re working with. :slight_smile:

If I understood it right, you’re using this as some kind of presence detection. If so, I’d use simple input_booleans to reflect your home status. I’m working with a so called residence state:

input_boolean.residence_state_home
input_boolean.residence_state_not_home
and so on

Working with scenes is more complicated in this situation. An input_boolean is on or off, and shows exactly what you need. Everything else can then be worked out in automations, that reference this input_boolean. :slight_smile:

Just saying. :slight_smile:

Thanks for the info, Patrick!

4 posts were split to a new topic: Add a button in lovelace that toggles between two scenes