3D Floorplan using lovelace picture-elements card

Hey Fahr!
Thank you so much for this tutorial. I have created my floorplan and picture elements card. I am using state-icon instead of a transparent image in my floorplan as it is easier for my parents to use. The whole picture elements card seems to be clickable tho. I’ve tried adding the hold_action:none in every light overlay but still doesnt seem to work :confused: Before this, I tried adding tap action:none and hold_action:none, but that didnt seem to work either. Here is a copy of my config, any help will be appreciated!

type: picture-elements
image: /local/images/3d_floorplan/top_floor/final_upstairs_dark.png
elements:
  - type: image
    entity: switch.s24
    style:
      left: 50%
      top: 50%
      width: 100%
    state_image:
      'on': /local/images/3d_floorplan/top_floor/Final_Upstairs_living_left_on.png
      'off': /local/images/3d_floorplan/top_floor/transparent.png
  - type: state-icon
    entity: switch.s24
    style:
      left: 45%
      top: 35%
    tap_action:
      action: toggle
  - type: image
    entity: switch.s20_2
    style:
      left: 50%
      top: 50%
      width: 100%
    state_image:
      'on': /local/images/3d_floorplan/top_floor/Final_Upstairs_living_right_on.png
      'off': /local/images/3d_floorplan/top_floor/transparent.png
  - type: state-icon
    entity: switch.s20_2
    style:
      left: 45%
      top: 52%
    tap_action:
      action: toggle
  - type: image
    entity: switch.s19_3
    style:
      left: 50%
      top: 50%
      width: 100%
    state_image:
      'on': /local/images/3d_floorplan/top_floor/final_top_floor_back_lights_on.png
      'off': /local/images/3d_floorplan/top_floor/transparent.png
  - type: state-icon
    entity: switch.s19_3
    style:
      left: 35%
      top: 49%
    tap_action:
      action: toggle
  - type: image
    entity: switch.s19_1
    style:
      left: 50%
      top: 50%
      width: 100%
    state_image:
      'on': /local/images/3d_floorplan/top_floor/Final_top_stair_lights_on.png
      'off': /local/images/3d_floorplan/top_floor/transparent.png
  - type: state-icon
    entity: switch.s19_1
    style:
      left: 22%
      top: 45%
    tap_action:
      action: toggle
  - type: image
    entity: light.s22
    hold_action: none
    style:
      left: 50%
      top: 50%
      width: 100%
    state_image:
      'on': /local/images/3d_floorplan/top_floor/Final_Upstairs_living_main_on.png
      'off': /local/images/3d_floorplan/top_floor/transparent.png
  - type: state-icon
    entity: light.s22
    style:
      left: 49%
      top: 43%
    tap_action:
      action: toggle
  - type: image
    entity: switch.s28_1
    style:
      left: 50%
      top: 50%
      width: 100%
    state_image:
      'on': /local/images/3d_floorplan/top_floor/Final_kitchenette_on.png
      'off': /local/images/3d_floorplan/top_floor/transparent.png
  - type: state-icon
    entity: switch.s28_1
    style:
      left: 51%
      top: 55%
    tap_action:
      action: toggle
  - type: image
    entity: switch.s26
    style:
      left: 50%
      top: 50%
      width: 100%
    state_image:
      'on': /local/images/3d_floorplan/top_floor/walk_in_robe_on.png
      'off': /local/images/3d_floorplan/top_floor/transparent.png
  - type: state-icon
    entity: switch.s26
    style:
      left: 60%
      top: 22%
    tap_action:
      action: toggle
  - type: image
    entity: light.s25
    hold_action: none
    style:
      left: 50%
      top: 50%
      width: 100%
    state_image:
      'on': /local/images/3d_floorplan/top_floor/Bedroom_1_on.png
      'off': /local/images/3d_floorplan/top_floor/transparent.png
  - type: state-icon
    entity: light.s25
    style:
      left: 70%
      top: 22%
    tap_action:
      action: toggle
  - type: image
    entity: light.bed2
    hold_action: none
    style:
      left: 50%
      top: 50%
      width: 100%
    state_image:
      'on': /local/images/3d_floorplan/top_floor/Bedroom_2_on.png
      'off': /local/images/3d_floorplan/top_floor/transparent.png
  - type: state-icon
    entity: light.bed2
    style:
      left: 30%
      top: 22%
    tap_action:
      action: toggle
  - type: image
    entity: light.bed3
    hold_action: none
    style:
      left: 50%
      top: 50%
      width: 100%
    state_image:
      'on': /local/images/3d_floorplan/top_floor/Bedroom_3_on.png
      'off': /local/images/3d_floorplan/top_floor/transparent.png
  - type: state-icon
    entity: light.bed3
    style:
      left: 75%
      top: 65%
    tap_action:
      action: toggle
  - type: image
    entity: switch.bed4
    style:
      left: 50%
      top: 50%
      width: 100%
    state_image:
      'on': /local/images/3d_floorplan/top_floor/Bedroom_4_on.png
      'off': /local/images/3d_floorplan/top_floor/transparent.png
  - type: state-icon
    entity: switch.bed4
    style:
      left: 30%
      top: 65%
    tap_action:
      action: toggle
  - type: image
    entity: light.lifx_d0_73_d5_3c_10_f2
    hold_action: none
    style:
      left: 50%
      top: 50%
      width: 100%
    state_image:
      'on': >-
        /local/images/3d_floorplan/top_floor/Room_lamp_on.png
      'off': /local/images/3d_floorplan/top_floor/transparent.png
  - type: state-icon
    entity: light.lifx_d0_73_d5_3c_10_f2
    style:
      left: 79%
      top: 60%
    tap_action:
      action: toggle
  - type: image
    entity: light.lifx_d0_73_d5_3b_f9_1b
    hold_action: none
    style:
      left: 50%
      top: 50%
      width: 100%
    state_image:
      'on': >-
        /local/images/3d_floorplan/top_floor/Room_lamp_brown_on.png
      'off': /local/images/3d_floorplan/top_floor/transparent.png
  - type: state-icon
    entity: light.lifx_d0_73_d5_3b_f9_1b
    style:
      left: 71%
      top: 72%
    tap_action:
      action: toggle

I’m pretty sure this is due to the ordering of your elements. I had to go back to my blog post to verify because I thought I mentioned it in there since it’s a gotcha:

Ensure that you put all of your lighting overlays at the top of your view. All of the toggles should be below your overlays. If you do not do this, then you will not be able to click on any of your toggles. So the order matters.

So in your case, all of your state-icon elements need to go below all of the lighting overlay elements.

hello everyone, I have a problem with lovelace, in the iphone open the floorplan but in browser give me error ‘’ You need to define an entity ‘’ what can I be doing wrong ??

I’m not familiar with this custom floorplan card. This post is about creating a floorplan using the picture-elements card. I’d ask in the floorplan topic: https://community.home-assistant.io/c/third-party/floorplan/28

gday guys ,
i am just starting home assistant the last 2 weeks and managed to have my floorplan 3d done , it works great in card display on lovelace but not in panel display , only the plan shows but nothing happens when i turn on lights . Any help would be greatly appreciated :):slight_smile:

Hi @fahr,

First of all, thanks for your floorplan. It inspired me to get started on mine, although there are some variations since I wanted to control individual lights as well as groups.

I took your code with the input select to change floors and mine seems to not work as smoothly as yours. When I call the service, the input_select state does change, however the view does not until I refresh my lovelace. I’ve set up an automation to refresh the lovelace view based on the input_select state via browser mod. This works, but takes about 10 seconds to complete.

Did you do anything more to get this working?

I’m not doing anything different than what I put in the post. Are you sure you are using a conditional card to display the correct floor based on the value of the input select?

I went the state-switch route. The reason is, I noticed the first floor’s picture-element was moved over slightly to the right in relation to the ground floor, due to the horizontal-stack.
I guess I’ll investigate on that side of things, then… Or if you have a solution for said placement difference due to horizontal-stack, I’m all ears :wink:

I’m not sure I know what a state-switch is. It’s hard to say what the cause might be without seeing your lovelace configuration for your floorplan.

State-switch is a custom card, see:
https://github.com/thomasloven/lovelace-state-switch

Here you go for the first lines of my yaml (more of the same repeating for the different views):

custom_header:
  compact_mode: true
  exceptions:
    - conditions:
        device_id: 2c088d82-ca71ed40
      config:
        disable_sidebar: true
        kiosk_mode: true
title: Home

views:

