Styling elements in Picture elements card: a small tutorial

I am in the process of creating a floor plan based on the Picture Element Card and am actually quite happy with it.

However, I am currently trying to display my switched-on lights differently. I would like to have them with a yellow button background, preferably a little blurred and the icon itself also in yellow. However, the icon background is very small and I can’t get it any bigger, can anyone help me here, also with the blurred effect?

image

  - type: state-icon
    state_color: false
    entity: light.wohnzimmer_spots
    tap_action:
      action: toggle
    style:
      top: 39%
      left: 44%
      border-radius: 50%
      background-color: rgba(102, 102, 102, 0.2)
    card_mod:
      style:
        state-badge $: |
          ha-state-icon {
            {% if is_state('light.wohnzimmer_spots','on') %}
              color: red !important;
              background-color: #f5ff00 !important;
              border-radius: 50% !important;
              background-size: 45px !important;
            {% else %}
            color: white;
            {% endif %}
          }
1 Like

Not sure about the blurred effect but try adding width under the style.
example:

        style:
          top: 22%
          left: 80%
          width: 4%

I changed to:

  - type: state-icon
    state_color: false
    entity: light.wohnzimmer_spots
    tap_action:
      action: toggle
    style:
      top: 39%
      left: 44%
      width: 4%
      border-radius: 50%
      background-color: rgba(102, 102, 102, 0.2)
    card_mod:
      style:
        state-badge $: |
          ha-state-icon {
            {% if is_state('light.wohnzimmer_spots','on') %}
              color: red !important;
              background-color: #f5ff00 !important;
              border-radius: 50% !important;
              background-size: 45px !important;
            {% else %}
            color: white;
            {% endif %}
          }

However, this only moves the icon to the left, but the yellow background behind the icon has not been enlarged.

I have found a solution for myself with the “custom:config-template-card”, and I also use variables that are defined in card-mod.

      - type: custom:config-template-card
        entities:
          - light.wohnzimmer_spots
        element:
          type: state-icon
          state_color: false
          entity: light.wohnzimmer_spots
          tap_action:
            action: toggle
        style:
          top: 39%
          left: 45%
          border-radius: 50%
          "--paper-item-icon-color": >-
            ${states['light.wohnzimmer_spots'].state === 'on' ? 'var(--light-button-active-state-colour)' : 'var(--light-button-inactive-state-colour)'}
          background-color: >-
            ${states['light.wohnzimmer_spots'].state === 'on' ? 'var(--light-button-active-state-background-colour)' : 'var(--light-button-inactive-state-background-colour)'}
type: vertical-stack
cards:
  - type: picture-elements
    image: /local/floorplan/EG/Night.png
    style:
      left: 50%
      top: 45%
      width: 160%
    card_mod:
      style: |
        ha-card {
          color: #ffffff; border: solid 2px #A0A2A8; box-shadow: none;
          
          --light-button-active-state-colour: yellow;
          --light-button-active-state-background-colour: #fafacd66;
          --light-button-inactive-state-colour: white;
          --light-button-inactive-state-background-colour: #66666699;
        }

Hello, can you pls say me: how can I make a smaller this card?
But the card or picture is too big. I will be very happy when it go to half of the height.

This is me code:
image

thank you

What’s wrong?
It’s always written in black

type: picture-elements
image: local/jbb/plan-32-lafontaine-rdc-1er.png
card_mod:
  style: |
    ha-card { 
      {% if is_state('climate.chambrecam','off') %} 
      --color-state-climate: cyan;
      {% else %}
      --color-state-climate: red ;
      {% endif %}
    }
elements:  
  - type: state-label
    attribute: current_temperature
    style:
      left: 75%
      top: 10%
      font-size: 10px
      font-weight: bold
      color: var(--color-state-climate)
      # color: blue
    entity: climate.chambrecam

Hello ciscolyon69

The card_mod of the picture-elements card is written after the state-label uses the variable.

