3D Floorplan using lovelace picture-elements card

Hello @fahr,

Love what you did here!

I do have a question.
I’m trying out your tutorial but when I have a light off, it’s not being shown as it should (the off image is being shown with full with instead of being put on the place it should be).

Lights on:

1 light (for now the only one added) off:

Do you have any idea of what I’m doing wrong?

Also with the below code the transparant square with the red border is not being added to the image.

- type: image
    entity: group.bar
    tap_action:
      action: toggle
    image: /local/floorplan/transparent_square.png
    style:
      top: 71%
      left: 40.5%
      border: 5px solid red

My guess would be the ordering of your elements is causing it to get covered up by another image. It’s really hard to say without seeing the images and more of your picture-elements yaml.

Hello @fahr,

Thank you for the fast response!

I used SweetHome 3D to create the image with the lights on and created the photo 1540x558.
To create the overlays with the lights off I took the same steps to create the image with the lights on, only then with the lights turned to 0%.
Then I used Gimp (lasso tool) to cut out the different dark parts of the house.

My /config/ui-lovelace.yaml:

  - id: floorplan2
    title: Floorplan2
    path: floorplan2
    panel: true
    icon: mdi:floor-lamp-variant
    cards:
      - type: horizontal-stack
        cards:
          - type: conditional
            conditions:
              - entity: input_select.floorplan_floor
                state: "Begane grond"
            card: !include begane-grond.yaml

My /config/begane-grond.yaml:

type: picture-elements
image: /local/floorplan/Thuis-Beganegrond.png
elements:

  # Lighting Overlays...
  - type: image
    entity: group.bar
    tap_action: none
    hold_action: none
    state_image:
      "on": /local/floorplan/transparent_square.png
      "off": /local/floorplan/Bar-Off.png
    style:
      top: 5%
      left: 10%
      width: 100%

  # Light Toggles...
  - type: image
    entity: group.bar
    tap_action:
      action: toggle
    image: /local/floorplan/transparent_square.png
    style:
      top: 71%
      left: 40.5%
      border: 5px solid red

  # Floor Toggle
  - type: service-button
    title: Begane grond
    service: input_select.select_next
    service_data:
      entity_id: input_select.floorplan_floor
    style:
      top: 15%
      left: 5%
      background: "#eaeaea"
      border-radius: 5%

Sorry, English isn’t my native language, hope you understand what I mean.

Bar-Off

Your English is excellent!

Are those 2 images the exact same that you are using? If so it will not work like you want. The image you have with the lights off needs to be exactly the same size as the main image with the lights on. It should be the same size with the rest of the image being transparent.

1 Like

Ohhhh I didn’t understand it like that.
I thought I had to cut the part out but now I understand that you have to cut the rest out and make it transparent.

Thanks I will try that in a bit!

Any idea why the transparent square with the red border isn’t showing?

@fahr,

Thank you for your help/explaination!
I’ve come up with below results, not the most beautiful work but it’ll do for now.

Lights off:

Livingroom, bar, garage and front door on:

Great work! You may want to try adding a gaussian blur around the edges of the image with the lights off to make the darker areas blend better into the lit areas.

Glad you got it working!

1 Like

Thank you for the tips @fahr!

Still struggling a bit with creating the lights off images (see image below with the lights off, you can see the lights from the image below (with all the lights on) coming through).
But for now I’m kind of satisfied.

Seems that the light coming from the image below (with the lights on) is being caused by the blur I added.
When I replace the dark images with the ones I haven’t applied the blur to, it’s a lot better.

image

It is tricky when you have multiple lights in a single room. That’s the primary reason each room only has one light that can be clicked which controls the entire room in my floorplan.

Since you only have one room like this the other thing you could do is multiple renders with one light on and 2 off, 2 lights on and 1 off, etc. That would create a lot of extra work though, so if you are happy with what you’ve got I would stick with that!

1 Like

Hello @fahr,

Yes that’s what I thought, I will leave it like this for now.
Thank you for all your help and tips!

cris, i can code but i cant work with gimp, im trying to lasso etc, but i cant get it to work, do you have a quick tutorial for this, i dunno how to setup the layers for it to work.

Great job btw

Hello @henrikrox,

I’m not the right person to write a tutorial about Gimp since I don’t know the program as well, but I can tell you what I did.

First I added a transparant layer to the images with the lights off, and then I used the lasso tool to cut everything out except the part I need to create the dark image.
After that I exported the image as png and that can be used to create the overlay.

Hi @fahr,

Your great work has inspired and instructed me to do a 3D floor plan for my apartment. Thank you very much.
I and my daughter now enjoy to control the apartment with this new awesome 3D model :grinning:

I noticed that in your youtube clip, you’ve showed the back door opened in when door contact sensor reported open status. So I also want to do it for my floor plan. However, it will happen that we will have 4 images for different status of 1 room, including: light on & door open, light off & door open, light on & door closed, light off & door closed. So I am thinking about how to code it into ui-lovelace.yaml to display correct status of light and door. Could you please share me your experience about that? Thank you very much.

Very nicely done!

I use 4 images for the various states for when the backdoor is open (both lights on, no lights on, kitchen light on and mud room light off, kitchen light off mud room light on). I’m using conditional elements to handle that. Here’s a snippet for which image I show based on the back door sensor status:

  ## Back Door Sensor
  - type: conditional
    conditions:
      - entity: light.kitchen
        state: 'on'
      - entity: switch.mud_room_light
        state: 'on'
    elements:
      - type: image
        entity: binary_sensor.back_door_contact
        tap_action: none
        hold_action: none
        state_image:
          "on": /local/floorplan/first_floor_kitchen_and_mud_room_lights_on_back_door_open.png
          "off": /local/floorplan/transparent_square.png
        style:
          top: 50%
          left: 50%
          width: 100%

  - type: conditional
    conditions:
      - entity: light.kitchen
        state: 'off'
      - entity: switch.mud_room_light
        state: 'off'
    elements:
      - type: image
        entity: binary_sensor.back_door_contact
        tap_action: none
        hold_action: none
        state_image:
          "on": /local/floorplan/first_floor_lights_off_back_door_open.png
          "off": /local/floorplan/transparent_square.png
        style:
          top: 50%
          left: 50%
          width: 100%

  - type: conditional
    conditions:
      - entity: light.kitchen
        state: 'off'
      - entity: switch.mud_room_light
        state: 'on'
    elements:
      - type: image
        entity: binary_sensor.back_door_contact
        tap_action: none
        hold_action: none
        state_image:
          "on": /local/floorplan/first_floor_mud_room_lights_on_back_door_open.png
          "off": /local/floorplan/transparent_square.png
        style:
          top: 50%
          left: 50%
          width: 100%

  - type: conditional
    conditions:
      - entity: light.kitchen
        state: 'on'
      - entity: switch.mud_room_light
        state: 'off'
    elements:
      - type: image
        entity: binary_sensor.back_door_contact
        tap_action: none
        hold_action: none
        state_image:
          "on": /local/floorplan/first_floor_kitchen_lights_on_back_door_open.png
          "off": /local/floorplan/transparent_square.png
        style:
          top: 50%
          left: 50%
          width: 100%

The door closed is the default state of the floorplan so I am using the normal way documented in the blog post for showing the lights on or off in the kitchen or mud room.

3 Likes

Thank you very much @fahr !

I changed to use conditional elements as you advised for both state changing of sensors and switches and it worked perfectly.

Hope to see more of your great works on 3D floor plan :slight_smile: Thank you.

I am trying to figure out how to use a state label to be displayed when a window is open, but disappear when the window is closed. I can get the state-label to say “On” if the window is open, or “Off” if it is shut. I would like it to say, “Bedroom Window Open.” and nothing for “Off”. Any ideas?

You should be able to use a conditional element to achieve this.

So studying this for a couple of nights now, I am not sure a state label is available the way I want it, or at least the way I want to do it. It looks like under the conditional element, you can use other “elements” but I can’t even get the “Title” to work with the state-labels. I can get the prefix and suffix to work. But I can’t seem to change the label from “On” to “Open”.

          - type: conditional
            conditions:
              entity: binary_sensor.zds_backdoor
              state: "on"
            elements: state-label
            title: "Backdoor Open"
            style:
              top: 60%
              left: 87%
              --iron-icon-stroke-color: "#969696"
              border-radius: 50%
              text-align: center
              background-color: "rgba(255, 255, 255, 0.3)"

One thing I have considered is going back and adding the text to the png files, and building conditional elements based off of that.

Sorry it took me so long to respond, it’s been a busy few weeks. I played around with my own floorplan and came up with a solution for you. The first thing I want to point out in your example is that title refers to the tooltip when your cursor hovers over the entity, so that will not change the title.

You were on the right track using the prefix.

  - type: state-label
    entity: binary_sensor.back_door_contact
    title: "This is a tooltip for the back door contact sensor"
    prefix: "Backdoor "
    style:
      top: 84%
      left: 5%
      --iron-icon-stroke-color: "#969696"
      border-radius: 50%
      text-align: center
      background-color: "rgba(255, 255, 255, 0.3)"

The above code renders this on my floorplan (note in the screenshot my cursor was hovering over the entity):
backdoor

When the back door is opened it changes to Backdoor Open just like you wanted it to be displayed. In order for the state to show as Closed/Open instead of on/off you will need to customize the entity and change the Device Class to opening. To do this, go to the Configuration page then scroll down and click on Customizations. On this page select your entity from the Entity dropdown. Then click on the pencil icon next to Device Class dropdown. Finally, select “opening” from the dropdown then click Save.