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?
Krivatri
(Krivatri)
December 31, 2023, 6:35am
2
You could use an input boolean (helper switch) for this and use it as a trigger in an automation for your acclimatisation.
tom_l
December 31, 2023, 6:39am
3
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.
tom_l
December 31, 2023, 7:04am
5
Yes, that is what I meant by this:
1 Like
I have the button.
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?
tom_l
December 31, 2023, 7:22am
7
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”?
tom_l
December 31, 2023, 7:42am
9
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.
tom_l
December 31, 2023, 8:34am
11
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.
tom_l
December 31, 2023, 8:53am
13
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?
tom_l
December 31, 2023, 9:05am
15
What about this in the template editor:
{{ states('sensor.cupra_born_climatisation_state') }}
tom_l
December 31, 2023, 9:10am
17
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'] }}
tom_l
December 31, 2023, 9:29am
19
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') }}