Giter Site home page Giter Site logo

ha-floorplan's Introduction

⚠️ Please migrate to ha-floorplan ⚠️

ha-floorplan has been replaced with ha-floorplan.

Please check out the new solution, and let us know what you think.

Floorplan for Home Assistant

floorplan

Background

Out of the box, the Home Assistant front end provides a great way of viewing and interacting with your entities. This project builds on top of that, allowing you to extend the user interface by adding your own visuals.

With Floorplan for Home Assistant, you can:

  • Integrate with Home Assistant as either a state card or a custom panel
  • Display any number of entities (i.e. binary sensors, lights, cameras, etc.)
  • Style each entity's states using CSS
  • Gradually transition between states using color gradients
  • Display the last triggered binary sensor using CSS
  • Display hover-over text for each entity
  • Call a service or display a popup dialog when an entity is clicked

Despite its title, Floorplan for Home Assistant can be used as a general purpose user interface for just about anything you want to present in a visual way.

The concept is quite simple. You create an SVG file and simply add shapes/images to represent your Home Assistant entities. As long as the ids match up, your SVG comes to life and displays your entities' states in real time. Your entities also become clickable, so they act as shortcuts to opening the built-in 'more info' popups that are normally displayed by Home Assistant. This means clicking on a camera icon, for example, opens the Home Assistant 'more info' popup that displays the live camera feed. Hovering over the entitiy displays a tooltip showing all the information related to the entity.

Although using it as a floorplan is the most common use case, you can go even further and create visuals of real world components. Some examples are:

  • An SVG image of a remote control with each button click triggering a service in Home Assistant
  • An SVG image of a Ring doorbell with the sensor and camera mapped to sensors in Home Assistant
  • An SVG image of a Logitech Squeezebox media player with the screen text mapped to the state, current song, etc. in Home Assistant

Usage

To get started, copy the following files from this repo to your Home Assistant directory:

www/custom_ui/floorplan/ha-floorplan.html
www/custom_ui/floorplan/floorplan.svg
www/custom_ui/floorplan/floorplan.css
www/custom_ui/floorplan/lib/jquery-3.2.1.min.js
www/custom_ui/floorplan/lib/moment.min.js
www/custom_ui/floorplan/lib/svg-pan-zoom.min.js

Although a sample floorplan SVG file is included in this repo, you will want to create your own. See the appendix for more information.

You then have two options for how you want to the floorplan to appear in Home Assistant:

  • custom state card
  • custom panel

Of course, you can choose to have it displayed in both places. If you have several floorplans to display (i.e. different levels of a house), that is supported too.

Option 1: Floorplan custom state card

image

To display the floorplan as a custom state card, copy the following file from this repo to your Home Assistant directory:

www/custom_ui/state-card-floorplan.html

To allow the above file to be served by Home Assistant, add it to the frontend section of your Home Assistant configuration:

frontend:
  extra_html_url:
    - /local/custom_ui/state-card-floorplan.html

Since Home Assistant requires a single entity to be used as the target for a state card, create a virtual entity to represent the overall floorplan. You can choose any type of entity for this, such as the MQTT binary sensor. Add the following to your Home Assistant configuration:

binary_sensor:
  - platform: mqtt
    state_topic: dummy/floorplan/sensor
    name: Floorplan

Then, add the following to get Home Assistant to display this new virtual entity using the floorplan custom state card:

homeassistant:
  customize:    
    binary_sensor.floorplan:
      custom_ui_state_card: state-card-floorplan
      config: !include floorplan.yaml

To actually display the floorplan custom state card in the front end, add the virtual entity to one of your groups:

group:
  zones:
    name: Zones
    entities:
      - binary_sensor.floorplan

You can also add a 'last motion' entity to keep track of which binary sensor was triggered last. See the appendix for more information.

Option 2: Floorplan custom panel

image

To display the floorplan as a custom panel, copy the following file from this repo to your Home Assistant directory:

panels/floorplan.html

Then, add the following to your Home Assistant configuration:

panel_custom:
  - name: floorplan
    sidebar_title: Floorplan
    sidebar_icon: mdi:home
    url_path: floorplan
    config: !include floorplan.yaml

Configure the floorplan

Whether your floorplan is being displayed as a custom state card or as a custom panel, the same configuration file floorplan.yaml is used. This is where you tell Home Assistant which entities you want to display on your floorplan.

The example floorplan.yaml included in this repo shows how to add various entities to your floorplan and style their appearance based on their states.

At the top of the file, you provide a name for the floorplan, as well as the location of the SVG and CSS files:

      name: Demo Floorplan
      image: /local/custom_ui/floorplan/floorplan.svg
      stylesheet: /local/custom_ui/floorplan/floorplan.css

If you want the floorplan to display any warnings (i.e. SVG file does not contain required elements), add the following:

      warnings:

If you want to support panning and zooming within your SVG file, add the following:

      pan_zoom:

If you want to hide the main application toolbar and display the floorplan in true fullscreen mode (when used as a custom panel), add the following:

      hide_app_toolbar:

To set the date format displayed in the hover-over text, add the following:

      date_format: DD-MMM-YYYY

If you want to display a 'last motion' entity, you can include that in the next section of the file. You specify the name of the entity, as well as the CSS class used to style its appearance:

      last_motion_entity: sensor.template_last_motion
      last_motion_class: last-motion