I have this issue myself and am still searching for a way to fix it.
If you dont mind re-typing it for each element you could fix it by moving the card_mood to the element itself

PS: Probably a typo in pasting here but your state-label element should be below the elements row

I try with no success, still writing in black

  - type: state-label
    attribute: current_temperature
    card_mod:
      style: |
        ha-card { 
          {% if is_state('climate.chambrecam','off') %} 
          --color-state-climate: cyan;
          {% else %}
          --color-state-climate: red ;
          {% endif %}
        }
    style:
      left: 75%
      top: 10%
      font-size: 10px
      font-weight: bold
      color: var(--color-state-climate)
    entity: climate.chambrecam

This is wrong.
Either use a “:host” or move card_mod code to the picture-elements card’s level.
Suggest you to check a proper syntax as per info provided in the 1st post.

still black

  - type: state-label
    attribute: current_temperature
    style:
      left: 75%
      top: 10%
      font-size: 10px
      font-weight: bold
      # color: var(--color-state-climate)
    card_mod:
      style: |
        :host {      
          color: red
        }
    entity: climate.chambrecam

Because you are doing smth which was not suggested. Why not trying to set that variable you first intended to use?

it doesn’t work, there is something I’m missing

type: state-label
attribute: current_temperature
card_mod:
  style: |
    :host {      
      --color-state-climate: cyan;
    }
style:
  left: 75%
  top: 10%
  font-size: 10px
  font-weight: bold
  color: var(--color-state-climate)
entity: climate.chambrecam

It works:

type: picture-elements
elements:
  - type: state-label
    entity: sun.sun
    attribute: elevation
    card_mod:
      style: |
        :host {      
          --color-state-climate: cyan;
        }
    style:
      left: 75%
      top: 10%
      font-size: 10px
      font-weight: bold
      color: var(--color-state-climate)
image: https://demo.home-assistant.io/stub_config/floorplan.png

BTW, in THIS particular case there is no need to use some particular CSS var.
This CSS var can be named like “–my-fictious-climate”. Honestly I have no idea if this “–color-state-climate” does exist. Means - the whole code may be written as

  - type: state-label
    entity: sun.sun
    attribute: elevation
    style:
      left: 75%
      top: 10%
      font-size: 10px
      font-weight: bold
      color: cyan

But only if you need to set a color conditionally - then yes, card-mod should be used:

  - type: state-label
    entity: sun.sun
    attribute: elevation
    card_mod:
      style: |
        :host {      
          {% if ... -%}
          --anything: cyan;
          {%- else -%}
          --anything: red;
          {%- endif %}
        }
    style:
      left: 75%
      top: 10%
      font-size: 10px
      font-weight: bold
      color: var(--anything)

And ofc card-mod must be installed.

No, it does not matter.
The only reason to define a variable on a picture-element card’s level is “this var is used in many elements”. Otherwise the variable may be defined on a particular element’s level.

IT WORKS
shame on me.
I missed this essential step and we wasted our time
mea culpa

1 Like

Hi everyone, I’m trying to create a very cute way to display my solar panels info, with the same layout used in my solar panels’ application UI. The only thing I miss is changing a rectangle’s height depending on the battery’s level. I wonder if somebody knows how to help me.


In the screenshot the rectangle is the one circled in red and here’s my code.

-type: image
image: …
style:
left: 50%
top: 74.8%

I would like to display the operating modes of a building automation center using image-element cards. The number of different operating modes is 16, these will be shown in the images. The location of the captions and data to be displayed is the same in each image. If I use 16 image-element cards, from which I select the visible image with a conditional card, everything works. Is there a simpler solution to this?
The attached program demonstrates what I want, but it doesn’t work like this. I read through this page, but I couldn’t find a solution.
I appreciate your help!

