Make 2 buttons (and 2 entities) in 1 button

Hello!

How can I turn 2 buttons into 1 button?

Now I have a start button and a stop button. I want to have 1 button which can do both based on its status (acclimating on or off).

Current separate buttons which I want to combine into 1 based on it’s status:

title: Auto
square: false
columns: 1
type: grid
cards:
  - square: false
    columns: 2
    type: grid
    cards:
      - type: custom:mushroom-entity-card
        entity: button.cupra_born_start_climate
        secondary: sensor.cupra_born_climatisation_state
        fill_container: true
        icon: mdi:leaf-circle-outline
        icon_color: green
        tap_action:
          action: toggle
      - type: custom:mushroom-entity-card
        entity: button.cupra_born_stop_climate
        secondary: sensor.cupra_born_climatisation_state
        fill_container: true
        icon: mdi:leaf-circle-outline
        icon_color: red
        secondary_info: none
        tap_action:
          action: toggle

Can someone help me write code for this?

You could use an input boolean (helper switch) for this and use it as a trigger in an automation for your acclimatisation.

Create a template switch.

configuration.yaml

switch:
  - platform: template
    switches:
      climatisation:
        value_template: "{{ is_state('sensor.cupra_born_climatisation_state', 'on') }}"
        turn_on:
          service: button.press
          target:
            entity_id: button.cupra_born_start_climate
        turn_off:
          service: button.press
          target:
            entity_id: button.cupra_born_stop_climate

Then use this switch in your card. Using the toggle action will toggle the switch on or off, pressing the required buttons.

Note: the value template will probably be wrong. It needs to be the state your sensor is when the switch is on.

Thank you, this makes sense.

I did added the code to configuration.yaml and the on/off status should be fine as you mentioned.

A total noob here, and I read the url you provided; but how do I add this to the card as you mentioned? I think I got it by creating a new button and put as entity: switch.climatisation

Will test it.

Yes, that is what I meant by this:

1 Like

I have the button.

2023-12-31_08-17-39

type: custom:mushroom-entity-card
show_name: true
show_icon: true
tap_action:
  action: toggle
entity: switch.climatisation
name: Cupra Born Climatiseren
icon: mdi:leaf-circle-outline
show_state: true

When I now press the button, the status keep saying “off” (in Dutch it’s “Uit”), while the car is actually climatizing. Any idea what I need to do to fix this?

Yes, this:

That template determines the state of your switch.

In the Developer Tools → Template editor, what does this return when the climate is on and when it is off?

{{ states('sensor.cupra_born_climatisation_state') }}

I think it’s “heating”, right? So I should now edit the configuration.yaml where “on” was mentioned, it should be “heating”?

I don’t know. You have not done what I asked and have shown something else instead.

Also is it possible to cool as well as heat, or is it only a heater?

Also cooling is possible indeed.

Ok then. Change the switch value template to this:

value_template: "{{ states('sensor.cupra_born_climatisation_state') in ['heating', 'cooling] }}"

If there are any other possibilities (e.g. “fan only”) put them in the list too.

value_template: "{{ states('sensor.cupra_born_climatisation_state') in ['heating', 'cooling] }}"

I also added the ’ after cooling, same as ‘heating’.

But, when activated and when the car is warming up, still no status feedback. It remains ‘off’ while it’s clearly heating.

What does this return in the template editor?:

{{ states('sensor.cupra_born_climatisation_state') in ['heating', 'cooling'] }}

And what is the state of switch.climatisation in Developer Tools → States?

What about this in the template editor:

{{ states('sensor.cupra_born_climatisation_state') }}

That’s not possible. Put all three in:

{{ states('sensor.cupra_born_climatisation_state') }}
{{ states('sensor.cupra_born_climatisation_state') == 'heating' }}
{{ states('sensor.cupra_born_climatisation_state') in ['heating', 'cooling'] }}

That’s better.

Now try:

{{ states('sensor.cupra_born_climatisation_state') }}
{{ states('sensor.cupra_born_climatisation_state') == 'heating' }}
{{ states('sensor.cupra_born_climatisation_state') in ['heating', 'cooling'] }}
{{ states('switch.climatisation') }}