The remainder of the file is where you add your floorplan groups. These floorplan groups are not to be confused with Home Assistant entity groups that are used to combine multiple entities into one.

      groups:

You need to place each of your entities into a floorplan group, since configuration is performed at a floorplan group level. The floorplan groups can be given any name, and have no purpose other than to allow for configuration of multiple items in one place.

If you've already created some Home Assistant entity groups, you can actually include those groups in two different ways:

  • single - the group will be represented as a single entity (group.pantry_lights in the example below). These sorts of Home Assistant entity groups get added beneath entities:).

  • exploded - the group will be exploded into separate entities (group.living_area_lights in the example below). These sorts of Home Assistant entity groups get added beneath groups:).

        - name: Lights
          entities:
             - light.kitchen
             - group.pantry_lights
          groups:
             - group.living_area_lights

In addition to monitoring your entities in real time, you can also trigger actions when your entities are clicked. Below is an example of such an action. Whenever one of the lights in the group is clicked, an action is triggered that calls the Home Assistant 'toggle' service. See the appendix for more information.

        - name: Lights
          entities:
             - light.kitchen
             - group.pantry_lights
          groups:
             - group.living_area_lights
          action:
            service: toggle

Below are some examples of groups, showing how to configure different types of entities in the floorplan.

Sensors

Below is an example of a 'Sensors' group, showing how to add a temperature sensor (as text) to your floorplan. in the screenshot above, this can be seen as an SVG text element displaying the current temperature (i.e. '9.0°').

The sensor's state is displayed using a text_template. As you can see, it contains some embedded code that determines which actual text to display.

The sensor's CSS class is determined dynamically using a class_template. In the example below, the CSS class is determined based on the actual temperature value.

See the appendix for more information on how to use template literals in your configuration.

        - name: Sensors
          entities:
             - sensor.melbourne_now
             - group.major_city_temp_sensors
          text_template: '${entity.state ? entity.state : "unknown"}'
          class_template: '
            var temp = parseFloat(entity.state.replace("°", ""));
            if (temp < 10)
              return "temp-low";
            else if (temp < 30)
              return "temp-medium";
            else
              return "temp-high";
            '

Below is an example of using dynamic images which are swapped out at runtime, based on the sensor's current state. In the example below, the sensor.home_dark_sky_icon entitiy is mapped to a <rect> in the SVG file with the same id (which simply acts as a placeholder). Whenever the temperature sensor changes state, the image_template is evaluated to determine which SVG image should be emebedded within the bounds of the <rect>. Also you need to make sure that the placeholder is placed directly within the svg (e.g. not in a layer in inkscape) or else the calculated coordinates will be wrong.

      groups:

        - name: Dark Sky Sensors
          entities:
            - sensor.home_dark_sky_icon
          image_template: '
            var imageName = "";

            switch (entity.state) {
              case "clear-day":
                imageName = "day";
                break;

              case "clear-night":
                imageName = "night";
                break;

              case "partly-cloudy-day":
                imageName = "cloudy-day-1";
                break;

              case "partly-cloudy-night":
                imageName = "cloudy-night-1";
                break;

              case "cloudy":
                imageName = "cloudy";
                break;

              case "rain":
                imageName = "rainy-1";
                break;

              case "snow":
                imageName = "snowy-1";
                break;
            }

            return "/local/custom_ui/floorplan/images/weather/" + imageName + ".svg";
            '

Switches

Below is an example of a 'Switches' group, showing how to add switches to your floorplan. The appearance of each switch is styled using the appropriate CSS class, based on its current state.

        - name: Switches
          entities:
             - switch.doorbell
          states:
            - state: 'on'
              class: 'doorbell-on'
            - state: 'off'
              class: 'doorbell-off'
          action:
            domain: switch
            service: toggle

Lights

Below is an example of a 'Lights' group, showing how to add lights to your floorplan. The appearance of each light is styled using the appropriate CSS class, based on its current state.

        - name: Lights
          entities:
             - light.hallway
             - light.living_room
             - light.patio
          states:
            - state: 'on'
              class: 'light-on'
            - state: 'off'
              class: 'light-off'

Alarm Panel

Below is an example of an 'Alarm Panel' group, showing how to add an alarm panel (as text) to your floorplan. The appearance of the alarm panel is styled using the appropriate CSS class, based on its current state. In the screenshot above, this can be seen as an SVG text element displaying the current alarm status (i.e. 'disarmed').

       - name: Alarm Panel
          entities:
             - alarm_control_panel.alarm
          states:
            - state: 'armed_away'
              class: 'alarm-armed'
            - state: 'armed_home'
              class: 'alarm-armed'
            - state: 'disarmed'
              class: 'alarm-disarmed'

Binary Sensors

Below is an example of a 'Binary sensors' group, showing how to add binary sensors to your floorplan. The appearance of each binary sensor is styled using the appropriate CSS class, based on its current state. In the screenshot above, these can be seen as SVG paths (i.e. rooms/zones of the house).

The state_transitions section is optional, and allows your binary sensors to visually transition from one state to another, using the fill colors defined in the CSS classes associated with each state. You can specify the duration (in seconds) for the transition from one color to the other.

        - name: Binary Sensors
          entities:
            - binary_sensor.front_hallway
            - binary_sensor.kitchen
            - binary_sensor.master_bedroom
            - binary_sensor.theatre_room
          states:
            - state: 'off'
              class: 'info-background'
            - state: 'on'
              class: 'warning-background'
          state_transitions:
            - name: On to off
              from_state: 'on'
              to_state: 'off'
              duration: 10