type: picture-elements
image: /local/img/transparent.jpg
elements:
  - type: state-label
    entity: sensor.blank
    prefix: HMV
    style:
      top: 18%
      left: 74%
      color: black
      font-family: Times New Roman
      font-size: 90%
      font-weight: bold
  - type: state-label
    entity: sensor.blank
    prefix: tároló
    style:
      top: 24%
      left: 74%
      color: black
      font-family: Times New Roman
      font-size: 90%
      font-weight: bold
  - type: state-label
    entity: sensor.blank
    prefix: Kazán
    style:
      top: 21%
      left: 8%
      color: black
      font-family: Times New Roman
      font-size: 90%
      font-weight: bold
  - type: state-label
    entity: sensor.blank
    prefix: Hő-
    style:
      top: 73%
      left: 8%
      color: black
      font-family: Times New Roman
      font-size: 90%
      font-weight: bold
  - type: state-label
    entity: sensor.blank
    prefix: szivattyú
    style:
      top: 79%
      left: 8%
      color: black
      font-family: Times New Roman
      font-size: 90%
      font-weight: bold
  - type: state-label
    entity: sensor.homerseklet_1
    style:
      top: 5%
      left: 25%
  - type: state-label
    entity: sensor.homerseklet_2
    style:
      top: 61%
      left: 25%
  - type: state-label
    entity: sensor.homerseklet_3
    style:
      top: 84%
      left: 25%
  - type: state-label
    entity: sensor.homerseklet_4
    style:
      top: 61%
      left: 49%
  - type: state-label
    entity: sensor.homerseklet_5
    style:
      top: 84%
      left: 49%
  - type: state-label
    entity: sensor.homerseklet_6
    style:
      top: 28%
      left: 90%
  - type: state-label
    entity: sensor.homerseklet_7
    style:
      top: 61%
      left: 90%
visibility:
  - condition: state
    entity: switch.c_gepeszet
    state: "on"
  - condition: and
    conditions:
      - condition: state
        entity: switch.cg_gephaz
        state: "on"
title: Hőközpont
card_mod:
  style: |-
    ha-card {
      {% if is_state('switch.r21', 'on') %}
        {% set IMAGE = '/local/img/hk1.jpg' %}
      {% elif is_state('switch.r22', 'on') %}
        {% set IMAGE = '/local/img/hk2.jpg' %}
      {% elif is_state('switch.r23', 'on') %}
        {% set IMAGE = '/local/img/hk3.jpg' %}
      {% else %}
        {% set IMAGE = '/local/img/hk0.jpg' %}
      {% endif %}
      font-size: 17px;
      color: white;
      background-color: black;
    }

screenshot_1

screenshot_2

It works! The card-mod setting was wrong.

card_mod:
  style: |-
    ha-card {
      font-size: 17px;
      color: white;
      background-color: black;
      {% if is_state('switch.r21', 'on') %}
        {% set IMAGE = '/local/img/hk4.jpg' %}
      {% elif is_state('switch.r22', 'on') %}
        {% set IMAGE = '/local/img/hk8.jpg' %}
      {% elif is_state('switch.r23', 'on') %}
        {% set IMAGE = '/local/img/hk13.jpg' %}
      {% else %}
        {% set IMAGE = '/local/img/hk0.jpg' %}
      {% endif %}
      background-size: 100% 100%;
      background-image: url({{IMAGE}});
    }

Do you know that if switch.r21 is ‘on’ and the state of some of the others is changed to ‘on’, the image will still be for switch.r21? Shouldn’t it be more dynamic?

Hello,
I’m trying to rotate a gauge needle, but it won’t work.

type: picture-elements
image: /local/images/background.png
elements:
  - type: image
    entity: sensor.tdegc_h_chambre_arriere_battery
    image: /local/images/aiguille.png
    style:
      top: 50%
      left: 50%
      transform: >-
        rotate({{ (states('input_number.rotation_aiguille')| round(0)| string) }}deg)
      transform-origin: center;

In the model

(states('input_number.rotation_aiguille')| round(0)| string) }}deg

gives => 163deg

What i’m doing wrong ?

Thank you.