- title: Vue d'ensemble
  theme: slate
  icon: 'mdi:floor-plan'
  panel: true
  badges: []
  path: overview
  cards:
 
    - type: 'custom:config-template-card'
      entities:
        - light.cuisine_deco
        - light.cuisine_plafonnier
        - light.manger_lampe
        - light.manger_plafonnier
        - light.grand_totem
        - light.grand_totem_deco
        - light.petit_totem
        - light.petit_totem_deco
        - light.salon_plafonnier
        - light.panneau_lumineux
        - light.tv
        - light.vinyles
        - light.bar
        - light.salon_3
        - light.cuisine_3
        - light.terrasse_sol
        - light.terrasse_3
        - light.couleur_rez
        - light.lit_parents_blanc
        - light.lit_parents_couleur
        - light.chevet_cdrx_4
        - light.chevet_nanne_3
        - light.plafond_charles_exterieur_white
        - light.plafond_charles_interieur_white
        - light.imprimante
      card:
        type: 'custom:state-switch'
        entity: input_select.floor
        states:
          Rez:
            !include frontend/lights_rez.yaml
          1er:
            !include frontend/lights_1er.yaml

As said, I’ll be investigating on the state-switch side in the next few days and will report back if I find anything.

Still in the process of testing, figured out that it doesn’t have to do with the type of card used, as I reverted to horizontal-stack per your setup and did not speed up the floor change.

However, I do have one question: in your code, you have an underscore in front of the included files: !include _floorplan_second_floor.yaml Is there any specific reason for this?

The reason I started with an underscore is just a reminder to me that it’s a view to be included and not a main tab that shows up in my lovelace dashboard. So it’s just a personal naming convention. Haven’t had a chance yet to look at the custom card you are using but hope to this week.

Ok, got it, thanks. I don’t think it’s due to the custom card. Changed it to horizontal-stack and still takes 10 seconds to switch from one view to another. I’m starting to think it has to do either with the size of images or the views, since they are quite large.

For what it’s worth, I tried out the state-switch card and replaced my conditional cards and it works exactly the same. The floorplan changes instantly. So I’m not exactly sure what’s causing your particular issue.

---
title: Floorplan
path: floorplan
panel: true
icon: 'mdi:floor-plan'
cards:
  - type: horizontal-stack
    cards:
      - type: custom:state-switch
        entity: input_select.floorplan_floor
        states:
          "1st Floor": !include _floorplan_first_floor.yaml
          "2nd Floor": !include _floorplan_second_floor.yaml

Thank you for testing. As said, I’m leaning towards the size of the images. I’m following this way of including pictures and blending them, and seeing as each image is around 3MB in size, I’m really leaning towards the time it takes to load all this as the cause.

Just want to say thanks for this amazing guide and I have created a 3d floorplan and have it working with my home assistant.

1 Like

Glad to hear it was helpful!

Nice tutorial Aaron, I was looking for some information about state of a offline device but couldn’t find anything, that’s how i stumble on this topic. The information I was looking was not here either, but I figured out with trial and error on my 3D floor plan dash.

When one of your devices gets offline by removing it or just because of a failure, you get a broken image over your whole floor plan and that looks ugly since it covers whole 3D plan.

To fix that you need to add an ‘unavailable’ state in your code.

For example:

    state_image:
      "on": /local/floorplan/kitchen_on.png
      "off": /local/floorplan/transparent.png
      "unavailable": /local/floorplan/transparent.png

It is up to you if you want to add in your first post.

Now I am looking for curtain switch states, so I can play with closed and open curtains/roller shutters in my plans.

4 Likes

That’s a fantastic tip! I’ve actually had some entity that’s been unavailable in my floor plan for over a month but I’ve been too busy to look into it. It resulted in exactly what you described, a large broken image over your floor plan.

I used your example and added an unavailable state to each entity one by one and found out which one was causing the issue. Thanks so much for posting this, I will definitely update the blog post and credit your post here for the solution.

I’m thinking it might be nice to somehow call attention to it. In my case it was unavailable because I had renamed the entity. So rather than just hiding the problem if there were a way to highlight the entity that was causing the issue with the unavailable state that could be very useful. Perhaps a transparent square with a red border that highlights the element. Going to think about this and try out a few things.

2 Likes

I am glad if it was helpful, I don’t need credits for simple thing like this, I am sure you’d find out too.

About using transparent square with red border, it does not work unfortunately, if the image is small, lets say 50x50pxl it will automatically resize it to the floorplan.

In my case I can see the problem because I use state-icon as well, and when a entity is not available it will grayout.