Cameras

Below is an example of a 'Cameras' group, showing how to add cameras to your floorplan. The appearance of each camera is styled using the appropriate CSS class, based on its current state. In the screenshot above, these can be seen as camera icons, which were imported from an external SVG image.

    - name: Cameras
      entities:
        - camera.hallway
        - camera.driveway
        - camera.front_door
        - camera.backyard
      states:
        - state: 'idle'
          class: 'camera-idle'

Media Players

Below is an example of a 'Media Players' group, showing how to add media players to your floorplan. The appearance of each media player is styled using the appropriate CSS class, based on its current state. In the screenshot above, these can be seen as Logitech Squeezebox icons, which were imported from an external SVG image.

    - name: Media Players
      entities:
        - media_player.alfresco
        - media_player.ensuite
        - media_player.salon
      states:
        - state: 'off'
          class: 'squeezebox-off'
        - state: 'idle'
          class: 'squeezebox-off'
        - state: 'paused'
          class: 'squeezebox-off'
        - state: 'playing'
          class: 'squeezebox-on'

Toggling the visibility of entities

If you'd like to control the visibility of your entities, you can create a layer in your SVG file (using the <g> element) that contains the entities you want show/hide, along with a button (using <rect>, for example) that is actually used to toggle the visiblity. Below is an example of a button media_players_button that toggles the visibility of all media players in the floorplan (i.e. those that are contained within the media_players_layer layer). The floorplan toggles between the two CSS classes whenever the button is clicked.

        - name: Media Players
          elements:
            - media_players_button
          action:
            domain: class
            service: toggle
            data:
              elements:
                - media_players_layer
              classes:
                - layer-visible
                - layer-hidden
              default_class: layer-hidden

Appendix

Creating a floorplan SVG file

Inkscape is a free application that lets you create vector images. You can make your floorplan as simple or as detailed as you want. The only requirement is that you create an element (i.e. rect, path, text, etc.) for each entity ( i.e. binary sensor, switch, camera, etc.) you want to display on your floorplan. Each of these elements needs to have its id set to the corresponding entity name in Home Assistant.

For example, below is what the SVG element looks like for a Front Hallway binary sensor. The id of the shape is set to the entity name binary_sensor.front_hallway. This allows the shape to automatically get hooked up to the right entity when the floorplan is displayed.

<path id="binary_sensor.front_hallway" d="M650 396 c0 -30 4 -34 31 -40 17 -3 107 -6 200 -6 l169 0 0 40 0 40
-200 0 -200 0 0 -34z"/>

If you need a good source of SVG files for icons or images, you can check out the following resources : Material Design Icons, Noun Project and Flat Icon

Adding a last motion entity to your floorplan

As an optional step, you can create a 'last motion' entity to keep track of which binary sensor was triggered last. To do so, add the following:

sensor:
  - platform: template
    sensors:
      template_last_motion:
        friendly_name: 'Last Motion'
        value_template: >
          {%- set sensors = [states.binary_sensor.theatre_room, states.binary_sensor.back_hallway, states.binary_sensor.front_hallway, states.binary_sensor.kitchen] %}
          {% for sensor in sensors %}
            {% if as_timestamp(sensor.last_changed) == as_timestamp(sensors | map(attribute='last_changed') | max) %}
              {{ sensor.name }}
            {% endif %}
          {% endfor %}

To actually display the 'last motion' entity', add it to one of your groups:

group:
  zones:
    name: Zones
    entities:
      - sensor.template_last_motion
      - binary_sensor.floorplan

Using template literals in your configuration

The settings text_template, class_template, and action_template allow you to inject your own expressions and code using JavaScript template literals. Within these template literals, you have full access to the entity's state object, which allows you to access other properties such as last_changed, attributes.friendly_name, etc. The full set of objects available to your template literals is shown below:

  • entity - the state object for the current entity
  • entities - the state objects for all entities
  • hass - the hass object
  • config - the floorplan configuration
        - name: Sensors
          entities:
             - sensor.melbourne_now
          text_template: '${entity.state ? entity.state : "unknown"}'
          class_template: '
            var temp = parseFloat(entity.state.replace("°", ""));
            if (temp < 10)
              return "temp-low";
            else if (temp < 30)
              return "temp-medium";
            else
              return "temp-high";
            '

Triggering actions

Within each group, you can define an action that triggers a call to the specified Home Assistant service when an entity is clicked. The domain is optional, and defaults to either the domain of the entity being clicked (for regular entities, i.e. 'light'), or to 'homeassistant' (for Home Assistant group entities).

In its simplest form, an action can be used to toggle an enity (or a group of entities, in the case of a Home assistant group).

           action:
            service: toggle

You can also explictly set the domain if you want to call a service from a particular domain.

          action:
            domain: homeassistant
            service: toggle

The ability to specify a domain means you can kick off just about any service available in Home Assistant (scripts, automations, notifcations, shell commands, TTS, etc.).

          action:
            domain: script
            service: sound_frontdoor_chime

For services that support additional data, you can include that as well. Below is an example of setting the transition and brightness when switching on a light.

          action:
            domain: light
            service: turn_on
            data:
              transition: 50
              brightness: 75

