Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set button colour to match active light colour #32

Open
Xiondewah opened this issue Jan 10, 2023 · 11 comments
Open

Set button colour to match active light colour #32

Xiondewah opened this issue Jan 10, 2023 · 11 comments
Labels
documentation Improvements or additions to documentation

Comments

@Xiondewah
Copy link

On other cards (custom-button) I am able to change the colour of the button to match that of the light when it is turned on.

This involves using 'state' and a variable which holds the colour of the light when it is turned on.

Am I able to do this on LCARS please and, if so, how? I've scoured the web but can't find anything which pulls in that colour variable.

Many thanks.

@th3jesta
Copy link
Owner

Can you provide some screenshots of what you are describing, please? I think I am following, but I want to be sure.

@Xiondewah
Copy link
Author

I ‘ve worked out how to change a specific button’s colour depending on state, but somewhere there is a variable holding a light’s active colour when it’s turned on. That’s what I’m looking for, the variable. On other things it’s var(--button-card-light-color) but that doesn’t work here.

@Xiondewah
Copy link
Author

6C252137-13AC-42B0-A3B6-3BD296D5D746

this is from another dashboard - each light button shows the colour it’s set to.

@th3jesta th3jesta added the support Getting help label Jan 11, 2023
@th3jesta
Copy link
Owner

The card colors are hard-coded in the CSS via card-mod using the variables. So you would probably need to apply some custom CSS to the cards themselves with card-mod (this is the basic functionality of card-mod, as opposed to the entire theme as has been done with LCARS).

@Xiondewah
Copy link
Author

Hi, yes I get that - I can do it all (apply a colour/border depending on the state (on/off) of the light - what I can't find out is the variable which holds the current colour of the light. It must be built-in to Home Assistant somehow?

@Xiondewah
Copy link
Author

card_mod:
class: button-bullet
style: |
ha-card {
border: {{ '3px solid gold' if is_state('light.desk_lamp', 'on') else '' }};
}

I want to replace 'gold' with the light's colour.

@Xiondewah
Copy link
Author

Something like this:

  • color: >
    [[[ if (entity.state === 'on') return "rgb(" +
    states['light.zachs_lamp'].attributes.rgb_color + ")";]]]

@z3r0l1nk
Copy link

z3r0l1nk commented Jul 7, 2023

Hi,
I have something like this.
It changes if its ON = yellow and OFF = RED.
Code is below the screenshot

image

type: horizontal-stack
cards:
  - show_name: true
    show_icon: false
    name: Server Room
    type: button
    tap_action:
      action: toggle
    entity: light.it_room_5afc8b25_on_off
    icon_height: 50px
    show_state: true
    card_mod:
      class: button-capped
      style: |
        ha-card.button-capped {
          {% if is_state('light.it_room_5afc8b25_on_off', 'on') %}
            background-color: #ffcc33;
            color: black;
          {% else %}
            background-color: #dd4444;
            color: black;
          {% endif %}
        }

@Xiondewah
Copy link
Author

Xiondewah commented Jul 7, 2023 via email

@z3r0l1nk
Copy link

z3r0l1nk commented Nov 9, 2023

@Xiondewah, sorry for the late late answer...here are the modifications that I also did in my system.
I think this is what you wanted and it's a great ideea.

show_name: true
show_icon: false
name: Terasa Light
type: button
tap_action:
  action: toggle
entity: light.terasa
show_state: true
hold_action:
  action: more-info
icon_height: 50px
card_mod:
  class: button-capped-right
  style: |
    ha-card {
      {% if is_state('light.terasa', 'on') %}
        {% set rgb_color = state_attr('light.terasa', 'rgb_color') %}
        background-color: rgba({{ rgb_color[0] }}, {{ rgb_color[1] }}, {{ rgb_color[2] }}, 1);
        color: black;  /* or any other logic for text color */
      {% else %}
        background-color: #dd4444;
        color: black;
      {% endif %}
    }

image

@Xiondewah
Copy link
Author

Xiondewah commented Nov 9, 2023 via email

@th3jesta th3jesta added documentation Improvements or additions to documentation and removed support Getting help labels Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants