Styling elements in Picture elements card: a small tutorial

You only can do it by using “pure card-mod” - but results may not satisfy you:

type: vertical-stack
cards:
  - type: picture-elements
    elements:
      - type: state-icon
        entity: sun.sun
        style:
          top: 50%
          left: 50%
    image: "/local/images/blue_low_2.jpg"
  - type: picture-elements
    elements:
      - type: state-icon
        entity: sun.sun
        style:
          top: 50%
          left: 50%
    image: "/local/images/blue_low_2.jpg"
    card_mod:
      style:
        hui-image $: |
          img {
            transform: rotate(45deg);
          }

изображение

Thanks for the tutorial which helped al lot. So far I did not manage to display the entity’s name. I can show state-label as well as state-icon, but is there a way to show the entity name or write a name as I’d prefer names instead of icon in this case?

best Florian

2022-10-02 19_02_32-Übersicht – Home Assistant

Consider using Entities card for displaying icon/name/states - w/o a border, with transparent background, with defined width.

That’s what I used so far, but no option for a background image, right?

Use card mod to set transparent background and removing borders and any other styling

I’m trying to recreate an Apple Remote using Photoshop by exporting each layer individually for each button. I thought this would be the best way since it would preserve the exact base dimensions for the base image and overlaid image elements (i.e. autoscale), but it appears that the picture elements card resizes image elements. Is there a way around this so that the elements scale in relation to the base image?

Photoshop

Picture Elements Card Configuration

There are width and height parameters you can set in style. Not sure that’s what you’re looking for but that’s how I set my doors and windows to scale off of a green or red rectangle.


     - type: image
        entity: binary_sensor.l_gate_opened
        state_image:
          "on": /local/redwall.png
          "off": /local/greenwall.png
          "unknown": /local/red_x.png
          "unavailable": /local/red_x.png
        style:
          top: 93%
          left: 5%
          width: 6%
          height: 1%

@bigscience Thanks. I’m aware of those parameters and was able to get it to look right, but if the picture element is already at the same scale as the base picture, why is it resized to begin with?

So if I’m following you, you made the buttons and background at the right sizes they shouldn’t need any adjustments but they do? I can’t say for sure but my guess is that it puts regular icons in at a normal size and then other pictures at the size of the background. Here you can see my floor plan with the pictures adjusted to the size I want with the height/width settings:

      - type: image
        entity: binary_sensor.living_room_motion_detected
        state_image:
          "on": /local/motion_red.png
          "off": /local/motion_grey.png
          "unknown": /local/red_x.png
          "unavailable": /local/red_x.png
        style:
          top: 60%
          left: 88%
          width: 5%

image

If I add in a picture with no scaling, it makes it full size:

      - type: image
        entity: binary_sensor.living_room_motion_detected
        state_image:
          "on": /local/motion_red.png
          "off": /local/motion_grey.png
          "unknown": /local/red_x.png
          "unavailable": /local/red_x.png
        style:
          top: 50%
          left: 50%
#          width: 5%

image

1 Like

You’re addressing my question. I suppose I still don’t understand why it works this way and am trying to determine if it’s a good feature request to have non-CSS scaled picture elements to essentially auto-scale with the background/base image.

Here’s another question. Is there a way to get this card to use the transparency data for the action zones of non-rectangular .png’s used as picture elements?

The picture elements I used are .png’s with transparency, but it appears that this card does not use that information to determine the “action zones” (or whatever they’re called). Here’s a screenshot with the elements’ opacity at 50% (will eventually be set to 0%). My cursor focus is at the top left corner of the info popup which is in the transparent area of the picture element image, but within the horizontal and vertical dimensions of the image.

Try playing with “pointer-events: none” style for elements you do not want to intercept mouse input.

1 Like

@Ildar_Gabdullin Thank you. But, if I understand that property right, it would also disable mouse clicks on the non-transparent part of the picture element. Is that right? If so, that’s not what I’m after at this time.

Right. An element is rectangular.
In similar circumstances I had to revise a structure of a card (what elements are located on each layer, what is an order of layers, …).

As for scaling images - check this.

Ok. Thank you. I guess I got what I came here for which is that both are working as currently intended/designed and there’s nothing I’m missing in the basic configuration of the Picture Elements Card itself.

Overall, whether it’s this card or many others, I wish the HA front end had CSS more embedded (UI and/or yaml) so we didn’t have to mess with all of these CSS properties, card-mod, etc.

These two “issues” are IMO prime examples. I bring in a bunch of images all scaled appropriately, but the front end doesn’t present a check box to “preserve native size” (or similar). Same thing with the transparency…although if it cannot be done with CSS, I guess it’s not possible anyways (?)

That came off more rant-y than I intended. :man_shrugging:t3:

Again, thanks for your help. :wink:

2 Likes

It is mentioned that one could “– the whole floorplan card is a decluttering-card - pass a scale value as a variable;”
Ideally, that’d come from the scaling of the original image. Is there a way to do that?

If I had easy access to javascript, this would be trivial-- I’d query the image size, and compute the scale, which I could use on all the other elements, but that isn’t what we have here.

Can you add a background picture.

I do not know any way for it - may be except a brute programming by JS.

I have updated from 2022.10.5 to 2022.11.x and my style tranforms for state_image (mainly scaling) have stopped working.
Anyone else have this issue?