When an entity is clicked, it can actually trigger an action on another entity. The example below shows how clicking on a light triggers a different light to be switched on, by supplying the other's light's entity_id as part of the action.

          action:
            domain: light
            service: turn_on
            data:
              entity_id: light.some_other_light
              transition: 50
              brightness: 75

For more flexibility, you can use the data_template to dynamically generate data required for your action. The example below shows how a JSON object is dynamically created and populated with data. Thanks to template literals, you can inject code to evaluate expressions at runtime. Just for the purposes of illustration, the example shows the use of the JavaScript Math.min() function being used in conjunction with another entity's current state.

         action:
           domain: light
           service: turn_on
           data_template: '
             {
               "entity_id": "light.some_other_light",
               "brightness": ${Math.min(entities["zone.home"].attributes.radius, 50)}
             }
             '

Troubleshooting

First of all, check the indentation of the floorplan config. All the examples above show the correct level of indentantion, so make sure that's done before proceedeing further.

The recommended web browser to use is Google Chrome. Pressing F12 displays the Developer Tools. When you press F5 to reload your floorplan page, the Console pane will show any errors that may have occurred. Also check the Network tab to see if any of the scripts failed to load. Ad-blockers have been known to prevent some scripts from loading.

If you're not seeing latest changes that you've made, try clearing the web browser cache. This can also be done in the Chrome Developer Tools. Select the Network tab, right click and select Clear browser cache.

If you're not able to access the floorplan in your web browswer at all, it could be that you've been locked out of Home Assistant due to too many failed login attempts. Check the file ip_bans.yaml in the root Home Assistant config directory and remove your IP address if it's in there.

If you encounter any issues with your entities not appearing, or not correctly showing state changes, firstly make sure that warnings: is added to your floorplan config. It will report any SVG elements that are missing, misspelt, etc.

If you're adding your own CSS classes for styling your entities, make sure you escape the dot character in the id, by prefixing it with a backlash:

#light\.hallway:hover {
}

Resources

Check out Patrik's tutorial on how to create a custom floorplan SVG

More information

For discussions and more information, check out the thread on the Home Assistant forums.

ha-floorplan's People

Contributors

balloob avatar cribbstechnologies avatar djryan012 avatar klikini avatar marcjenningsuk avatar oblogic7 avatar pkozul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ha-floorplan's Issues

Floorplan shows OFF on HA frontend

I followed your steps so far and do get an OFF statement on the Floorplan
image
What have I done wrong, what did I missed?

Furthermore: in the configuration file of HA I have this:
customize: !include_dir_merge_named customizations
!include customize.yaml

Is this correct? Will this work?

can't work with a zigbee switch without zero line,

thank you for you ha-floorplan. but i have a problem here.
i have a switch without N,only L, it is control by an gateway using zigbee.
but the switch without N will work sleep work sleep and go on,so it has high timeouts,it's a technical problem,and can't be solved.
in the floorplan when i touch the icon only one time.the switch will turn on,turn off,many times,i don't know why.because it's high timeouts?
in HA and homekit it work good,because i will not click the switch very quick。
I have try a switch with N,and control by same gateway using zigbee. it's work very good.
can you help me to fix it? sorry for my trouble English.

panel custom

I get a card saying that the panel_custom component could not be set up.
Anyone know how to fix this?

my panel_custom.yaml:

  - name: floorplan
    sidebar_title: Floorplan
    sidebar_icon: mdi:home
    url_path: floorplan
    config: !include floorplan.yaml

Small howtow

Can you please write a small installation howto?

Thanks,
Frank

about ipad can't work

now I know ,floorplan can‘t work in IOS(ipad iphone),but my Android MB can't work ; I want to know :windows pad Support it?

Touch screen input - can it be debounced?

In some instances, using floorplan on a touchscreen device double-fires the service action. Is it possible to add some debounce logic to the click handler with a configurable debounce time?

stopPropagation does not work on 0.65

After upgrading to 0.65, stopPropagation stopped working when using the state card and clicking on anything on the state card opens the more-info dialog instead of performing the action. Once the more-info dialog is open you then need to click on the entitiy within the svg.

I found the following changes worked for me to change it back to the way it usually works:

diff --git a/www/custom_ui/floorplan/ha-floorplan.html b/www/custom_ui/floorplan/ha-floorplan.html
index 8646f91..ff24732 100644
--- a/www/custom_ui/floorplan/ha-floorplan.html
+++ b/www/custom_ui/floorplan/ha-floorplan.html
@@ -59,7 +59,7 @@
       <ul></ul>
     </div>

-    <div id="floorplan" on-tap="stopPropagation"></div>
+    <div id="floorplan"></div>

   </template>

@@ -781,6 +781,7 @@
       else {
         this.instance.fire('hass-more-info', { entityId: entityId });
       }
