Lovelace: picture-elements - How to display image containing transparency?

In an attempt to make my floor plan image more Theme friendly, I decided to replace all of the whitespace with a transparency and then export the floor plan as a PNG. Unfortunately, HA is not rendering the image correctly with any sort of transparency. I’ve read through the picture-elements documentation but nothing really stands out to me as a possible solution. Here are my settings, a screenshot of the rendered lovelace card, and a screenshot of the actual image I am trying to output.

Am I doing this correctly?

  - title: Floor Plan
    id: main-floor
    icon: mdi:floor-plan
    panel: true
    cards:
      - type: picture-elements
        image: /local/floorplan/floorplan_transparent.png
        elements:
           <long list of elements removed>

Rendered Card
24%20PM

Actual Image (Transparency is inside the floor plan.)

Hi!
I use png picture for my picture-elemets card that has transparancy around and it works without problems.

Everything around the walls are transparancy and the theme color is shown. Also between the bars of the “fence” at the belcony is transparent expect the long side that has som white stripes left.

All and all, it should work but dont know why its not working for you. Have you tried to remove cookies and stored images in the browser?

Thank you for you reply. I indeed purged all of my history and cookies. I also tried different browsers which yielded the same result. FWIW, the filename for the transparent version of the floorplan is different than the original floorplan image filename. I use this method to work around the need to clear browser history as it is far more efficient.

Can you upload the png file and I will give it a try later when I am at home?

The png file is in the original post. Just right-click and save as.

The attached file is jpg.

WTH? Not sure how that happened.

I just re-uploaded the image file. Try it now.

Tried your PNG and the transparancy works for me. Not sure why its not working for you. :confused:

  • type: picture-elements
    image: /local/floorplan/test.png
    elements:
    • type: state-icon
      entity: switch.reciver
      tap_action: none
      style:
      top: 50%
      left: 50%

Color me confused. This makes no sense…

I’ve identified the culprit. As it turns out, the filename as listed in ui-lovelace.yaml was incorrect. I used an underscore instead of a dash. Therefore, lovelace could not load a file that didn’t exist…

TLDR, I’m an idiot.

Happens to all of us at some point, dont be too hard on yourself :grin:

Hi @r1kkie - I notice you are doing something similar to me above with the 3D floorplan and I was hoping you could help me further understand picture-elements. I have my floorplan done, split each ‘lit’ room into various files (were layers in photoshop) and have them working in lovelace no worries. However, I am starting to have issues with each transparent room overlapping the other as from what I understand, PNG files (like all transparent files) are still square although they only display the none transparent bit. This isn’t really an issue if using light icons to control your lights as the transparency hides the true dimensions of the image file but I am wanting to use the image tap action so that when I touch a room the light goes on or off. However, being a 3D background, the rooms are not rectangular like the images so the area you click overlaps with other rooms. Sorry, hard to explain but in a nutshell, each transparent image is fine unless you want to use it for tap action toggling of lights, where the ‘actual’ image dimensions are different from what’s visible (ie the rooms). If you click in the middle of a room it generally works ok but other rooms still infringe on the edges.

Did you have this issue with your floorplan (looks great BTW) or am I missing something? Am I simply forced to use light switch state-icons because of this issue? Would be great if we could map out areas that the tap action works from so that we can have more accuracy but I guess that isn’t currently possible.

Thanks.

Lachlan.

I think i understand what your saying. I made it easy and made all pictures that overlaps equal in size so the positioning and sizeing wouldnt be an issue. What you could do is to overlap a square that fits inside the selected room and use that one for your tap action. This will however create some “blind spots” but as far as my knowing thats your best bet.

Good luck on your project!

1 Like

Hi, could someone help me with this simple one, I cant get an image to display in Lovelace? I have added four photo’s (as jpg) into my www folder, then added this into my lovelace.yaml;

  • type: picture-entity
    entity: device_tracker.richard_pretious
    state_image:
    “home”: /local/richardhome.jpg
    “away”: /local/richardaway.jpg

but I’m getting this error;

I know I’m mad late but you guys are the closest to my issue so hoping y’all can help me out. I’m running into a transparency issue with only the active entity taking over the whole image
ezgif.com-gif-maker (3)

type: picture-elements
image: /local/floorplan-images/all_off.png
elements:
  - type: image
    entity: light.office_overhead
    tap_action: none
    hold_action: none
    state_image:
      'on': /local/floorplan-images/office_light_overhead.png
      'off': /local/floorplan-images/home_trans.png
    style:
      top: 50%
      left: 50%
      width: 100%
  - type: image
    entity: light.bigtv
    tap_action: none
    hold_action: none
    state_image:
      'on': /local/floorplan-images/livingroom_LED_tv.png
      'off': /local/floorplan-images/home_trans.png
    style:
      top: 50%
      left: 50%
      width: 100%
  - type: image
    entity: switch.living_room_lamp_tall
    tap_action: none
    hold_action: none
    state_image:
      'on': /local/floorplan-images/livingroom_lamp_tall.png
      'off': /local/floorplan-images/home_trans.png
    style:
      top: 50%
      left: 50%
      width: 100%
  - type: state-icon
    entity: switch.living_room_lamp_tall
    tap_action:
      action: toggle
    style:
      '--mdc-icon-size': 15px
      '--paper-item-icon-color': gray
      top: 33%
      left: 35.5%
  - type: state-icon
    entity: light.bigtv
    tap_action:
      action: toggle
    style:
      '--mdc-icon-size': 15px
      '--paper-item-icon-color': gray
      top: 40%
      left: 23.5%
  - type: state-icon
    entity: light.office_overhead
    tap_action:
      action: toggle
    style:
      '--mdc-icon-size': 15px
      '--paper-item-icon-color': gray
      top: 43%
      left: 54.5%