Styling elements in Picture elements card: a small tutorial

hello,

i do a floorplan for my covers like this :


When a cover close the floorplan is updating with the picture of the cover closed like this :

My question is i would like to do the real animation of the cover but i don’t really know how to do it.
I did this try but it doesn’t do an animation. I hope it is clear ^^

type: picture-elements
image: /local/Volet/Ouvert.png
elements:
  - type: image
    entity: cover.store_salon_est_rideau
    image: /local/Volet/Volet Salon Sud fermé.png
    style:
      top: 50%
      left: 50%
      width: 100%
      height: 100%
      transform: translate(-50%,-53%) scale(1,0.01)
    state_image:
      open: /local/Volet/bureau fermé.png
1 Like

Anyone know how i get a black transparant horizontal box at the bottom of my card (containing elements) ?
Like wit hthe picture glance card (at the bottom) ?

Also how do i add just text as an element?

Ildar_Gabdullin,
Is there a way to get the icon color of an entity which changes colors in function of its state? I need to get its current color value. I tried the variables you suggested without success. I’m using custom-button-card. Many thanks

This thread is about using Picture elements card.
Are you using the button-card as a custom element?
Anyway, the button-card has its own effective mechanism for styling colors.
Post a SHORT example of what you wish to achieve.

Ildar,
I’m using a template and for some entities I want to control the icon color in function of the entity and/or state, but for some others I want to display their original color, which happens to change in function of the state. The problem is that if the icon color style is set for some entities, by filtering them using the entity_id, then for those entities that I want to display their original color, the color turns white. Thus, the only way to show the original color is not to change the color style at all? Sounds strange. So I need a workaround and this is why I was thinking to catch the original color…
The following is the code I’m using to set the color style:

  styles:
    icon:
      - color: |
          [[[
            var type = entity.entity_id.split(".")[0];
            if (type == "switch") {
              return states[entity.entity_id].state == 'on' ? 'rgb(0,100,255)' : 'Silver';
            } else if (variables.var_select_option_value) {
              if (states[entity.entity_id].state == variables.var_select_option_value) {
                return "rgb(0,100,255)";
              } else {
                return "Silver";
              }
            }
            //if the entity is not a switch or a select entity the original color should be used, but it's not !
          ]]]

Many thanks!

I would be happy to help. But this is not related to Picture elements card. So it is not supposed to be discussed here.
Please ask this question in a proper thread:

Now I am rather far from any PC and cannot test your code. In a week - if your question still is not answered in that button-card thread - I will be able to test it.

1 Like

@jmfargas Answered you in that button-card thread.

Hello community! Can anyone help me create a dashboard card that consists of images and templates?

So far I have only found “tailwindcss-template-card” which works well, but with multiple cards the CPU is heavily used and loading takes longer.

POST

my html-css tailwindcss-template-card code that I have used so far.