+      e.stopPropagation();
     },

     getFill(stateConfig) {

Happy to create a PR, but they don't seem to be getting merged and I'll just conflict with the other PRs

getStroke is not a function

I've got my floor plan displaying in HA, but am having a problem when an entity's state is changed. Any ideas what would cause this issue?

Uncaught TypeError: this.getStroke is not a function
    at HTMLElement.setEntityStyle (ha-floorplan.html:480)
    at HTMLElement.handleEntities (ha-floorplan.html:323)
    at Array.window.HAWS.subscribeEntities.entities (ha-floorplan.html:99)
    at Object.r [as eventCallback] (core-d4a7cb8….js:1)
    at S._handleMessage (core-d4a7cb8….js:1)

statecard

I got a weird issue:
in home assistant my hikvision sensor gets name floorplan in ui
floorplanissue

but in devices they are named

binary_sensor.ip_camera_disk_error | off | last_tripped_time: 2018-06-28T19:57:40.404250 friendly_name: Floorplan Disk Error
-- | -- | --
binary_sensor.ip_camera_disk_full | off | last_tripped_time: 2018-06-28T19:57:40.404234 friendly_name: Floorplan Disk Full
binary_sensor.ip_camera_field_detection | off | last_tripped_time: 2018-06-28T19:57:40.404300 friendly_name: Floorplan Field Detection device_class: motion
binary_sensor.ip_camera_illegal_access | off | last_tripped_time: 2018-06-28T19:57:40.404266 friendly_name: Floorplan Illegal Access
binary_sensor.ip_camera_line_crossing | off | last_tripped_time: 2018-06-28T19:57:40.404282 friendly_name: Floorplan Line Crossing device_class: motion
binary_sensor.ip_camera_motion

And the state card doesnt show up.
from my config files:
binary_sensor.yaml:
platform: mqtt
state_topic: dummy/floorplan/sensor
name: Floorplan

customize.yaml:
binary_sensor.floorplan:
custom_ui_state_card: state-card-floorplan
config: !include floorplan.yaml

frontend:
extra_html_url:

  • /local/custom_ui/state-card-floorplan.html

panel_custom.yaml:

  • name: floorplan
    sidebar_title: Floorplan
    sidebar_icon: mdi:home
    url_path: floorplan
    config: !include floorplan.yaml

I cant figure this one out.. Floorplan works from the sidebar..

Ability to add camera image to the Floorplan homepage

I tried to use the image_template but it seems that is expecting an SVG. It would be great to have maybe a camera_template that could use entitiy.attributes.entity_picture to display the current thumbnail image like in HASS.

image

hass.callService called multiple times

Hi,

image

When I add a console.log to onEntityClick, right before callService, it is being logged twice.

image

I think the click event should not be added for every child element, but only on the main element

$(svgElement).on('click', this.instance.onEntityClick.bind({ instance: this.instance, entityId: entityId }));

for (svgElementId in entityConfig.svgElementConfigs) {

This also fixed a flickering I had with my philips hue bulbs because it spammed the hue hub due to multiple calls.

Refresh Camera image

Hi

Just adding this request as we discussed in PM @pkozul

Would be great with the camera images feed in the rect refresh every few seconds just like the camera feed does in HA frontend.
At the moment the camera feed only gets refreshed when you reload the page and sometimes its hours or days in the past.

thanks

A bug in click 'Floorplan custom state card' item in 'Floorplan custom panel'

I created three Floorplan custom state cards and a Floorplan custom panel
image
image

I introduced the Floorplan custom state card virtual binary sensor on the Floorplan custom panel
image

When I first click on 'binary_sensor.central_stations', the sensor information pops up correctly, but when I click on the other 'binary_sensor. *', It just pops up the message 'binary_sensor.central_stations'

11 0

Card View works on browser but not on Android

I have a set up that works perfectly in Chrome browser (Windows) in both the panel and card view. Note: I had to put the dummy binary sensor in a group to get it to show up as per other threads on here,

However, on my android phone (in both chrome and firefox), whilst the panel floorplan works fine, the card view just displays the group name (Downstairs) and when you click on it you get a toggle switch to turn the group on which does nothing.

I have noted an error "Unable to find service binary_sensor/turn_on" but can't figure out how to resolve it and suspect that is the cause.

Any ideas about the above or where else to start looking?

Desktop Chrome:
capture

Android Chrome:
ink 1

And when clicked:
ink 2

Disabling tooltip for a given group

Hi,

I came across the case where I wish I could disable the tooltip on a group, because this one is only used to display a background for other entities which are used to manage actions through scripts.

Do you have an option for this kind of use case?

Thanks

NEW Feature : Dynamic Weather Icons!

@pkozul - Let's create an issue and just close it to note the new features or enhancements you make to the Floorplan. This could be a great place for people to see and note the new things in the program until a more proper versioning is worked out.


Getting back to your idea about integrating the Dark Sky icons (Skycons). That looked promising, but I then noticed the positioning was out of whack on different devices, and even on different laptops, and Chrome was used in all cases. Ended up abandoning that idea. I don't think there is good browser support for embedding non-SVG stuff (i.e. HTML5 canvas) into SVGs. Too bad Skycons aren't available as SVG (from what I could see anyway).

Not all is lost though. I manged to get dynamic SVG images working in the floorplan. To test it, I found an alternative source for animated weather icons, and they are in SVG format:

amcharts.com
https://www.amcharts.com/free-animated-svg-weather-icons/

Free animated SVG weather icons - amCharts

We’re all about beautiful vector stuff here at amCharts. That’s why we felt compelled to create our own, how-grown and nurtured icons for our weather demos and especially Weather Map tool. We also want you to use them in your projects as well. Free....
I tried on several browsers, on different devices and it seems to work well. The only catch is that they don't animate in the Microsoft Edge browser. I read some posts about this not being supported, but still need to look further into this. Not a problem - the icons are still there :slight_smile:

The latest code on GitHub has been updated to support this. It was a relatively simple change is and is totally non-intrusive. The new functionality only kicks in if you add the relevant option in your floorplan config.

Below is an example of how to use it. As you can see, there is a new section image_template that lets you write some rules around which image should be displayed based on the state of your entity. In this example, my entity is a Dark Sky weather sensor that I added in HA. Of course, I had to create the associated element in the SVG file, which I simply implemented as a `rect, as it's only purpose is to serve as a placeholder (bounding box for the image being loaded). The dynamic image gets scaled to fit exactly within the SVG element.

      groups:

        - name: Dark Sky Sensors
          entities:
            - sensor.melbourne_dark_sky_icon
          image_template: '
            var imageName = "";

            switch (entity.state) {
              case "clear-day":
                imageName = "day";
                break;

              case "clear-night":
                imageName = "night";
                break;

              case "partly-cloudy-day":
                imageName = "cloudy-day-1";
                break;

              case "partly-cloudy-night":
                imageName = "cloudy-night-1";
                break;

              case "cloudy":
                imageName = "cloudy";
                break;

              case "rain":
                imageName = "rainy-1";
                break;

              case "snow":
                imageName = "snowy-1";
                break;
            }

            return "/local/custom_ui/floorplan/images/weather/" + imageName + ".svg";
            '

One thing I found with the weather icons I mentioned above, is that the weather SVG files had the wrong case for the viewBox attribute. It was originally all lower case, but the B is supposed to be upper case. I changed it in all the files, and that allowed the image to resize properly.

<svg
version="1.1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="64"
height="64"
viewBox="0 0 64 64">

BTW, this is actually a very powerful new feature. It means we finally have the ability to use dynamic images, with the ability to swap out different images based on the states of our entities.

disable system popup/notifications

every time I turn on a light or any other device I get that pop up in the bottom left corner, is there a way to disable or hide that?

Script action doesn't work in element group

This yaml:

- name: Garage Toggles
  elements:
    - garage_label
    - garage_area
  action:
    domain: script
    service: toggle_garage_door

results in this error:
Uncaught TypeError: Cannot read property 'elements' of undefined
URL: http://192.168.1.8:8123/local/custom_ui/floorplan/ha-floorplan.html
Line: 241, column: 46
Error: {}

The fix is pretty simple -- just add another check to the if statement on that line so it becomes:
if (elementGroup.action.data && elementGroup.action.data.elements) {

more than on floorplan?

Hello,

does someone has an example of how to have more than one floorplan? I've been trying to set that up but... no luck.

thanks

Multiple Binds

I have a problem that switches would turn off and then right back on. I tracked it down to the click event was being assigned multiple times because my switches are groups of object and each object was getting a click bind.

I'm not sure why each item needs to go through this loop but I fixed my issue with a simple condition to check if the bind has already happened. You might have a better solution though since you understand the code better.

` var alreadyBound = false;
for (svgElementId in entityConfig.svgElementConfigs) {
let svgElementConfig = entityConfig.svgElementConfigs[svgElementId];

            let svgElement = $(svgElementConfig.svgElement);

            // Create a title element (to support hover over text)
            svgElement.append(document.createElementNS('http://www.w3.org/2000/svg', 'title'));

            if (svgElement.length) {
              svgElementConfig.svgElement = svgElement[0];

              if (!alreadyBound){
                $(svgElement).on('click', this.instance.onEntityClick.bind({ instance: this.instance, entityId: entityId }));
                alreadyBound = true;
              }`

$(svgElement).on('click', this.instance.onEntityClick.bind({ instance: this.instance, entityId: entityId }));

state-card-floorplan does not show, only sensor

I think others have experienced same issue, but their solutions do not work for me. My custom floorplan works brilliantly as a side menu item. I even got my tv remote scripts to work without issues.

However, as a state-card it only shows the dummy floorplan mqtt sensor. When I click the sensor I get to see the floorplan on my mac, including a series of config items from the floorplan.yaml file (see enclosed 2nd picture). When I click on the sensor on my iPhone I get the floorplan, without error messages. I used the standard setup, including all the suggested yaml files and the other files in the right location. Is there anyone who experienced the same issue and who has resolved it?
Of course I'd like to show the floorplan immediately, without clicking the dummy sensor. Any suggestions are very much appreciated!! @pkozul , do you perhaps have suggestion?

screen shot 2018-03-30 at 15 11 07
screen shot 2018-03-30 at 15 11 17

Uncaught TypeError: Polymer.dom is not a function

Hi,

i get an error (after updating Home assistant to 0.70.1), floorplan does not show up.
The error appears on chrome.

On MS Edge and my Sony Xperia XZ (Android 8.0.0) - the floorplan is shown and it looks like there are no errors in the log.

Error:
/local/custom_ui/floorplan/ha-floorplan.html:375:25 Uncaught TypeError: Polymer.dom is not a function

Floorplan from GIT Repo 02.06.2018

How would i toggle a group all-off/all-on?

At the moment i have a bunch of lights in one room, which is the group.

      groups:
        - name: Lights
          entities:
             - light.tafel
             - light.staanlamp
             - light.bureau
             - light.plafond
             - light.ganglicht
          states:
            - state: 'on'
              class: 'light-on'
            - state: 'off'
              class: 'light-off'
          action:
            domain: homeassistant   # This optional parameter allows you to use other services such as homeassistant.toggle like here.
            service: toggle
        - name: Rooms
          entities:
            - group.lightgroup_living
            - group.lightgroup_eetkamer
            - group.lightgroup_gang
          states:
            - state: 'on'
              class: 'room-on'
            - state: 'off'
              class: 'room-off'
          action:
            domain: homeassistant
            service: toggle

When 1 light is on and one light is off in a group, when using toggle --> the one goes off and the other will turn on.
with service: turn_off it only turns off.

How can it be turned on/off?

script not found 404

hi im getting a :

webcomponents-lite.js.map
Failed to load resource: the server responded with a status of 404 (Not Found)

but i don't see the file any where in the git.

Multiple floorplan problem

Dear all,

I use many floorplan tab with HAAS named "floorplan" and "groundfloor".

After a visualization of the first floorplan, there is a bug to display the second.
I need to refreNothing apear and I need to use CTRL+F5 to have a result.

System log :
Log Details (ERROR)
Fri Nov 02 2018 17:56:37 GMT+0100 (heure normale d’Europe centrale)
http://192.168.1.9:8123/api/panel_custom/groundfloor:42:9 Uncaught SyntaxError: Identifier 'HaPanelFloorplan' has already been declared

My configuration :

/config/configuration.yaml

# Enables the frontend
frontend:
  extra_html_url:
    - /local/custom_ui/state-card-floorplan.html

binary_sensor:
  - platform: mqtt
    state_topic: dummy/floorplan/sensor
    name: Floorplan
  - platform: mqtt
    state_topic: dummy/floorplan/sensor
    name: Groundfloor 

/config/groups.yaml

floorplan:
   - name: Floorplan
     entities:
     - binary_sensor.floorplan
     - binary_sensor.groundfloor

/config/panel_custom.yaml


  - name: floorplan
    sidebar_title: Rez-de-chaussée
    sidebar_icon: mdi:home
    url_path: floorplan
    config: !include floorplan.yaml
    
  - name: groundfloor
    sidebar_title: Sous-sol
    sidebar_icon: mdi:home
    url_path: groundfloor
    config: !include groundfloor.yaml

Could you please help me to solve this bug ?
Thx by advance.
Nicolas

No map displayed

I am deeply sorry to have to bother others, but I have spent hours rechecking my configuration and Googling to understand the custom-ui's of HASS. Still I have no luck.

My "state card" has the circle icon, nothing more. Definitely no map.
Nothing of interesting in the developer's console, or in HASS's logs.

If I enable the custom panel I just get a loading animation for that panel.
I do get a 404 for the CSS in the developer's console though. But I can not figure out why.
EDIT: This actually works now, not sure what I did or why. I would prefer the state card though, which still doesn't work.

The relevant parts of my configs are available in this pastebin, so is the relevant directory listings.
https://pastebin.com/ZHU8SgJX
All files are readable by the user homeassistant.
It's not very well described where to put those files from git, but as I understand it, it should be in the configuration directory, and this is where my yaml files are stored, as shown in the paste.

My HASS is installed according to https://home-assistant.io/docs/installation/virtualenv/

floormap not showing

Hi!

Thanks for a great write-up. I followed your tutorial, but the actual image is not showing up. I just see a generic circle, with a black circle inside.

When I hit the circle, it shows status as off and the following text:

{ "name": "Demo Floorplan", "image": "/local/custom_ui/floorplan/floorplan.svg", "stylesheet": "/local/custom_ui/floorplan/floorplan.css" }

Floorplan ui not clickable

Hello,

Since hass 0.50.x, floorplan items are not clickable. I tried on both ios 10.2 and ios 11 as well as kindle fire os 5.4.
Everything works on desktop pc.

SVG weather icon shows below the floorplan

Hi Pkozul, I have found an issue where the weather icon loads according to the code based on the sensor.darksky_icon but the image displays way below the whole floorplan rather than in the rect I’ve created for it. I can confirm my code behind the svg has “viewBox” and not “viewbox” , and “0 0 64 64” as suggested in other posts but still showing the icon in the wrong place. Seems to be aligned vertically but not horizontally.
The svg icons come from ammap.com as suggested yourself. Thanks

Floorplan actions are not clickable

Hello,

I am unable to click to the most icons/actions on my floorplan - Any hints about that behaviour?

Lights config:

groups:
  - name: lights
    entities:
      - light.livingroom_ceilinglight
      - light.bedroom_ceilinglight
      - light.bathroom_ceilinglight
      - light.childrenroom_ceilinglight
      - light.kitchen_ceilinglight
      - light.wc_ceilinglight
      - light.kitchen_led
      - light.gateway_light_286c0788b78a
      - light.bedroom_bedsidelamp_tom
      - light.bedroom_bedsidelamp_judith
      - light.balkony
    states:
      - state: 'on'
        class: 'light-on'
      - state: 'off'
        class: 'light-off'
    action:
      domain: light
service: toggle

Windows-config:

  - name: windows
    entities:
      - binary_sensor.livingroom_climate_windowshutter
      - binary_sensor.bedroom_climate_windowshutter
      - binary_sensor.childrenroom_climate_windowshutter
      - binary_sensor.wc_climate_windowshutter
      - binary_sensor.kitchen_climate_windowshutter
      - binary_sensor.frontdoor_windowshutter
    states:
      - state: 'on'
        class: 'window-on'
      - state: 'off'
class: 'window-off'

In examples all lights are not clickable - Example of a light:

    <g
       style="display:inline;fill:#808080"
       id="light.bathroom_ceilinglight"
       transform="matrix(0.43596735,0,0,0.43596735,341.66152,-137.02364)"
       inkscape:label="">

All windows are hoverable/clickable (they have no actions):

    <g
       transform="matrix(0.26449636,0,0,0.28324627,-2452.0094,2059.0055)"
       style="display:inline"
       id="binary_sensor.kitchen_climate_windowshutter"
       inkscape:label="">

The states seems to be working without any issues on the floorplan.

Thankful for every hint!

duplicate floorplans

not sure how much detail is needed but main floorplan community thread has most of it.
Seems related to state-card more than panel?
3.6.3
0.63 HA

let me know if you need any extra info

Safari script error in HA 0.51.1

After updating HA to version 0.51.1 floorplan gives a script error in Safari on both mac and ipad. Chrome on the mac works but chrome on ipad doesn't. This might be related to latest changes in the frontend and polymer 2?

state_transitions are not optional as documented

Documentation states that state_transitions are optional, but in my testing, they do not appear to be. When that section of the config is omitted, the transition does not happen at all. Additionally, setting a transition time of 0 does not result in an instant transition.

state-card-floorplan shows floorplan multiple times

Every time I leave the states page to go to another page such as the developer console, when I go back to states page, there is another floorplan added to the card. I have seen three or more floorplans in the card. All of the floorpans work just fine. Using the latest code from this site with no changes except the normal configuration items.
I am using latest Safari.

License

What is the license for this project?

Uncaught TypeError: Class constructor HaPanelFloorplan cannot be invoked without 'new'

I am running MagicMirror2 on a raspberry pi. I have an iFrame pointed at https://REDACTED.duckdns.org:8123/floorplan and it used to display my floorplan, but now I do not see anything and I am getting the following error when I check my systemlog and attempt a reload of the mirror.

ERROR (MainThread) [frontend.js.es5.201806080b0] https://REDACTED.duckdns.org:8123/static/custom-elements-es5-adapter.js:1:11 Uncaught TypeError: Class constructor HaPanelFloorplan cannot be invoked without 'new'

Error after install

Upon following the install guide, opening the Floorplan tab gives me the following error:
URIError: http://192.168.1.5:8123/local/custom_ui/floorplan/lib/floorplan.js?_=1519050233960

Multiple Floorplan Polymer/Javascript errors

I have multiple floor plans set up as panels for my HASS 0.83.1 running on Centos. Upon initial login I can see EACH of the floorplans. However, after viewing ANY of the floorplans, attempting to view any of the OTHER floorplan panel causes a failure with the following polymer message in the logs:


2018-12-02 09:49:14 ERROR (MainThread) [frontend.js.latest.201811211] data:text/javascript;charset=utf-8,%0A%20%20class%20HaPanelFloorplan%20
extends%20Polymer.Element%20%7B%0A%20%20%20%20static%20get%20is()%20%7B%20return%20'ha-panel-upperfloorplan'%3B%20%7D%0A%0A%20%20%20%20static
%20get%20properties()%20%7B%0A%20%20%20%20%20%20return%20%7B%0A%20%20%20%20%20%20%20%20hass%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20type%3A%
20Object%2C%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20narrow%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20type%3A%20Boolean%2C%0
A%20%20%20%20%20%20%20%20%20%20value%3A%20false%2C%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20showMenu%3A%20%7B%0A%20%20%20%2
0%20%20%20%20%20%20type%3A%20Boolean%2C%0A%20%20%20%20%20%20%20%20%20%20value%3A%20true%2C%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20
%20%20%20showAppToolbar%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20type%3A%20Boolean%2C%0A%20%20%20%20%20%20%20%20%20%20value%3A%20false%2C%0A%
20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20panel%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20type%3A%20Object%2C%0A%20%20%20%20%20%
20%20%20%20%20observer%3A%20'panelChanged'%2C%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20containerClass%3A%20%7B%0A%20%20%20%
20%20%20%20%20%20%20type%3A%20String%2C%0A%20%20%20%20%20%20%20%20%20%20value%3A%20'container-fullscreen'%2C%0A%20%20%20%20%20%20%20%20%7D%2C
%0A%20%20%20%20%20%20%7D%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20panelChanged()%20%7B%0A%20%20%20%20%20%20var%20hideAppToolbar%20%3D%20((this.p
anel.config.hide_app_toolbar%20%3D%3D%3D%20null)%20%7C%7C%20(this.panel.config.hide_app_toolbar%20!%3D%3D%20undefined))%3B%0A%20%20%20%20%20%
20this.showAppToolbar%20%3D%20!hideAppToolbar%3B%0A%20%20%20%20%20%20this.containerClass%20%3D%20this.showAppToolbar%20%3F%20'container-with-
toolbar'%20%3A%20'container-fullscreen'%3B%0A%20%20%20%20%7D%0A%20%20%7D%0A%0A%20%20customElements.define(HaPanelFloorplan.is%2C%20HaPanelFlo
orplan)%3B%0A%0A%0A%2F%2F%23%20sourceURL%3Dhttps%3A%2F%2F192.168.199.xxx%3A8123%2Fapi%2Fpanel_custom%2Fupperfloorplan.js%0A:0:0 Script error.

I've followed the instructions at (https://community.home-assistant.io/t/floorplan-for-home-assistant/17394/302)

I can confirm that this issue is consistent in Firefox and Chrome. Is this a known issue? Workarounds?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.