Files
.github
.themes
_deploy
credits_generator
plugins
sass
source
_addons
_components
_cookbook
_data
_docs
_faq
_includes
_layouts
_posts
addons
assets
blog
cloud
code_of_conduct
components
cookbook
demo
developers
documentation
hassio
intent
internationalization
add_new_platform.markdown
api.markdown
architecture.markdown
architecture_components.markdown
asyncio.markdown
asyncio_101.markdown
asyncio_categorizing_functions.markdown
asyncio_misc.markdown
asyncio_working_with_async.markdown
cla.markdown
cla_sign.html
cla_sign_start.html
code_review_component.markdown
code_review_platform.markdown
component_deps_and_reqs.markdown
component_discovery.markdown
component_events.markdown
component_generic_discovery.markdown
component_loading.markdown
component_states.markdown
component_visibility.markdown
creating_components.markdown
credits.markdown
development.markdown
development_101.markdown
development_catching_up.markdown
development_checklist.markdown
development_config.markdown
development_environment.markdown
development_events.markdown
development_guidelines.markdown
development_hass_object.markdown
development_services.markdown
development_states.markdown
development_submitting.markdown
development_testing.markdown
development_validation.markdown
frontend.markdown
frontend_add_card.markdown
frontend_add_more_info.markdown
frontend_creating_custom_panels.markdown
frontend_creating_custom_ui.markdown
helpers.markdown
index.markdown
license.markdown
maintenance.markdown
multiple_instances.markdown
platform_example_light.markdown
platform_example_sensor.markdown
python_api.markdown
releasing.markdown
rest_api.markdown
server_sent_events.markdown
websocket_api.markdown
docs
faq
font
getting-started
hassio
help
images
javascripts
privacy
static
tos
CNAME
atom.xml
favicon.png
googlef4f3693c209fe788.html
index.html
robots.txt
service_worker.js
version.json
.editorconfig
.gitattributes
.gitignore
.gitmodules
.powrc
.project
.ruby-version
.slugignore
.travis.yml
CLA.md
CODE_OF_CONDUCT.md
Gemfile
Gemfile.lock
LICENSE.md
README.markdown
Rakefile
_config.yml
config.rb
config.ru
home-assistant.io/source/developers/frontend_creating_custom_panels.markdown
2017-12-02 10:49:19 -08:00

2.9 KiB

layout, title, description, date, sidebar, comments, sharing, footer
layout title description date sidebar comments sharing footer
page Creating custom panels Introduction to create custom panels for Home Assistant. 2016-07-29 13:00 true false true true

Panels are pages within Home Assistant that show information within Home Assistant and can allow controlling it. Panels are linked from the sidebar and rendered full screen. The have have real-time access to the Home Assistant object via JavaScript. Examples of panels in the app are map, logbook and history.

Besides components registering panels, users can also register panels using the panel_custom component. This allows users to quickly build their own custom interfaces for Home Assistant.

{% linkable_title Before you get started %}

The Home Assistant user interface is currently served to browsers in modern JavaScript and older JavaScript (ES5). The older version has a wider browser support but that comes at a cost of size, performance and more difficult to get started building panels for authors.

We therefore advice to set up the frontend to serve the modern version of the frontend so that you won't need any build tools while developing. If you realize that your audience requires both, you can add a transpilation step in the future. To set up your frontend to always serve the latest version, add this to your config:

frontend:
  javascript_version: latest

{% linkable_title Building your first panel %}

Create a file called hello.html in your /panels/.

The hello.html contains the needed building blocks to create the elements inside the view.

<dom-module id='ha-panel-hello'>
  <template>
    <style>
      p {
        font-weight: bold;
      }
    </style>
    <p>Hello {% raw %}{{who}}{% endraw %}. Greetings from Home Assistant.</p>
  </template>
</dom-module>

<script>
class HaPanelHello extends Polymer.Element {
  static get is() { return 'ha-panel-hello'; }
  
  static get properties() {
    return {
      // Home Assistant object
      hass: Object,
      // If should render in narrow mode
      narrow: {
        type: Boolean,
        value: false,
      },
      // If sidebar is currently shown
      showMenu: {
        type: Boolean,
        value: false,
      },
      // Home Assistant panel info
      // panel.config contains config passed to register_panel serverside
      panel: Object,
      who: {
        type: String,
        computed: 'computeWho(panel)',
      },
    };
  }

  computeWho(panel) {
    return panel && panel.config && panel.config.who ? panel.config.who : 'World';
  }
}
customElements.define(HaPanelHello.is, HaPanelHello);
</script>

Create an entry for the new panel in your configuration.yaml file:

panel_custom:
  - name: hello
    sidebar_title: Hello World
    sidebar_icon: mdi:hand-pointing-right
    url_path: hello

For more possibilities, see the Custom panel section on our Examples page.