type: custom:tailwindcss-template-card
content: >
  <div class="container">
    <!-- Hintergrund Bilder -->
    <div class="background-images">
      <img src="/local/sportpng/flagen/spanien.png" alt="Left Background">
      <img src="{{state_attr('sensor.tennis_atp_rafael_nadal', 'opponent_logo')}}" alt="">
    </div>
  
    <div class="foreground-images">
      <img src="/local/sportpng/nadal.png" alt="Left Foreground">
      <img src="https://a.espncdn.com/combiner/i?img=/i/headshots/tennis/players/full/{{state_attr('sensor.tennis_atp_rafael_nadal', 'opponent_id')}}.png" alt="">
    </div>
  
    <div class="content">
      <center>
        <p>
  
    {% set down_distance_text = state_attr('sensor.tennis_atp_rafael_nadal', 'down_distance_text') %}
    {% set date_attr = state_attr('sensor.tennis_atp_rafael_nadal', 'date') %} 
    {% if date_attr %}
        {% set date = date_attr | as_timestamp | timestamp_custom('%d.%m.%y um %H:%M Uhr') %}
    {% else %}
        {% set date = 'Kein Datum vorhanden' %}
    {% endif %}
  
    {% set uhr_attr = state_attr('sensor.tennis_atp_rafael_nadal', 'date') %}
    {% if uhr_attr %}
        {% set uhr = uhr_attr | as_timestamp | timestamp_custom('%H:%M Uhr') %}
    {% else %}
        {% set uhr = 'Keine Uhrzeit vorhanden' %}
    {% endif %}
  
    {% set kickoff_in = state_attr('sensor.tennis_atp_rafael_nadal', 'kickoff_in') %}
    {% set event_name = state_attr('sensor.tennis_atp_rafael_nadal', 'event_name') %}
    {% set venue = state_attr('sensor.tennis_atp_rafael_nadal', 'venue') %}
    {% set location = state_attr('sensor.tennis_atp_rafael_nadal', 'location') %}
    {% set clock = state_attr('sensor.tennis_atp_rafael_nadal', 'clock') %}
    {% set team_score = state_attr('sensor.tennis_atp_rafael_nadal', 'team_score') %}
    {% set translations = {'Round 1': 'Runde 1', 'Round 2': 'Runde 2', 'Round 3': 'Runde 3', 'Round 4': 'Runde 4', 'Quarterfinal': 'Viertelfinale', 'Semifinal': 'Halbfinale', 'Final': 'Finale'} %}
    {% set down_distance_text = translations.get(state_attr('sensor.tennis_atp_rafael_nadal', 'down_distance_text'), state_attr('sensor.tennis_atp_rafael_nadal', 'down_distance_text')) %}
    {% set opponent_score = state_attr('sensor.tennis_atp_rafael_nadal', 'opponent_score') %}
    {% set gegner_name = state_attr('sensor.tennis_atp_rafael_nadal', 'opponent_name') %}
    {% set spieler_name = state_attr('sensor.tennis_atp_rafael_nadal', 'team_name') %}
    {% set spieler_win_set = state_attr('sensor.tennis_atp_rafael_nadal', 'team_sets_won') %}
    {% set gegner_win_set = state_attr('sensor.tennis_atp_rafael_nadal', 'opponent_sets_won') %} 
    {% set last_play = state_attr('sensor.tennis_atp_rafael_nadal', 'last_play') %} 
  
    {% set result_set = "<font color=red>Abgesagt</font>" if clock == "Walkover"
                 else "<font color=green>Satz-Gewinn</font>" if spieler_win_set is not none and gegner_win_set is not none and spieler_win_set > gegner_win_set
                 else "<font color=red>Satz-Verlust</font>" if spieler_win_set is not none and gegner_win_set is not none and spieler_win_set < gegner_win_set
                 else "<font color=yellow>Satz-Gleich</font>" %}
  
    {% set result = "<font color=red>Abgesagt</font>" if clock == "Walkover"
                 else "<font color=green>Gewinnt</font>" if team_score is not none and opponent_score is not none and team_score > opponent_score
                 else "<font color=red>Verliert</font>" if team_score is not none and opponent_score is not none and team_score < opponent_score
                 else "<font color=yellow>Unentschieden</font>" %}
  
    {% if is_state('sensor.tennis_atp_rafael_nadal', 'PRE') %}
      {{ spieler_name }} gegen {{ gegner_name }}<br />
      ({{ down_distance_text }}) um {{ uhr }}<br />
      
    {% elif is_state('sensor.tennis_atp_rafael_nadal', 'IN') %}
      
       ({{ down_distance_text }}) {{ result_set }} {{ spieler_win_set }}:{{ gegner_win_set }}<br />
      {% if team_score is not none and opponent_score is not none %} 
      LIVE {{ result }} {{ team_score | int }} zu {{ opponent_score | int }} im {{ clock }} <br />
      {% else %}
        Keine Ergebnisse verfügbar.
      {% endif %}
  
      {% if last_play %}
        {% set spieler = last_play.split(' ;')|regex_findall('(\d+)(?=\s)') %}
        {% set gegner = last_play.split(' ;')|regex_findall('\d+(?=\s*;)') %}
  
            <div class="inline-block-right">
              <p class="text-white text-base font-bold">
  				{{ spieler_name }}: {{ spieler|join('|') }}<br />    
  				{{ gegner_name }}: {{ gegner|join('|') }}
  				{% else %}
  				  Keine Daten gefunden.
  				{% endif %}
              </p>
            </div>
  
    {% elif is_state('sensor.tennis_atp_rafael_nadal', 'POST') %}
     Ergebnis ({{ down_distance_text }}) {{ result }} 
    {% if team_score is not none and opponent_score is not none %}:
        {{ team_score | int }} zu {{ opponent_score | int }} <br/>
      {% else %}
        Keine Ergebnisse verfügbar.
      {% endif %}
  
      {% if last_play %}
        {% set spieler = last_play.split(' ;')|regex_findall('(\d+)(?=\s)') %}
        {% set gegner = last_play.split(' ;')|regex_findall('\d+(?=\s*;)') %}
            
            <div class="inline-block-right">
              <p class="text-white text-base font-bold">
  				{{ spieler_name }}: {{ spieler|join('|') }}<br />
  				{{ gegner_name }}: {{ gegner|join('|') }}
  				{% else %}
  				  Keine Daten gefunden.
  				{% endif %}
             </p>
            </div>
          
    {% elif is_state('sensor.tennis_atp_rafael_nadal', 'NOT_FOUND') %}
      Momentan Keine Tennis ATP Spiele.
    {% endif %}
        </p>
      </center>
    </div>
  
    <!-- Linke transparente Klickfläche -->
    <a href="/dashboard-sport/tennis" class="transparent-link transparent-link-left"></a>
    <!-- Rechte transparente Klickfläche -->
    <a href="{{ state_attr('sensor.tennis_atp_rafael_nadal', 'event_url')}}" target="_blank" class="transparent-link transparent-link-right"></a>
  </div>
  <hr class="hr-style" />
  <p class="footer-text">
    {{ event_name }} - {{ venue }} - {{ location }}
  </p>
  <style>
    .container, .background-images, .foreground-images {
      position: absolute;
      inset: 0;
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0;
    }
    .container {
      flex-direction: column;
      min-height: 0;
      border-radius: 0.5rem;
      overflow: hidden;
      position: relative;
    }
    .background-images { opacity: 0.3; }
    .background-images img, .foreground-images img {
      height: 10rem;
      width: 10rem;
    }
    .foreground-images img { height: 7.5rem; }
    .content {
      flex: 1;
      padding: 0.75rem;
      position: relative;
      z-index: 0;
      color: white;
      font-size: 1rem;
      font-weight: bold;
      text-align: center;
    }
    .inline-block-right {
      display: inline-block;
      text-align: right;
    }
    .text-white { color: white; }
    .text-base { font-size: 1rem; }
    .font-bold { font-weight: bold; }
    .transparent-link {
      position: absolute;
      top: 0;
      bottom: 0;
      width: 10rem;
      background-color: transparent;
      z-index: 1;
    }
    .transparent-link-left { left: 0; }
    .transparent-link-right { right: 0; }
    .hr-style { border-color: #cbd5e0; width: 100%; }
    .footer-text {
      color: #f7fafc;
      text-align: center;
      font-size: 1rem;
      padding: 0.25rem 0;
    }
  </style>

Sorry, how is this related to picture-elements?

is it possible to create the image arrangement with the “picture-elements”? or something like that.

Hi,
I would like to change the icon and the color of some icons on my picture-elements card depending on the state of the entry.
I understand that I have to use card-mod for that , which I did, similar to the examples. I’m also using the ‘–paper-item-icon-color’ style element as I see from the examples.

However this does not work. The icon color does not change. The icon itself even is not shown anymore if I set that with a variable that was set via the card-mod template.

If I set the icon color or name manually instead of using the variable it works fine, so it seems as if the conditional part in the {% if xxx %| section is not evaluated.

This is my code, what am I doing wrong here?

type: picture-elements
image: local/pictures/Tesla-model3-new.png
card_mod:
  style: |
    ha-card {
      --tesla-state-color: 
        {% if is_state('sensor.tesla_state', 'online') %}
          green
        {% elif is_state('sensor.tesla_state', 'asleep') %}
          blue
        {% elif is_state('sensor.tesla_state', 'offline') %}
          grey
        {% else %}
          purple
        {% endif %};
      --tesla-lock-color: 
        {% if is_state('binary_sensor.tesla_locked', 'on') %}
         green
        {% else %}
          orange
        {% endif %};
      --tesla_state_icon-name: 
        {% if is_state('sensor.tesla_state', 'online') %}
          mdi:check-circle
        {% elif is_state('sensor.tesla_state', 'asleep') %}
          mdi:sleep
        {% elif is_state('sensor.tesla_state', 'offline') %}
          mdi:alert-circle
        {% else %}
          mdi:help-circle        
    }   
elements:
  - type: state-icon
    entity: sensor.tesla_state
    tap_action:
      action: more-info
    hold_action:
      action: none
    style:
      top: 7%
      left: 50%
      '--paper-item-icon-color': var(--tesla-state-color)
    icon: var(--tesla_state_icon-name)
  - type: state-icon
    entity: binary_sensor.tesla_locked
    tap_action:
      action: more-info
    hold_action:
      action: none
    style:
      top: 7%
      left: 57%
      '--paper-item-icon-color': var(--tesla-lock-color)

Use Dev tools - Templates for validating your templates before putting them into cards.
Your templates are wrong, no closing end f.

Oh, thanks! That was silly as I did test it but somehow it got lost with all the iterations.
The template now properly evaluates to:

    ha-card {
      --tesla-state-color: 
        
          purple
        ;
      --tesla-lock-color: 
        
          green
        ;
      --tesla_state_icon-name: 
        
          mdi:help-circle 
        ;          
    }

So now the icons change the color properly, great!

Now we are at it, I also would like to change the icon itself based on the state.
But if I change the code for the sensor.tesla_state entry to the below, the icon is no longer visible.
(if I don’t use the variable but set the icon to a fixed value it works fine).

elements:
  - type: state-icon
    entity: sensor.tesla_state
    tap_action:
      action: more-info
    hold_action:
      action: none
#    icon: mdi:car-electric-outline
    icon: var(--tesla_state_icon-name)
    style:
      top: 8%
      left: 50%
      '--paper-item-icon-color': var(--tesla-state-color)

Thanks for your tips!

Please help!
How can I place and align text “content-text” in the middle between the images?

button-text

type: custom:button-card
entity: sensor.tennis_atp_alexander_zverev_card
name: false
show_name: false
show_state: false
show_icon: false
styles:
  card:
    - border-radius: 0.5rem
    - overflow: hidden
    - position: relative
    - padding: 0
    - display: flex
    - flex-direction: column
    - justify-content: center
    - align-items: center
  custom_fields:
    background-images:
      - position: absolute
      - inset: 0
      - display: flex
      - justify-content: space-between
      - align-items: center
      - opacity: 0.3
    foreground-images:
      - position: absolute
      - inset: 0
      - display: flex
      - justify-content: space-between
      - align-items: center
      - z-index: 1
    content-text:
      - position: relative
      - z-index: 2
      - color: white
      - font-size: 1rem
      - font-weight: bold
      - text-align: center
      - padding: 5px
      - display: flex
      - justify-content: center
      - align-items: center
      - width: 100%
      - height: 100%
      - box-sizing: border-box
custom_fields:
  background-images: |
    [[[
      return `
        <img src="/local/sportpng/flagen/ger.png" alt="Left Background" style="height: 10rem; width: 10rem;">
        <img src="${states['sensor.tennis_atp_alexander_zverev'].attributes.opponent_logo}" alt="Right Background" style="height: 10rem; width: 10rem;">
      `;
    ]]]
  foreground-images: |
    [[[
      return `
        <img src="/local/sportpng/zverev.png" alt="Left Foreground" style="height: 7.5rem; width: 10rem;">
        <img src="https://a.espncdn.com/combiner/i?img=/i/headshots/tennis/players/full/${states['sensor.tennis_atp_alexander_zverev'].attributes.opponent_id}.png" alt="Right Foreground" style="height: 7.5rem; width: 10rem;">
      `;
    ]]]
  content-text: |
    [[[
      return 'Text <br/> Text <br/>';
    ]]]

This is not related to Picture-elements. Ask in the main button-card thread (find it).

Not supported, you can only use vars for css properties.

UPDATE: ok, I should have read this thread more carefully. Looks like card-mod is what I need to use. Will have a play around with that!


ORIGINAL POST:

No mention of the ‘state_filter’ options in this thread. I’m assuming it only support “on” / “off” states (as per the documentation here), and that I’ll need to do something different if I want the appearance of an element to vary based on a sensor reading rather an a binary on/off.
e.g.:

Current code for the bit I’m working on:

  - type: state-label
    tap_action: toggle
    entity: sensor.myenergi_home_power_export
    style:
      font-size: 75%
      text-align: right
      top: 46%
      left: 97%
    state_filter:
      "0": opacity(0%)   ## Does not work, not supported

I have a separate binary sensor called binary_sensor.exporting which can tell me if I’m exporting i.e. if the value circled in red above should be shown or not.

What would the syntax be for using the state of this binary sensor to determine the visibility of the separate sensor (sensor.myenergi_home_power_export). So that if I’m not exporting, no value is shown?

Hi everyone!
Is there a way to change the size of the clickable area?
Screenshot 2024-09-06 alle 05.57.02
it’s too big and overlaps with the others

Thank you!
Diego

@diegoves

use these parameters to manage in your code:

style:
      left: 53%
      top: 30%
      opacity: 0%
      scale: 1

They are self explanatory!

Than you @wgumaa but this is not what I mean. If you want to trigger the action you could tap on the arrow or also in the white space near the arrow but inside the circle I’m showing. The problem is that the circle goes above the label “100%”.

I have another question: how could I use a variable (or something else) to change for example the font size of every card inside a picture elements?

Thank you,
Diego