Site updated at 2017-02-23 10:14:06 UTC
This commit is contained in:
parent
f402a25638
commit
ac0a1f4c4f
932 changed files with 1599 additions and 29010 deletions
|
@ -1,298 +0,0 @@
|
|||
<!doctype html>
|
||||
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
|
||||
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
|
||||
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
|
||||
<!--[if gt IE 8]><!--> <html> <!--<![endif]-->
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Events - Home Assistant</title>
|
||||
<meta name="author" content="Home Assistant">
|
||||
<meta name="description" content="Describes all there is to know about events in Home Assistant.">
|
||||
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<link rel="canonical" href="https://home-assistant.io/topics/events/">
|
||||
|
||||
<meta property="fb:app_id" content="338291289691179">
|
||||
<meta property="og:title" content="Events">
|
||||
<meta property="og:site_name" content="Home Assistant">
|
||||
<meta property="og:url" content="https://home-assistant.io/topics/events/">
|
||||
<meta property="og:type" content="article">
|
||||
<meta property="og:description" content="Describes all there is to know about events in Home Assistant.">
|
||||
<meta property="og:image" content="https://home-assistant.io/images/default-social.png">
|
||||
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:site" content="@home_assistant">
|
||||
|
||||
<meta name="twitter:title" content="Events">
|
||||
<meta name="twitter:description" content="Describes all there is to know about events in Home Assistant.">
|
||||
<meta name="twitter:image" content="https://home-assistant.io/images/default-social.png">
|
||||
|
||||
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet">
|
||||
<link href="/atom.xml" rel="alternate" title="Home Assistant" type="application/atom+xml">
|
||||
<link rel='shortcut icon' href='/images/favicon.ico' />
|
||||
<link rel='icon' type='image/png' href='/images/favicon-192x192.png' sizes='192x192' />
|
||||
</head>
|
||||
|
||||
<body >
|
||||
|
||||
<header>
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid">
|
||||
|
||||
<div class="grid__item three-tenths lap-two-sixths palm-one-whole ha-title">
|
||||
<a href="/" class="site-title">
|
||||
<img width='40' src='/demo/favicon-192x192.png'>
|
||||
<span>Home Assistant</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="grid__item seven-tenths lap-four-sixths palm-one-whole">
|
||||
<nav>
|
||||
<input type="checkbox" id="toggle">
|
||||
<label for="toggle" class="toggle" data-open="Main Menu" data-close="Close Menu"></label>
|
||||
<ul class="menu pull-right">
|
||||
|
||||
<li><a href="/getting-started/">Getting started</a></li>
|
||||
<li><a href="/components/">Components</a></li>
|
||||
<li><a href="/ecosystem/">Ecosystem</a></li>
|
||||
<li><a href="/cookbook/">Examples</a></li>
|
||||
<li><a href="/developers/">Developers</a></li>
|
||||
<li><a href="/blog/">Blog</a></li>
|
||||
<li><a href="/help/">Need help?</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
|
||||
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid grid-center">
|
||||
|
||||
<div class="grid__item two-thirds lap-one-whole palm-one-whole">
|
||||
|
||||
|
||||
<article class="page">
|
||||
|
||||
|
||||
<div class='edit-github'><a href='https://github.com/home-assistant/home-assistant.github.io/tree/current/source/_topics/events.markdown'>Edit this page on GitHub</a></div>
|
||||
|
||||
|
||||
|
||||
<header>
|
||||
<h1 class="title indent">
|
||||
Events
|
||||
</h1>
|
||||
</header>
|
||||
<hr class="divider">
|
||||
|
||||
|
||||
<p>The core of Home Assistant is the event bus. The event bus allows any component to fire or listen for events. It is the core of everything. For example, any state change will be announced on the event bus as a <code class="highlighter-rouge">state_changed</code> event containing the previous and the new state of an entity.</p>
|
||||
|
||||
<p>Home Assistant contains a few built-in events that are used to coordinate between various components.</p>
|
||||
|
||||
<h3><a class="title-link" name="event-homeassistant_start" href="#event-homeassistant_start"></a> Event <code class="highlighter-rouge">homeassistant_start</code></h3>
|
||||
<p>Event <code class="highlighter-rouge">homeassistant_start</code> is fired when all components from the configuration have been intitialized. This is the event that will start the timer firing off <code class="highlighter-rouge">time_changed</code> events.</p>
|
||||
|
||||
<h3><a class="title-link" name="event-homeassistant_stop" href="#event-homeassistant_stop"></a> Event <code class="highlighter-rouge">homeassistant_stop</code></h3>
|
||||
<p>Event <code class="highlighter-rouge">homeassistant_stop</code> is fired when Home Assistant is shutting down. It should be used to close any open connection or release any resources.</p>
|
||||
|
||||
<h3><a class="title-link" name="event-state_changed" href="#event-state_changed"></a> Event <code class="highlighter-rouge">state_changed</code></h3>
|
||||
<p>Event <code class="highlighter-rouge">state_changed</code> is fired when a state changes. Both <code class="highlighter-rouge">old_state</code> and <code class="highlighter-rouge">new_state</code> are state objects. <a href="/topics/state_object/">Documentation about state objects.</a></p>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Field</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><code class="highlighter-rouge">entity_id</code></td>
|
||||
<td>Entity ID of the changed entity. Example: <code class="highlighter-rouge">light.kitchen</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code class="highlighter-rouge">old_state</code></td>
|
||||
<td>The previous state of the entity before it changed. This field is ommitted if the entity is new.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code class="highlighter-rouge">new_state</code></td>
|
||||
<td>The new state of the entity. This field is ommitted if the entity is removed from the state machine.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h3><a class="title-link" name="event-time_changed" href="#event-time_changed"></a> Event <code class="highlighter-rouge">time_changed</code></h3>
|
||||
<p>Event <code class="highlighter-rouge">time_changed</code> is fired every second by the timer and contains the current time.</p>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Field</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><code class="highlighter-rouge">now</code></td>
|
||||
<td>A <a href="https://docs.python.org/3.4/library/datetime.html#datetime.datetime">datetime object</a> containing the current time in UTC.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h3><a class="title-link" name="event-service_registered" href="#event-service_registered"></a> Event <code class="highlighter-rouge">service_registered</code></h3>
|
||||
<p>Event <code class="highlighter-rouge">service_registered</code> is fired when a new service has been registered within Home Assistant.</p>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Field</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><code class="highlighter-rouge">domain</code></td>
|
||||
<td>Domain of the service. Example: <code class="highlighter-rouge">light</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code class="highlighter-rouge">service</code></td>
|
||||
<td>The service to call. Example: <code class="highlighter-rouge">turn_on</code></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h3><a class="title-link" name="event-call_service" href="#event-call_service"></a> Event <code class="highlighter-rouge">call_service</code></h3>
|
||||
<p>Event <code class="highlighter-rouge">call_service</code> is fired to call a service.</p>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Field</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><code class="highlighter-rouge">domain</code></td>
|
||||
<td>Domain of the service. Example: <code class="highlighter-rouge">light</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code class="highlighter-rouge">service</code></td>
|
||||
<td>The service to call. Example: <code class="highlighter-rouge">turn_on</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code class="highlighter-rouge">service_data</code></td>
|
||||
<td>Dictionary with the service call parameters. Example: <code class="highlighter-rouge"><span class="p">{</span><span class="w"> </span><span class="err">'brightness':</span><span class="w"> </span><span class="err">120</span><span class="w"> </span><span class="p">}</span></code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code class="highlighter-rouge">service_call_id</code></td>
|
||||
<td>String with a unique call id. Example: <code class="highlighter-rouge">23123-4</code>.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h3><a class="title-link" name="event-service_executed" href="#event-service_executed"></a> Event <code class="highlighter-rouge">service_executed</code></h3>
|
||||
<p>Event <code class="highlighter-rouge">service_executed</code> is fired by the service handler to indicate the service is done.</p>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Field</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><code class="highlighter-rouge">service_call_id</code></td>
|
||||
<td>String with the unique call id of the service call that was executed. Example: <code class="highlighter-rouge">23123-4</code>.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h3><a class="title-link" name="event-platform_discovered" href="#event-platform_discovered"></a> Event <code class="highlighter-rouge">platform_discovered</code></h3>
|
||||
<p>Event <code class="highlighter-rouge">platform_discovered</code> is fired when a new platform has been discovered by the discovery component.</p>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Field</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><code class="highlighter-rouge">service</code></td>
|
||||
<td>The service that is discovered. Example: <code class="highlighter-rouge">zwave</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code class="highlighter-rouge">discovered</code></td>
|
||||
<td>Information that is discovered. Can be a dict, tuple etc. Example: <code class="highlighter-rouge">(192.168.1.10, 8889)</code>.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h3><a class="title-link" name="event-component_loaded" href="#event-component_loaded"></a> Event <code class="highlighter-rouge">component_loaded</code></h3>
|
||||
<p>Event <code class="highlighter-rouge">component_loaded</code> is fired when a new component has been loaded and initialized.</p>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Field</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><code class="highlighter-rouge">component</code></td>
|
||||
<td>Domain of the component that has just been initialized. Example: <code class="highlighter-rouge">light</code>.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
</article>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer>
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid">
|
||||
<div class="grid__item">
|
||||
<div class="copyright">
|
||||
<a rel="me" href='https://twitter.com/home_assistant'><i class="icon-twitter"></i></a>
|
||||
<a rel="me" href='https://facebook.com/homeassistantio'><i class="icon-facebook"></i></a>
|
||||
<a rel="me" href='https://plus.google.com/110560654828510104551'><i class="icon-google-plus"></i></a>
|
||||
<a rel="me" href='https://github.com/home-assistant/home-assistant'><i class="icon-github"></i></a>
|
||||
|
||||
<div class="credit">
|
||||
Contact us at <a href='mailto:hello@home-assistant.io'>hello@home-assistant.io</a>.<br>
|
||||
Website powered by <a href='http://jekyllrb.com/'>Jekyll</a> and the <a href='https://github.com/coogie/oscailte'>Oscalite theme</a>.<br />
|
||||
Hosted by <a href='https://pages.github.com/'>GitHub</a> and served by <a href='https://cloudflare.com'>CloudFlare</a>.
|
||||
</div>
|
||||
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a><br /><span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">home-assistant.io</span> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
var _gaq=[['_setAccount','UA-57927901-1'],['_trackPageview']];
|
||||
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
|
||||
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
|
||||
s.parentNode.insertBefore(g,s)}(document,'script'));
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,303 +0,0 @@
|
|||
<!doctype html>
|
||||
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
|
||||
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
|
||||
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
|
||||
<!--[if gt IE 8]><!--> <html> <!--<![endif]-->
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Group Visibility - Home Assistant</title>
|
||||
<meta name="author" content="Home Assistant">
|
||||
<meta name="description" content="Instructions how to change group visibility using automations.">
|
||||
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<link rel="canonical" href="https://home-assistant.io/topics/group_visibility/">
|
||||
|
||||
<meta property="fb:app_id" content="338291289691179">
|
||||
<meta property="og:title" content="Group Visibility">
|
||||
<meta property="og:site_name" content="Home Assistant">
|
||||
<meta property="og:url" content="https://home-assistant.io/topics/group_visibility/">
|
||||
<meta property="og:type" content="article">
|
||||
<meta property="og:description" content="Instructions how to change group visibility using automations.">
|
||||
<meta property="og:image" content="https://home-assistant.io/images/default-social.png">
|
||||
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:site" content="@home_assistant">
|
||||
|
||||
<meta name="twitter:title" content="Group Visibility">
|
||||
<meta name="twitter:description" content="Instructions how to change group visibility using automations.">
|
||||
<meta name="twitter:image" content="https://home-assistant.io/images/default-social.png">
|
||||
|
||||
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet">
|
||||
<link href="/atom.xml" rel="alternate" title="Home Assistant" type="application/atom+xml">
|
||||
<link rel='shortcut icon' href='/images/favicon.ico' />
|
||||
<link rel='icon' type='image/png' href='/images/favicon-192x192.png' sizes='192x192' />
|
||||
</head>
|
||||
|
||||
<body >
|
||||
|
||||
<header>
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid">
|
||||
|
||||
<div class="grid__item three-tenths lap-two-sixths palm-one-whole ha-title">
|
||||
<a href="/" class="site-title">
|
||||
<img width='40' src='/demo/favicon-192x192.png'>
|
||||
<span>Home Assistant</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="grid__item seven-tenths lap-four-sixths palm-one-whole">
|
||||
<nav>
|
||||
<input type="checkbox" id="toggle">
|
||||
<label for="toggle" class="toggle" data-open="Main Menu" data-close="Close Menu"></label>
|
||||
<ul class="menu pull-right">
|
||||
|
||||
<li><a href="/getting-started/">Getting started</a></li>
|
||||
<li><a href="/components/">Components</a></li>
|
||||
<li><a href="/ecosystem/">Ecosystem</a></li>
|
||||
<li><a href="/cookbook/">Examples</a></li>
|
||||
<li><a href="/developers/">Developers</a></li>
|
||||
<li><a href="/blog/">Blog</a></li>
|
||||
<li><a href="/help/">Need help?</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
|
||||
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid grid-center">
|
||||
|
||||
<div class="grid__item two-thirds lap-one-whole palm-one-whole">
|
||||
|
||||
|
||||
<article class="page">
|
||||
|
||||
|
||||
<div class='edit-github'><a href='https://github.com/home-assistant/home-assistant.github.io/tree/current/source/_topics/group_visibility.markdown'>Edit this page on GitHub</a></div>
|
||||
|
||||
|
||||
|
||||
<header>
|
||||
<h1 class="title indent">
|
||||
Group Visibility
|
||||
</h1>
|
||||
</header>
|
||||
<hr class="divider">
|
||||
|
||||
|
||||
<p>After filling Home Assistant with all your precious home automation devices, you usually end up with a cluttered interface and lots of groups that are not interesting in your current context. What if you just want to show groups that are interesting <em>now</em> and hide the rest? That’s when group visibility comes to play.</p>
|
||||
|
||||
<h2><a class="title-link" name="changing-visibility-of-a-group" href="#changing-visibility-of-a-group"></a> Changing visibility of a group</h2>
|
||||
|
||||
<p>To change visibility of a group, use the service <code class="highlighter-rouge">group.set_visibility</code>, pass the group name as <code class="highlighter-rouge">entity_id</code> and use <code class="highlighter-rouge">visible</code> to decide wheter the group should be shown or hidden.</p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">service</span><span class="pi">:</span> <span class="s">group.set_visibility</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">group.basement</span>
|
||||
<span class="s">data</span><span class="pi">:</span>
|
||||
<span class="s">visible</span><span class="pi">:</span> <span class="s">False</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p class="note">
|
||||
If a sensor belongs to only one group and that group is hidden, the sensor will “jump” to the top of the web interface. Add the sensor to an additional (visible) group if you do not want this to happen.
|
||||
</p>
|
||||
|
||||
<h2><a class="title-link" name="automations" href="#automations"></a> Automations</h2>
|
||||
|
||||
<p>First you should decide under which circumstances a group should be visible or not. Depending on the complexity, you might have to write two automations: one that hides the group and another that shows it.</p>
|
||||
|
||||
<p>In this example, the group <code class="highlighter-rouge">group.basement</code> is hidden when the sun sets and shown again when it rises:</p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">automation</span><span class="pi">:</span>
|
||||
<span class="s">trigger</span><span class="pi">:</span>
|
||||
<span class="s">platform</span><span class="pi">:</span> <span class="s">sun</span>
|
||||
<span class="s">event</span><span class="pi">:</span> <span class="s">sunset</span>
|
||||
<span class="s">action</span><span class="pi">:</span>
|
||||
<span class="s">service</span><span class="pi">:</span> <span class="s">group.set_visibility</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">group.basement</span>
|
||||
<span class="s">data</span><span class="pi">:</span>
|
||||
<span class="s">visible</span><span class="pi">:</span> <span class="s">False</span>
|
||||
|
||||
<span class="s">automation 2</span><span class="pi">:</span>
|
||||
<span class="s">trigger</span><span class="pi">:</span>
|
||||
<span class="s">platform</span><span class="pi">:</span> <span class="s">sun</span>
|
||||
<span class="s">event</span><span class="pi">:</span> <span class="s">sunrise</span>
|
||||
<span class="s">action</span><span class="pi">:</span>
|
||||
<span class="s">service</span><span class="pi">:</span> <span class="s">group.set_visibility</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">group.basement</span>
|
||||
<span class="s">data</span><span class="pi">:</span>
|
||||
<span class="s">visible</span><span class="pi">:</span> <span class="s">True</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<h2><a class="title-link" name="easier-automations" href="#easier-automations"></a> Easier automations</h2>
|
||||
|
||||
<p>One of the most common uses cases are to show groups during certain times of day, maybe commuting information during a work day morning or light switches when it is getting dark. The complexity of automations needed to make this happen will quickly get out of hand. So, one way to make the automations easier is to create a sensor that alters its state depending on time of day. One way of doing that is using a <code class="highlighter-rouge">command_line</code> sensor and a script:</p>
|
||||
|
||||
<div class="language-python highlighter-rouge"><pre class="highlight"><code><span class="c">#!/usr/bin/env python3</span>
|
||||
<span class="c"># -*- coding: utf-8 -*-</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">time</span><span class="p">,</span> <span class="n">datetime</span>
|
||||
|
||||
<span class="k">def</span> <span class="nf">mk_occasion</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="p">,</span> <span class="n">days</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
|
||||
<span class="n">s</span> <span class="o">=</span> <span class="n">start</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">':'</span><span class="p">)</span>
|
||||
<span class="n">e</span> <span class="o">=</span> <span class="n">end</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">':'</span><span class="p">)</span>
|
||||
<span class="k">return</span> <span class="p">{</span><span class="s">'name'</span> <span class="p">:</span> <span class="n">name</span><span class="p">,</span>
|
||||
<span class="s">'start'</span><span class="p">:</span> <span class="n">time</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">s</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span> <span class="nb">int</span><span class="p">(</span><span class="n">s</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span> <span class="nb">int</span><span class="p">(</span><span class="n">s</span><span class="p">[</span><span class="mi">2</span><span class="p">])),</span>
|
||||
<span class="s">'end'</span> <span class="p">:</span> <span class="n">time</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">e</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span> <span class="nb">int</span><span class="p">(</span><span class="n">e</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span> <span class="nb">int</span><span class="p">(</span><span class="n">e</span><span class="p">[</span><span class="mi">2</span><span class="p">])),</span>
|
||||
<span class="s">'days'</span> <span class="p">:</span> <span class="n">days</span><span class="p">}</span>
|
||||
|
||||
<span class="c"># Matching is done from top to bottom</span>
|
||||
<span class="n">OCCASIONS</span> <span class="o">=</span> <span class="p">[</span>
|
||||
<span class="c"># More specific occasions</span>
|
||||
<span class="n">mk_occasion</span><span class="p">(</span><span class="s">'work_morning'</span><span class="p">,</span> <span class="s">'06:00:00'</span><span class="p">,</span> <span class="s">'07:10:00'</span><span class="p">,</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">)),</span>
|
||||
|
||||
<span class="c"># General matching</span>
|
||||
<span class="n">mk_occasion</span><span class="p">(</span><span class="s">'weekday'</span><span class="p">,</span> <span class="s">'00:00:00'</span><span class="p">,</span> <span class="s">'23:59:59'</span><span class="p">,</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">)),</span>
|
||||
<span class="n">mk_occasion</span><span class="p">(</span><span class="s">'weekend'</span><span class="p">,</span> <span class="s">'00:00:00'</span><span class="p">,</span> <span class="s">'23:59:59'</span><span class="p">,</span> <span class="p">[</span><span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">])</span>
|
||||
<span class="p">]</span>
|
||||
|
||||
<span class="k">def</span> <span class="nf">get_current_occasion</span><span class="p">(</span><span class="n">occasion_list</span><span class="p">,</span> <span class="n">default_occasion</span><span class="o">=</span><span class="s">'normal'</span><span class="p">):</span>
|
||||
<span class="n">now</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">()</span>
|
||||
<span class="k">for</span> <span class="n">occasion</span> <span class="ow">in</span> <span class="n">OCCASIONS</span><span class="p">:</span>
|
||||
<span class="k">if</span> <span class="n">occasion</span><span class="p">[</span><span class="s">'start'</span><span class="p">]</span> <span class="o"><=</span> <span class="n">now</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o"><=</span> <span class="n">occasion</span><span class="p">[</span><span class="s">'end'</span><span class="p">]</span> <span class="ow">and</span> \
|
||||
<span class="p">(</span><span class="n">occasion</span><span class="p">[</span><span class="s">'days'</span><span class="p">]</span> <span class="ow">is</span> <span class="bp">None</span> <span class="ow">or</span> <span class="n">now</span><span class="o">.</span><span class="n">weekday</span><span class="p">()</span> <span class="ow">in</span> <span class="n">occasion</span><span class="p">[</span><span class="s">'days'</span><span class="p">]):</span>
|
||||
<span class="k">return</span> <span class="n">occasion</span><span class="p">[</span><span class="s">'name'</span><span class="p">]</span>
|
||||
<span class="k">return</span> <span class="n">default_occasion</span>
|
||||
|
||||
<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">'__main__'</span><span class="p">:</span>
|
||||
<span class="k">print</span><span class="p">(</span><span class="n">get_current_occasion</span><span class="p">(</span><span class="n">OCCASIONS</span><span class="p">))</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>This script will output “work_morning” from 06:00-07:10 during weekdays (monday-friday), “weekday” during all other time from monday-friday and “weekend” on saturdays and sundays. Adjust according to your needs. To create the sensor, just add it like this:</p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">sensor</span><span class="pi">:</span>
|
||||
<span class="pi">-</span> <span class="s">platform</span><span class="pi">:</span> <span class="s">command_line</span>
|
||||
<span class="s">name</span><span class="pi">:</span> <span class="s">Occasion</span>
|
||||
<span class="s">command</span><span class="pi">:</span> <span class="s2">"</span><span class="s">python3</span><span class="nv"> </span><span class="s">occasion.py"</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>To simplify things, we create a Home Assistant script that changes the visibility of a group, but also verifies that an entity is in a specific state:</p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">script</span><span class="pi">:</span>
|
||||
<span class="s">group_visibility</span><span class="pi">:</span>
|
||||
<span class="s">sequence</span><span class="pi">:</span>
|
||||
<span class="pi">-</span> <span class="s">service</span><span class="pi">:</span> <span class="s">group.set_visibility</span>
|
||||
<span class="s">data_template</span><span class="pi">:</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s1">'</span><span class="s">{{</span><span class="nv"> </span><span class="s">entity_id</span><span class="nv"> </span><span class="s">}}'</span>
|
||||
<span class="s">visible</span><span class="pi">:</span> <span class="s1">'</span><span class="s">{{</span><span class="nv"> </span><span class="s">is_state(cond,</span><span class="nv"> </span><span class="s">visible_state)</span><span class="nv"> </span><span class="s">}}'</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>The last part is writing an automation that hides or shows the group:</p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">automation</span><span class="pi">:</span>
|
||||
<span class="pi">-</span> <span class="s">alias</span><span class="pi">:</span> <span class="s">Work morning</span>
|
||||
<span class="s">trigger</span><span class="pi">:</span>
|
||||
<span class="pi">-</span> <span class="s">platform</span><span class="pi">:</span> <span class="s">state</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">sensor.occasion</span>
|
||||
<span class="pi">-</span> <span class="s">platform</span><span class="pi">:</span> <span class="s">event</span>
|
||||
<span class="s">event_type</span><span class="pi">:</span> <span class="s">homeassistant_start</span>
|
||||
<span class="s">action</span><span class="pi">:</span>
|
||||
<span class="s">service</span><span class="pi">:</span> <span class="s">script.group_visibility</span>
|
||||
<span class="s">data</span><span class="pi">:</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">group.work_sensors</span>
|
||||
<span class="s">cond</span><span class="pi">:</span> <span class="s">sensor.occasion</span>
|
||||
<span class="s">visible_state</span><span class="pi">:</span> <span class="s1">'</span><span class="s">work_morning'</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>Our previously defined script will be called if <code class="highlighter-rouge">sensor.occasion</code> changes state OR when Home Assistant has started. The group <code class="highlighter-rouge">group.work_sensors</code> will be shown when <code class="highlighter-rouge">sensor.occasion</code> changes state to “work_morning” and hidden otherwise.</p>
|
||||
|
||||
<h3><a class="title-link" name="the-complete-example" href="#the-complete-example"></a> The complete example</h3>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">group</span><span class="pi">:</span>
|
||||
<span class="s">default_view</span><span class="pi">:</span>
|
||||
<span class="s">entities</span><span class="pi">:</span>
|
||||
<span class="pi">-</span> <span class="s">group.work_sensors</span>
|
||||
|
||||
<span class="c1"># Only visible when it's time to go to work</span>
|
||||
<span class="s">work_sensors</span><span class="pi">:</span>
|
||||
<span class="s">name</span><span class="pi">:</span> <span class="s">Time to go to work</span>
|
||||
<span class="s">entities</span><span class="pi">:</span>
|
||||
<span class="pi">-</span> <span class="s">sensor.something1</span>
|
||||
<span class="pi">-</span> <span class="s">sensor.something2</span>
|
||||
|
||||
<span class="s">sensor</span><span class="pi">:</span>
|
||||
<span class="pi">-</span> <span class="s">platform</span><span class="pi">:</span> <span class="s">command_line</span>
|
||||
<span class="s">name</span><span class="pi">:</span> <span class="s">Occasion</span>
|
||||
<span class="s">command</span><span class="pi">:</span> <span class="s2">"</span><span class="s">python3</span><span class="nv"> </span><span class="s">occasion.py"</span>
|
||||
|
||||
<span class="s">script</span><span class="pi">:</span>
|
||||
<span class="s">group_visibility</span><span class="pi">:</span>
|
||||
<span class="s">sequence</span><span class="pi">:</span>
|
||||
<span class="pi">-</span> <span class="s">service</span><span class="pi">:</span> <span class="s">group.set_visibility</span>
|
||||
<span class="s">data_template</span><span class="pi">:</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s1">'</span><span class="s">{{</span><span class="nv"> </span><span class="s">entity_id</span><span class="nv"> </span><span class="s">}}'</span>
|
||||
<span class="s">visible</span><span class="pi">:</span> <span class="s1">'</span><span class="s">{{</span><span class="nv"> </span><span class="s">is_state(cond,</span><span class="nv"> </span><span class="s">visible_state)</span><span class="nv"> </span><span class="s">}}'</span>
|
||||
|
||||
<span class="s">automation</span><span class="pi">:</span>
|
||||
<span class="pi">-</span> <span class="s">alias</span><span class="pi">:</span> <span class="s">Work morning</span>
|
||||
<span class="s">trigger</span><span class="pi">:</span>
|
||||
<span class="pi">-</span> <span class="s">platform</span><span class="pi">:</span> <span class="s">state</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">sensor.occasion</span>
|
||||
<span class="pi">-</span> <span class="s">platform</span><span class="pi">:</span> <span class="s">event</span>
|
||||
<span class="s">event_type</span><span class="pi">:</span> <span class="s">homeassistant_start</span>
|
||||
<span class="s">action</span><span class="pi">:</span>
|
||||
<span class="s">service</span><span class="pi">:</span> <span class="s">script.group_visibility</span>
|
||||
<span class="s">data</span><span class="pi">:</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">group.work_sensors</span>
|
||||
<span class="s">cond</span><span class="pi">:</span> <span class="s">sensor.occasion</span>
|
||||
<span class="s">visible_state</span><span class="pi">:</span> <span class="s1">'</span><span class="s">work_morning'</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
|
||||
</article>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer>
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid">
|
||||
<div class="grid__item">
|
||||
<div class="copyright">
|
||||
<a rel="me" href='https://twitter.com/home_assistant'><i class="icon-twitter"></i></a>
|
||||
<a rel="me" href='https://facebook.com/homeassistantio'><i class="icon-facebook"></i></a>
|
||||
<a rel="me" href='https://plus.google.com/110560654828510104551'><i class="icon-google-plus"></i></a>
|
||||
<a rel="me" href='https://github.com/home-assistant/home-assistant'><i class="icon-github"></i></a>
|
||||
|
||||
<div class="credit">
|
||||
Contact us at <a href='mailto:hello@home-assistant.io'>hello@home-assistant.io</a>.<br>
|
||||
Website powered by <a href='http://jekyllrb.com/'>Jekyll</a> and the <a href='https://github.com/coogie/oscailte'>Oscalite theme</a>.<br />
|
||||
Hosted by <a href='https://pages.github.com/'>GitHub</a> and served by <a href='https://cloudflare.com'>CloudFlare</a>.
|
||||
</div>
|
||||
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a><br /><span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">home-assistant.io</span> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
var _gaq=[['_setAccount','UA-57927901-1'],['_trackPageview']];
|
||||
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
|
||||
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
|
||||
s.parentNode.insertBefore(g,s)}(document,'script'));
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,164 +0,0 @@
|
|||
<!doctype html>
|
||||
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
|
||||
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
|
||||
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
|
||||
<!--[if gt IE 8]><!--> <html> <!--<![endif]-->
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Advanced Topics - Home Assistant</title>
|
||||
<meta name="author" content="Home Assistant">
|
||||
<meta name="description" content="Documentation about the more advanced features in Home Assistant.">
|
||||
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<link rel="canonical" href="https://home-assistant.io/topics/">
|
||||
|
||||
<meta property="fb:app_id" content="338291289691179">
|
||||
<meta property="og:title" content="Advanced Topics">
|
||||
<meta property="og:site_name" content="Home Assistant">
|
||||
<meta property="og:url" content="https://home-assistant.io/topics/">
|
||||
<meta property="og:type" content="website">
|
||||
<meta property="og:description" content="Documentation about the more advanced features in Home Assistant.">
|
||||
<meta property="og:image" content="https://home-assistant.io/images/default-social.png">
|
||||
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:site" content="@home_assistant">
|
||||
|
||||
<meta name="twitter:title" content="Advanced Topics">
|
||||
<meta name="twitter:description" content="Documentation about the more advanced features in Home Assistant.">
|
||||
<meta name="twitter:image" content="https://home-assistant.io/images/default-social.png">
|
||||
|
||||
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet">
|
||||
<link href="/atom.xml" rel="alternate" title="Home Assistant" type="application/atom+xml">
|
||||
<link rel='shortcut icon' href='/images/favicon.ico' />
|
||||
<link rel='icon' type='image/png' href='/images/favicon-192x192.png' sizes='192x192' />
|
||||
</head>
|
||||
|
||||
<body >
|
||||
|
||||
<header>
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid">
|
||||
|
||||
<div class="grid__item three-tenths lap-two-sixths palm-one-whole ha-title">
|
||||
<a href="/" class="site-title">
|
||||
<img width='40' src='/demo/favicon-192x192.png'>
|
||||
<span>Home Assistant</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="grid__item seven-tenths lap-four-sixths palm-one-whole">
|
||||
<nav>
|
||||
<input type="checkbox" id="toggle">
|
||||
<label for="toggle" class="toggle" data-open="Main Menu" data-close="Close Menu"></label>
|
||||
<ul class="menu pull-right">
|
||||
|
||||
<li><a href="/getting-started/">Getting started</a></li>
|
||||
<li><a href="/components/">Components</a></li>
|
||||
<li><a href="/ecosystem/">Ecosystem</a></li>
|
||||
<li><a href="/cookbook/">Examples</a></li>
|
||||
<li><a href="/developers/">Developers</a></li>
|
||||
<li><a href="/blog/">Blog</a></li>
|
||||
<li><a href="/help/">Need help?</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
|
||||
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid grid-center">
|
||||
|
||||
<div class="grid__item two-thirds lap-one-whole palm-one-whole">
|
||||
|
||||
|
||||
<article class="page">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<header>
|
||||
<h1 class="title indent">
|
||||
Advanced Topics
|
||||
</h1>
|
||||
</header>
|
||||
<hr class="divider">
|
||||
|
||||
|
||||
<p>Home Assistant is built from many small building blocks that together offer a powerful and customizable system. This page is a collection of the more advanced topics.</p>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<p><a href="/topics/platform_options/">Entity component platform options</a></p>
|
||||
</li>
|
||||
<li>
|
||||
<p><a href="/topics/events/">Events</a></p>
|
||||
</li>
|
||||
<li>
|
||||
<p><a href="/topics/group_visibility/">Group Visibility</a></p>
|
||||
</li>
|
||||
<li>
|
||||
<p><a href="/topics/packages/">Packages</a></p>
|
||||
</li>
|
||||
<li>
|
||||
<p><a href="/topics/splitting_configuration/">Splitting up the configuration</a></p>
|
||||
</li>
|
||||
<li>
|
||||
<p><a href="/topics/state_object/">State Objects</a></p>
|
||||
</li>
|
||||
<li>
|
||||
<p><a href="/topics/secrets/">Storing secrets</a></p>
|
||||
</li>
|
||||
<li>
|
||||
<p><a href="/topics/templating/">Templating</a></p>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
</article>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer>
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid">
|
||||
<div class="grid__item">
|
||||
<div class="copyright">
|
||||
<a rel="me" href='https://twitter.com/home_assistant'><i class="icon-twitter"></i></a>
|
||||
<a rel="me" href='https://facebook.com/homeassistantio'><i class="icon-facebook"></i></a>
|
||||
<a rel="me" href='https://plus.google.com/110560654828510104551'><i class="icon-google-plus"></i></a>
|
||||
<a rel="me" href='https://github.com/home-assistant/home-assistant'><i class="icon-github"></i></a>
|
||||
|
||||
<div class="credit">
|
||||
Contact us at <a href='mailto:hello@home-assistant.io'>hello@home-assistant.io</a>.<br>
|
||||
Website powered by <a href='http://jekyllrb.com/'>Jekyll</a> and the <a href='https://github.com/coogie/oscailte'>Oscalite theme</a>.<br />
|
||||
Hosted by <a href='https://pages.github.com/'>GitHub</a> and served by <a href='https://cloudflare.com'>CloudFlare</a>.
|
||||
</div>
|
||||
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a><br /><span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">home-assistant.io</span> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
var _gaq=[['_setAccount','UA-57927901-1'],['_trackPageview']];
|
||||
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
|
||||
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
|
||||
s.parentNode.insertBefore(g,s)}(document,'script'));
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,219 +0,0 @@
|
|||
<!doctype html>
|
||||
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
|
||||
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
|
||||
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
|
||||
<!--[if gt IE 8]><!--> <html> <!--<![endif]-->
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Packages - Home Assistant</title>
|
||||
<meta name="author" content="Home Assistant">
|
||||
<meta name="description" content="Describes all there is to know about configuration packages in Home Assistant.">
|
||||
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<link rel="canonical" href="https://home-assistant.io/topics/packages/">
|
||||
|
||||
<meta property="fb:app_id" content="338291289691179">
|
||||
<meta property="og:title" content="Packages">
|
||||
<meta property="og:site_name" content="Home Assistant">
|
||||
<meta property="og:url" content="https://home-assistant.io/topics/packages/">
|
||||
<meta property="og:type" content="article">
|
||||
<meta property="og:description" content="Describes all there is to know about configuration packages in Home Assistant.">
|
||||
<meta property="og:image" content="https://home-assistant.io/images/default-social.png">
|
||||
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:site" content="@home_assistant">
|
||||
|
||||
<meta name="twitter:title" content="Packages">
|
||||
<meta name="twitter:description" content="Describes all there is to know about configuration packages in Home Assistant.">
|
||||
<meta name="twitter:image" content="https://home-assistant.io/images/default-social.png">
|
||||
|
||||
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet">
|
||||
<link href="/atom.xml" rel="alternate" title="Home Assistant" type="application/atom+xml">
|
||||
<link rel='shortcut icon' href='/images/favicon.ico' />
|
||||
<link rel='icon' type='image/png' href='/images/favicon-192x192.png' sizes='192x192' />
|
||||
</head>
|
||||
|
||||
<body >
|
||||
|
||||
<header>
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid">
|
||||
|
||||
<div class="grid__item three-tenths lap-two-sixths palm-one-whole ha-title">
|
||||
<a href="/" class="site-title">
|
||||
<img width='40' src='/demo/favicon-192x192.png'>
|
||||
<span>Home Assistant</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="grid__item seven-tenths lap-four-sixths palm-one-whole">
|
||||
<nav>
|
||||
<input type="checkbox" id="toggle">
|
||||
<label for="toggle" class="toggle" data-open="Main Menu" data-close="Close Menu"></label>
|
||||
<ul class="menu pull-right">
|
||||
|
||||
<li><a href="/getting-started/">Getting started</a></li>
|
||||
<li><a href="/components/">Components</a></li>
|
||||
<li><a href="/ecosystem/">Ecosystem</a></li>
|
||||
<li><a href="/cookbook/">Examples</a></li>
|
||||
<li><a href="/developers/">Developers</a></li>
|
||||
<li><a href="/blog/">Blog</a></li>
|
||||
<li><a href="/help/">Need help?</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
|
||||
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid grid-center">
|
||||
|
||||
<div class="grid__item two-thirds lap-one-whole palm-one-whole">
|
||||
|
||||
|
||||
<article class="page">
|
||||
|
||||
|
||||
<div class='edit-github'><a href='https://github.com/home-assistant/home-assistant.github.io/tree/current/source/_topics/packages.markdown'>Edit this page on GitHub</a></div>
|
||||
|
||||
|
||||
|
||||
<header>
|
||||
<h1 class="title indent">
|
||||
Packages
|
||||
</h1>
|
||||
</header>
|
||||
<hr class="divider">
|
||||
|
||||
|
||||
<p>Packages in Home Assistant provides a way to bundle different component’s configuration together. We were already introduced to the two configuration styles (specifying platforms entries together or individually) on the <a href="/getting-started/devices/">adding devices</a> page. Both of these configuration methods require you to create the component key in the main <code class="highlighter-rouge">configuration.yaml</code> file. With packages we have a way to include different components, or parts of configuration using any of the <code class="highlighter-rouge">!include</code> directives introduced in <a href="/topics/splitting_configuration">splitting the configuration</a>.</p>
|
||||
|
||||
<p>Packages are configured under the core <code class="highlighter-rouge">homeassistant/packages</code> in the configuration and take the format of a packages name (no spaces, all lower case) followed by a dictionary with the package config. For example, package <code class="highlighter-rouge">pack_1</code> would be created as:</p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">homeassistant</span><span class="pi">:</span>
|
||||
<span class="s">...</span>
|
||||
<span class="s">packages</span><span class="pi">:</span>
|
||||
<span class="s">pack_1</span><span class="pi">:</span>
|
||||
<span class="s">...package configuration here...</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>The package configuration can include: <code class="highlighter-rouge">switch</code>, <code class="highlighter-rouge">light</code>, <code class="highlighter-rouge">automation</code>, <code class="highlighter-rouge">groups</code> or the majority of the Home Assistant components.</p>
|
||||
|
||||
<p>It can be specified inline or in a seperate YAML file using <code class="highlighter-rouge">!include</code>.</p>
|
||||
|
||||
<p>Inline example, main <code class="highlighter-rouge">configuration.yaml</code>:</p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">homeassistant</span><span class="pi">:</span>
|
||||
<span class="s">...</span>
|
||||
<span class="s">packages</span><span class="pi">:</span>
|
||||
<span class="s">pack_1</span><span class="pi">:</span>
|
||||
<span class="s">switch</span><span class="pi">:</span>
|
||||
<span class="pi">-</span> <span class="s">platform</span><span class="pi">:</span> <span class="s">rest</span>
|
||||
<span class="s">...</span>
|
||||
<span class="s">light</span><span class="pi">:</span>
|
||||
<span class="pi">-</span> <span class="s">platform</span><span class="pi">:</span> <span class="s">rpi</span>
|
||||
<span class="s">...</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>Include example, main <code class="highlighter-rouge">configuration.yaml</code>:</p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">homeassistant</span><span class="pi">:</span>
|
||||
<span class="s">...</span>
|
||||
<span class="s">packages</span><span class="pi">:</span>
|
||||
<span class="s">pack_1</span><span class="pi">:</span> <span class="kt">!include</span> <span class="s">my_package.yaml</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>The file <code class="highlighter-rouge">my_package.yaml</code> contains the “top-level” configuration:</p>
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code>switch:
|
||||
- platform: rest
|
||||
...
|
||||
light:
|
||||
- platform: rpi
|
||||
...
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>There are some rules for packages that will be merged:</p>
|
||||
|
||||
<ol>
|
||||
<li>Component names may only use the basic form (e.g. <code class="highlighter-rouge">switch</code> and <code class="highlighter-rouge">switch 1</code> or <code class="highlighter-rouge">switch aa</code> is not accepted).</li>
|
||||
<li>Platform based components (<code class="highlighter-rouge">light</code>, <code class="highlighter-rouge">switch</code>, etc) can always be merged.</li>
|
||||
<li>
|
||||
<p>Components where entities are identified by a key that will represent the entity_id (<code class="highlighter-rouge"><span class="p">{</span><span class="err">key:</span><span class="w"> </span><span class="err">config</span><span class="p">}</span></code>) need to have unique ‘keys’ between packages and the main configuration file.</p>
|
||||
|
||||
<p>For example if we have the following in the main config. You are not allowed to re-use “my_input” again for <code class="highlighter-rouge">input_boolean</code> in a package:</p>
|
||||
|
||||
<p><code class="highlighter-rouge">yaml
|
||||
input_boolean:
|
||||
my_input:
|
||||
</code></p>
|
||||
</li>
|
||||
<li>Any component that is not a platform [2], or dictionaries with Entity ID keys [3] cannot be merged and can only occur once between all packages and the main configuration.</li>
|
||||
</ol>
|
||||
|
||||
<p class="note tip">
|
||||
Components inside packages can only specify platform entries using configuration style 1, where all the platforms are grouped under the component name.
|
||||
</p>
|
||||
|
||||
<h3><a class="title-link" name="create-a-packages-folder" href="#create-a-packages-folder"></a> Create a packages folder</h3>
|
||||
|
||||
<p>One way to organise packages would be to create a folder named “packages” in your Home Assistant configuration directory. In the packages directory you can store any number of packages in a YAML file. This entry in your <code class="highlighter-rouge">configuration.yaml</code> will load all packages:</p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">homeassistant</span><span class="pi">:</span>
|
||||
<span class="s">packages</span><span class="pi">:</span> <span class="kt">!include_dir_named</span> <span class="s">packages</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>This uses the concept splitting the configuration and will include all files in a directory with the keys representing the filenames.
|
||||
See the documentation about <a href="/topics/splitting_configuration/">splitting the configuration</a> for more information about <code class="highlighter-rouge">!include_dir_named</code> and other include statements that might be helpful.</p>
|
||||
|
||||
|
||||
</article>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer>
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid">
|
||||
<div class="grid__item">
|
||||
<div class="copyright">
|
||||
<a rel="me" href='https://twitter.com/home_assistant'><i class="icon-twitter"></i></a>
|
||||
<a rel="me" href='https://facebook.com/homeassistantio'><i class="icon-facebook"></i></a>
|
||||
<a rel="me" href='https://plus.google.com/110560654828510104551'><i class="icon-google-plus"></i></a>
|
||||
<a rel="me" href='https://github.com/home-assistant/home-assistant'><i class="icon-github"></i></a>
|
||||
|
||||
<div class="credit">
|
||||
Contact us at <a href='mailto:hello@home-assistant.io'>hello@home-assistant.io</a>.<br>
|
||||
Website powered by <a href='http://jekyllrb.com/'>Jekyll</a> and the <a href='https://github.com/coogie/oscailte'>Oscalite theme</a>.<br />
|
||||
Hosted by <a href='https://pages.github.com/'>GitHub</a> and served by <a href='https://cloudflare.com'>CloudFlare</a>.
|
||||
</div>
|
||||
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a><br /><span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">home-assistant.io</span> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
var _gaq=[['_setAccount','UA-57927901-1'],['_trackPageview']];
|
||||
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
|
||||
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
|
||||
s.parentNode.insertBefore(g,s)}(document,'script'));
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,158 +0,0 @@
|
|||
<!doctype html>
|
||||
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
|
||||
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
|
||||
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
|
||||
<!--[if gt IE 8]><!--> <html> <!--<![endif]-->
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Entity component platform options - Home Assistant</title>
|
||||
<meta name="author" content="Home Assistant">
|
||||
<meta name="description" content="Shows how to customize polling interval for any component via configuration.yaml.">
|
||||
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<link rel="canonical" href="https://home-assistant.io/topics/platform_options/">
|
||||
|
||||
<meta property="fb:app_id" content="338291289691179">
|
||||
<meta property="og:title" content="Entity component platform options">
|
||||
<meta property="og:site_name" content="Home Assistant">
|
||||
<meta property="og:url" content="https://home-assistant.io/topics/platform_options/">
|
||||
<meta property="og:type" content="article">
|
||||
<meta property="og:description" content="Shows how to customize polling interval for any component via configuration.yaml.">
|
||||
<meta property="og:image" content="https://home-assistant.io/images/default-social.png">
|
||||
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:site" content="@home_assistant">
|
||||
|
||||
<meta name="twitter:title" content="Entity component platform options">
|
||||
<meta name="twitter:description" content="Shows how to customize polling interval for any component via configuration.yaml.">
|
||||
<meta name="twitter:image" content="https://home-assistant.io/images/default-social.png">
|
||||
|
||||
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet">
|
||||
<link href="/atom.xml" rel="alternate" title="Home Assistant" type="application/atom+xml">
|
||||
<link rel='shortcut icon' href='/images/favicon.ico' />
|
||||
<link rel='icon' type='image/png' href='/images/favicon-192x192.png' sizes='192x192' />
|
||||
</head>
|
||||
|
||||
<body >
|
||||
|
||||
<header>
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid">
|
||||
|
||||
<div class="grid__item three-tenths lap-two-sixths palm-one-whole ha-title">
|
||||
<a href="/" class="site-title">
|
||||
<img width='40' src='/demo/favicon-192x192.png'>
|
||||
<span>Home Assistant</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="grid__item seven-tenths lap-four-sixths palm-one-whole">
|
||||
<nav>
|
||||
<input type="checkbox" id="toggle">
|
||||
<label for="toggle" class="toggle" data-open="Main Menu" data-close="Close Menu"></label>
|
||||
<ul class="menu pull-right">
|
||||
|
||||
<li><a href="/getting-started/">Getting started</a></li>
|
||||
<li><a href="/components/">Components</a></li>
|
||||
<li><a href="/ecosystem/">Ecosystem</a></li>
|
||||
<li><a href="/cookbook/">Examples</a></li>
|
||||
<li><a href="/developers/">Developers</a></li>
|
||||
<li><a href="/blog/">Blog</a></li>
|
||||
<li><a href="/help/">Need help?</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
|
||||
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid grid-center">
|
||||
|
||||
<div class="grid__item two-thirds lap-one-whole palm-one-whole">
|
||||
|
||||
|
||||
<article class="page">
|
||||
|
||||
|
||||
<div class='edit-github'><a href='https://github.com/home-assistant/home-assistant.github.io/tree/current/source/_topics/platform_options.markdown'>Edit this page on GitHub</a></div>
|
||||
|
||||
|
||||
|
||||
<header>
|
||||
<h1 class="title indent">
|
||||
Entity Component Platform Options
|
||||
</h1>
|
||||
</header>
|
||||
<hr class="divider">
|
||||
|
||||
|
||||
<p>Any component that is based on the entity component allows various extra options to be set per platform.</p>
|
||||
|
||||
<h3><a class="title-link" name="entity-namespace" href="#entity-namespace"></a> Entity namespace</h3>
|
||||
|
||||
<p>By setting an entity namespace, all entities will be prefixed with that namespace. That way <code class="highlighter-rouge">light.bathroom</code> can become <code class="highlighter-rouge">light.holiday_house_bathroom</code>.</p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="c1"># Example configuration.yaml entry</span>
|
||||
<span class="s">light</span><span class="pi">:</span>
|
||||
<span class="s">platform</span><span class="pi">:</span> <span class="s">hue</span>
|
||||
<span class="s">entity_namespace</span><span class="pi">:</span> <span class="s">holiday_house</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<h3><a class="title-link" name="scan-interval" href="#scan-interval"></a> Scan Interval</h3>
|
||||
|
||||
<p>Platforms that require polling will be polled in an interval specified by the main component. For example a light will check every 30 seconds for a changed state. It is possible to overwrite this scan interval for any platform that is being polled by specifying a <code class="highlighter-rouge">scan_interval</code> config key. In the example below we setup the Philips Hue lights but tell Home Assistant to poll the devices every 10 seconds instead of the default 30 seconds.</p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="c1"># Example configuration.yaml entry to poll Hue lights every 10 seconds.</span>
|
||||
<span class="s">light</span><span class="pi">:</span>
|
||||
<span class="s">platform</span><span class="pi">:</span> <span class="s">hue</span>
|
||||
<span class="s">scan_interval</span><span class="pi">:</span> <span class="s">10</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
|
||||
</article>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer>
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid">
|
||||
<div class="grid__item">
|
||||
<div class="copyright">
|
||||
<a rel="me" href='https://twitter.com/home_assistant'><i class="icon-twitter"></i></a>
|
||||
<a rel="me" href='https://facebook.com/homeassistantio'><i class="icon-facebook"></i></a>
|
||||
<a rel="me" href='https://plus.google.com/110560654828510104551'><i class="icon-google-plus"></i></a>
|
||||
<a rel="me" href='https://github.com/home-assistant/home-assistant'><i class="icon-github"></i></a>
|
||||
|
||||
<div class="credit">
|
||||
Contact us at <a href='mailto:hello@home-assistant.io'>hello@home-assistant.io</a>.<br>
|
||||
Website powered by <a href='http://jekyllrb.com/'>Jekyll</a> and the <a href='https://github.com/coogie/oscailte'>Oscalite theme</a>.<br />
|
||||
Hosted by <a href='https://pages.github.com/'>GitHub</a> and served by <a href='https://cloudflare.com'>CloudFlare</a>.
|
||||
</div>
|
||||
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a><br /><span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">home-assistant.io</span> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
var _gaq=[['_setAccount','UA-57927901-1'],['_trackPageview']];
|
||||
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
|
||||
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
|
||||
s.parentNode.insertBefore(g,s)}(document,'script'));
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,216 +0,0 @@
|
|||
<!doctype html>
|
||||
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
|
||||
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
|
||||
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
|
||||
<!--[if gt IE 8]><!--> <html> <!--<![endif]-->
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Storing secrets - Home Assistant</title>
|
||||
<meta name="author" content="Home Assistant">
|
||||
<meta name="description" content="Storing secrets outside of your configuration.yaml.">
|
||||
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<link rel="canonical" href="https://home-assistant.io/topics/secrets/">
|
||||
|
||||
<meta property="fb:app_id" content="338291289691179">
|
||||
<meta property="og:title" content="Storing secrets">
|
||||
<meta property="og:site_name" content="Home Assistant">
|
||||
<meta property="og:url" content="https://home-assistant.io/topics/secrets/">
|
||||
<meta property="og:type" content="article">
|
||||
<meta property="og:description" content="Storing secrets outside of your configuration.yaml.">
|
||||
<meta property="og:image" content="https://home-assistant.io/images/default-social.png">
|
||||
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:site" content="@home_assistant">
|
||||
|
||||
<meta name="twitter:title" content="Storing secrets">
|
||||
<meta name="twitter:description" content="Storing secrets outside of your configuration.yaml.">
|
||||
<meta name="twitter:image" content="https://home-assistant.io/images/default-social.png">
|
||||
|
||||
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet">
|
||||
<link href="/atom.xml" rel="alternate" title="Home Assistant" type="application/atom+xml">
|
||||
<link rel='shortcut icon' href='/images/favicon.ico' />
|
||||
<link rel='icon' type='image/png' href='/images/favicon-192x192.png' sizes='192x192' />
|
||||
</head>
|
||||
|
||||
<body >
|
||||
|
||||
<header>
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid">
|
||||
|
||||
<div class="grid__item three-tenths lap-two-sixths palm-one-whole ha-title">
|
||||
<a href="/" class="site-title">
|
||||
<img width='40' src='/demo/favicon-192x192.png'>
|
||||
<span>Home Assistant</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="grid__item seven-tenths lap-four-sixths palm-one-whole">
|
||||
<nav>
|
||||
<input type="checkbox" id="toggle">
|
||||
<label for="toggle" class="toggle" data-open="Main Menu" data-close="Close Menu"></label>
|
||||
<ul class="menu pull-right">
|
||||
|
||||
<li><a href="/getting-started/">Getting started</a></li>
|
||||
<li><a href="/components/">Components</a></li>
|
||||
<li><a href="/ecosystem/">Ecosystem</a></li>
|
||||
<li><a href="/cookbook/">Examples</a></li>
|
||||
<li><a href="/developers/">Developers</a></li>
|
||||
<li><a href="/blog/">Blog</a></li>
|
||||
<li><a href="/help/">Need help?</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
|
||||
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid grid-center">
|
||||
|
||||
<div class="grid__item two-thirds lap-one-whole palm-one-whole">
|
||||
|
||||
|
||||
<article class="page">
|
||||
|
||||
|
||||
<div class='edit-github'><a href='https://github.com/home-assistant/home-assistant.github.io/tree/current/source/_topics/secrets.markdown'>Edit this page on GitHub</a></div>
|
||||
|
||||
|
||||
|
||||
<header>
|
||||
<h1 class="title indent">
|
||||
Storing Secrets
|
||||
</h1>
|
||||
</header>
|
||||
<hr class="divider">
|
||||
|
||||
|
||||
<p>The <code class="highlighter-rouge">configuration.yaml</code> file is a plain-text file, thus it is readable by anyone who has access to the file. The file contains passwords and API tokens which need to be redacted if you want to share your configuration. By using <code class="highlighter-rouge">!secrets</code> you can remove any private information from you configuration files. This separation can also help you to keep easier track of your passwords and API keys. As they are all stored at one place and no longer spread across the <code class="highlighter-rouge">configuration.yaml</code> file or even multiple yaml files if you <a href="/topics/splitting_configuration/">split up your configuration</a>.</p>
|
||||
|
||||
<h3><a class="title-link" name="using-secretsyaml" href="#using-secretsyaml"></a> Using secrets.yaml</h3>
|
||||
|
||||
<p>The workflow for moving private information to <code class="highlighter-rouge">secrets.yaml</code> is very similar to the <a href="/topics/splitting_configuration/">splitting of the configuration</a>. Create a <code class="highlighter-rouge">secrets.yaml</code> file in your Home assistant configuration directory (The location of the folder differs between operating systems: on OS X and Linux it’s <code class="highlighter-rouge">~/.homeassistant</code> and on Windows it’s <code class="highlighter-rouge">%APPDATA%/.homeassistant</code>).</p>
|
||||
|
||||
<p>The entries for password and API keys in the <code class="highlighter-rouge">configuration.yaml</code> file usually looks like the example below.</p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">http</span><span class="pi">:</span>
|
||||
<span class="s">api_password</span><span class="pi">:</span> <span class="s">YOUR_PASSWORD</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>Those entries need to be replaced with <code class="highlighter-rouge">!secret</code> and a identifier.</p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">http</span><span class="pi">:</span>
|
||||
<span class="s">api_password</span><span class="pi">:</span> <span class="kt">!secret</span> <span class="s">http_password</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>The <code class="highlighter-rouge">secrets.yaml</code> file contains the corresponding password assigned to the identifier.</p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">http_password</span><span class="pi">:</span> <span class="s">YOUR_PASSWORD</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<h3><a class="title-link" name="debugging-secrets" href="#debugging-secrets"></a> Debugging secrets</h3>
|
||||
|
||||
<p>When you start splitting your configuration into multiple files, you might end up with configuration in sub folders. Secrets will be resolved in this order:</p>
|
||||
<ul>
|
||||
<li>A <code class="highlighter-rouge">secrets.yaml</code> located in the same folder as the yaml file referencing the secret,</li>
|
||||
<li>next, parent folders will be searched for a <code class="highlighter-rouge">secrets.yaml</code> file with the secret, stopping at the folder with the main <code class="highlighter-rouge">configuration.yaml</code>,</li>
|
||||
<li>lastly, <code class="highlighter-rouge">keyring</code> will be queried for the secret (more info below)</li>
|
||||
</ul>
|
||||
|
||||
<p>To see where secrets are being loaded from you can either add an option to your <code class="highlighter-rouge">secrets.yaml</code> file or use the <code class="highlighter-rouge">check_config</code> script.</p>
|
||||
|
||||
<p><em>Option 1</em>: Print where secrets are retrieved from to the Home Assistant log by adding the following to <code class="highlighter-rouge">secrets.yaml</code>:</p>
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">logger</span><span class="pi">:</span> <span class="s">debug</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
<p>This will not print the actual secret’s value to the log.</p>
|
||||
|
||||
<p><em>Option 2</em>: View where secrets are retrieved from and the contents of all <code class="highlighter-rouge">secrets.yaml</code> files used, you can use the <code class="highlighter-rouge">check_config</code> script from the command line:</p>
|
||||
<div class="language-bash highlighter-rouge"><pre class="highlight"><code>hass --script check_config --secrets
|
||||
</code></pre>
|
||||
</div>
|
||||
<p>This will print all your secrets</p>
|
||||
|
||||
<h3><a class="title-link" name="storing-passwords-in-a-keyring-managed-by-your-os" href="#storing-passwords-in-a-keyring-managed-by-your-os"></a> Storing passwords in a keyring managed by your OS</h3>
|
||||
|
||||
<p>Using <a href="http://pythonhosted.org/keyring/">Keyring</a> is an alternative way to <code class="highlighter-rouge">secrets.yaml</code>. They can be managed from the command line via the keyring script.</p>
|
||||
|
||||
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>hass --script keyring --help
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>To store a password in keyring, replace your password or API key with <code class="highlighter-rouge">!secret</code> and an identifier in <code class="highlighter-rouge">configuration.yaml</code> file.</p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">http</span><span class="pi">:</span>
|
||||
<span class="s">api_password</span><span class="pi">:</span> <span class="kt">!secret</span> <span class="s">http_password</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>Create an entry in your keyring.</p>
|
||||
|
||||
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>hass --script keyring <span class="nb">set </span>http_password
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>If you launch Home Assistant now, you will be prompted for the keyring password to unlock your keyring.</p>
|
||||
|
||||
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>hass
|
||||
Config directory: /home/fab/.homeassistant
|
||||
Please enter password <span class="k">for </span>encrypted keyring:
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p class="note warning">
|
||||
If your are using the Python Keyring, <a href="/getting-started/autostart/">autostarting</a> of Home Assistant will no longer work.
|
||||
</p>
|
||||
|
||||
|
||||
</article>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer>
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid">
|
||||
<div class="grid__item">
|
||||
<div class="copyright">
|
||||
<a rel="me" href='https://twitter.com/home_assistant'><i class="icon-twitter"></i></a>
|
||||
<a rel="me" href='https://facebook.com/homeassistantio'><i class="icon-facebook"></i></a>
|
||||
<a rel="me" href='https://plus.google.com/110560654828510104551'><i class="icon-google-plus"></i></a>
|
||||
<a rel="me" href='https://github.com/home-assistant/home-assistant'><i class="icon-github"></i></a>
|
||||
|
||||
<div class="credit">
|
||||
Contact us at <a href='mailto:hello@home-assistant.io'>hello@home-assistant.io</a>.<br>
|
||||
Website powered by <a href='http://jekyllrb.com/'>Jekyll</a> and the <a href='https://github.com/coogie/oscailte'>Oscalite theme</a>.<br />
|
||||
Hosted by <a href='https://pages.github.com/'>GitHub</a> and served by <a href='https://cloudflare.com'>CloudFlare</a>.
|
||||
</div>
|
||||
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a><br /><span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">home-assistant.io</span> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
var _gaq=[['_setAccount','UA-57927901-1'],['_trackPageview']];
|
||||
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
|
||||
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
|
||||
s.parentNode.insertBefore(g,s)}(document,'script'));
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,570 +0,0 @@
|
|||
<!doctype html>
|
||||
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
|
||||
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
|
||||
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
|
||||
<!--[if gt IE 8]><!--> <html> <!--<![endif]-->
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Splitting up the configuration - Home Assistant</title>
|
||||
<meta name="author" content="Home Assistant">
|
||||
<meta name="description" content="Splitting the configuration.yaml into several files.">
|
||||
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<link rel="canonical" href="https://home-assistant.io/topics/splitting_configuration/">
|
||||
|
||||
<meta property="fb:app_id" content="338291289691179">
|
||||
<meta property="og:title" content="Splitting up the configuration">
|
||||
<meta property="og:site_name" content="Home Assistant">
|
||||
<meta property="og:url" content="https://home-assistant.io/topics/splitting_configuration/">
|
||||
<meta property="og:type" content="article">
|
||||
<meta property="og:description" content="Splitting the configuration.yaml into several files.">
|
||||
<meta property="og:image" content="https://home-assistant.io/images/default-social.png">
|
||||
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:site" content="@home_assistant">
|
||||
|
||||
<meta name="twitter:title" content="Splitting up the configuration">
|
||||
<meta name="twitter:description" content="Splitting the configuration.yaml into several files.">
|
||||
<meta name="twitter:image" content="https://home-assistant.io/images/default-social.png">
|
||||
|
||||
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet">
|
||||
<link href="/atom.xml" rel="alternate" title="Home Assistant" type="application/atom+xml">
|
||||
<link rel='shortcut icon' href='/images/favicon.ico' />
|
||||
<link rel='icon' type='image/png' href='/images/favicon-192x192.png' sizes='192x192' />
|
||||
</head>
|
||||
|
||||
<body >
|
||||
|
||||
<header>
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid">
|
||||
|
||||
<div class="grid__item three-tenths lap-two-sixths palm-one-whole ha-title">
|
||||
<a href="/" class="site-title">
|
||||
<img width='40' src='/demo/favicon-192x192.png'>
|
||||
<span>Home Assistant</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="grid__item seven-tenths lap-four-sixths palm-one-whole">
|
||||
<nav>
|
||||
<input type="checkbox" id="toggle">
|
||||
<label for="toggle" class="toggle" data-open="Main Menu" data-close="Close Menu"></label>
|
||||
<ul class="menu pull-right">
|
||||
|
||||
<li><a href="/getting-started/">Getting started</a></li>
|
||||
<li><a href="/components/">Components</a></li>
|
||||
<li><a href="/ecosystem/">Ecosystem</a></li>
|
||||
<li><a href="/cookbook/">Examples</a></li>
|
||||
<li><a href="/developers/">Developers</a></li>
|
||||
<li><a href="/blog/">Blog</a></li>
|
||||
<li><a href="/help/">Need help?</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
|
||||
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid grid-center">
|
||||
|
||||
<div class="grid__item two-thirds lap-one-whole palm-one-whole">
|
||||
|
||||
|
||||
<article class="page">
|
||||
|
||||
|
||||
<div class='edit-github'><a href='https://github.com/home-assistant/home-assistant.github.io/tree/current/source/_topics/splitting_configuration.markdown'>Edit this page on GitHub</a></div>
|
||||
|
||||
|
||||
|
||||
<header>
|
||||
<h1 class="title indent">
|
||||
Splitting Up the Configuration
|
||||
</h1>
|
||||
</header>
|
||||
<hr class="divider">
|
||||
|
||||
|
||||
<p>So you’ve been using Home Assistant for a while now and your <a href="https://home-assistant.io/cookbook/configuration_yaml_from_bassclarinetl2/">configuration.yaml file brings people to tears</a> or you simply want to start off with the distributed approach, here’s how to “split the configuration.yaml” into more manageable (read: humanly readable) pieces.</p>
|
||||
|
||||
<p>First off, several community members have sanitized (read: without api keys/passwords etc) versions of their configurations available for viewing, you can see a list of them <a href="https://home-assistant.io/cookbook/#example-configurationyaml">here</a>.</p>
|
||||
|
||||
<p>As commenting code doesn’t always happen, please read on for the details.</p>
|
||||
|
||||
<p>Now despite the logical assumption that the <code class="highlighter-rouge">configuration.yaml</code> will be replaced by this process it will in fact remain, albeit in a much less cluttered form.</p>
|
||||
|
||||
<p>In this lighter version we will still need what could be called the core snippet:</p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">homeassistant</span><span class="pi">:</span>
|
||||
<span class="c1"># Name of the location where Home Assistant is running</span>
|
||||
<span class="s">name</span><span class="pi">:</span> <span class="s">My Home Assistant Instance</span>
|
||||
<span class="c1"># Location required to calculate the time the sun rises and sets</span>
|
||||
<span class="s">latitude</span><span class="pi">:</span> <span class="s">37</span>
|
||||
<span class="s">longitude</span><span class="pi">:</span> <span class="s">-121</span>
|
||||
<span class="c1"># 'metric' for Metric, 'imperial' for Imperial</span>
|
||||
<span class="s">unit_system</span><span class="pi">:</span> <span class="s">imperial</span>
|
||||
<span class="c1"># Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones</span>
|
||||
<span class="s">time_zone</span><span class="pi">:</span> <span class="s">America/Los_Angeles</span>
|
||||
<span class="s">customize</span><span class="pi">:</span> <span class="kt">!include</span> <span class="s">customize.yaml</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>Note that each line after <code class="highlighter-rouge">homeassistant:</code> is indented two (2) spaces. Since the configuration files in Home Assistant are based on the YAML language, indentation and spacing are important. Also note that seemingly strange entry under <code class="highlighter-rouge">customize:</code>.</p>
|
||||
|
||||
<p><code class="highlighter-rouge">!include filename.yaml</code> is the statement that tells Home Assistant to insert the contents of <code class="highlighter-rouge">filename.yaml</code> at that point. This is how we are going to break a monolithic and hard to read file (when it gets big) into more manageable chunks.</p>
|
||||
|
||||
<p>Now before we start splitting out the different components, let’s look at the other components (in our example) that will stay in the base file:</p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">history</span><span class="pi">:</span>
|
||||
<span class="s">frontend</span><span class="pi">:</span>
|
||||
<span class="s">logbook</span><span class="pi">:</span>
|
||||
<span class="s">http</span><span class="pi">:</span>
|
||||
<span class="s">api_password</span><span class="pi">:</span> <span class="s">ImNotTelling!</span>
|
||||
|
||||
<span class="s">ifttt</span><span class="pi">:</span>
|
||||
<span class="s">key</span><span class="pi">:</span> <span class="pi">[</span><span class="nv">nope</span><span class="pi">]</span>
|
||||
|
||||
<span class="s">wink</span><span class="pi">:</span>
|
||||
<span class="s">access_token</span><span class="pi">:</span> <span class="pi">[</span><span class="nv">wouldn't you</span><span class="pi">]</span>
|
||||
<span class="s">refresh_token</span><span class="pi">:</span> <span class="pi">[</span><span class="nv">like to know</span><span class="pi">]</span>
|
||||
|
||||
<span class="s">zwave</span><span class="pi">:</span>
|
||||
<span class="s">usb_path</span><span class="pi">:</span> <span class="s">/dev/ttyUSB0</span>
|
||||
<span class="s">config_path</span><span class="pi">:</span> <span class="s">/usr/local/share/python-openzwave/config</span>
|
||||
<span class="s">polling_interval</span><span class="pi">:</span> <span class="s">10000</span>
|
||||
|
||||
<span class="s">mqtt</span><span class="pi">:</span>
|
||||
<span class="s">broker</span><span class="pi">:</span> <span class="s">127.0.0.1</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
<p>As with the core snippet, indentation makes a difference. The component headers (<code class="highlighter-rouge">mqtt:</code>) should be fully left aligned (aka no indent), and the parameters (<code class="highlighter-rouge">broker:</code>) should be indented two (2) spaces.</p>
|
||||
|
||||
<p>While some of these components can technically be moved to a separate file they are so small or “one off’s” where splitting them off is superfluous. Also, you’ll notice the # symbol (hash/pound). This represents a “comment” as far as the commands are interpreted. Put another way, any line prefixed with a <code class="highlighter-rouge">#</code> will be ignored. This makes breaking up files for human readability really convenient, not to mention turning off features while leaving the entry intact. (Look at the <code class="highlighter-rouge">zigbee:</code> entry above and the b entry further down)</p>
|
||||
|
||||
<p>Now, lets assume that a blank file has been created in the Home Assistant configuration directory for each of the following:</p>
|
||||
|
||||
<div class="language-text highlighter-rouge"><pre class="highlight"><code>automation.yaml
|
||||
zones.yaml
|
||||
sensors.yaml
|
||||
switches.yaml
|
||||
device_tracker.yaml
|
||||
customize.yaml
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p><code class="highlighter-rouge">automation.yaml</code> will hold all the automation component details. <code class="highlighter-rouge">zones.yaml</code> will hold the zone component details and so forth. These files can be called anything but giving them names that match their function will make things easier to keep track of.</p>
|
||||
|
||||
<p>Inside the base configuration file add the following entries:</p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">automation</span><span class="pi">:</span> <span class="kt">!include</span> <span class="s">automation.yaml</span>
|
||||
<span class="s">zone</span><span class="pi">:</span> <span class="kt">!include</span> <span class="s">zones.yaml</span>
|
||||
<span class="s">sensor</span><span class="pi">:</span> <span class="kt">!include</span> <span class="s">sensors.yaml</span>
|
||||
<span class="s">switch</span><span class="pi">:</span> <span class="kt">!include</span> <span class="s">switches.yaml</span>
|
||||
<span class="s">device_tracker</span><span class="pi">:</span> <span class="kt">!include</span> <span class="s">device_tracker.yaml</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>Note that there can only be one <code class="highlighter-rouge">!include:</code> for each component so chaining them isn’t going to work. If that sounds like greek, don’t worry about it.</p>
|
||||
|
||||
<p>Alright, so we’ve got the single components and the include statements in the base file, what goes in those extra files?</p>
|
||||
|
||||
<p>Let’s look at the <code class="highlighter-rouge">device_tracker.yaml</code> file from our example:</p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="pi">-</span> <span class="s">platform</span><span class="pi">:</span> <span class="s">owntracks</span>
|
||||
<span class="pi">-</span> <span class="s">platform</span><span class="pi">:</span> <span class="s">nmap_tracker</span>
|
||||
<span class="s">hosts</span><span class="pi">:</span> <span class="s">192.168.2.0/24</span>
|
||||
<span class="s">home_interval</span><span class="pi">:</span> <span class="s">3</span>
|
||||
|
||||
<span class="s">track_new_devices</span><span class="pi">:</span> <span class="s">yes</span>
|
||||
<span class="s">interval_seconds</span><span class="pi">:</span> <span class="s">40</span>
|
||||
<span class="s">consider_home</span><span class="pi">:</span> <span class="s">120</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>This small example illustrates how the “split” files work. In this case, we start with a “comment block” identifying the file followed by two (2) device tracker entries (<code class="highlighter-rouge">owntracks</code> and <code class="highlighter-rouge">nmap</code>). These files follow <a href="/getting-started/devices/#style-2-list-each-device-separately">“style 1”</a> that is to say a fully left aligned leading entry (<code class="highlighter-rouge">- platform: owntracks</code>) followed by the parameter entries indented two (2) spaces.</p>
|
||||
|
||||
<p>This (large) sensor configuration gives us another example:</p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="c1">### sensors.yaml</span>
|
||||
<span class="c1">### METEOBRIDGE #############################################</span>
|
||||
<span class="pi">-</span> <span class="s">platform</span><span class="pi">:</span> <span class="s">tcp</span>
|
||||
<span class="s">name</span><span class="pi">:</span> <span class="s1">'</span><span class="s">Outdoor</span><span class="nv"> </span><span class="s">Temp</span><span class="nv"> </span><span class="s">(Meteobridge)'</span>
|
||||
<span class="s">host</span><span class="pi">:</span> <span class="s">192.168.2.82</span>
|
||||
<span class="s">timeout</span><span class="pi">:</span> <span class="s">6</span>
|
||||
<span class="s">payload</span><span class="pi">:</span> <span class="s2">"</span><span class="s">Content-type:</span><span class="nv"> </span><span class="s">text/xml;</span><span class="nv"> </span><span class="s">charset=UTF-8</span><span class="se">\n\n</span><span class="s">"</span>
|
||||
<span class="s">value_template</span><span class="pi">:</span> <span class="s2">"</span><span class="s">{{value.split</span><span class="nv"> </span><span class="s">('</span><span class="nv"> </span><span class="s">')[2]}}"</span>
|
||||
<span class="s">unit</span><span class="pi">:</span> <span class="s">C</span>
|
||||
<span class="pi">-</span> <span class="s">platform</span><span class="pi">:</span> <span class="s">tcp</span>
|
||||
<span class="s">name</span><span class="pi">:</span> <span class="s1">'</span><span class="s">Outdoor</span><span class="nv"> </span><span class="s">Humidity</span><span class="nv"> </span><span class="s">(Meteobridge)'</span>
|
||||
<span class="s">host</span><span class="pi">:</span> <span class="s">192.168.2.82</span>
|
||||
<span class="s">port</span><span class="pi">:</span> <span class="s">5556</span>
|
||||
<span class="s">timeout</span><span class="pi">:</span> <span class="s">6</span>
|
||||
<span class="s">payload</span><span class="pi">:</span> <span class="s2">"</span><span class="s">Content-type:</span><span class="nv"> </span><span class="s">text/xml;</span><span class="nv"> </span><span class="s">charset=UTF-8</span><span class="se">\n\n</span><span class="s">"</span>
|
||||
<span class="s">value_template</span><span class="pi">:</span> <span class="s2">"</span><span class="s">{{value.split</span><span class="nv"> </span><span class="s">('</span><span class="nv"> </span><span class="s">')[3]}}"</span>
|
||||
<span class="s">unit</span><span class="pi">:</span> <span class="s">Percent</span>
|
||||
|
||||
<span class="c1">#### STEAM FRIENDS ##################################</span>
|
||||
<span class="pi">-</span> <span class="s">platform</span><span class="pi">:</span> <span class="s">steam_online</span>
|
||||
<span class="s">api_key</span><span class="pi">:</span> <span class="pi">[</span><span class="nv">not telling</span><span class="pi">]</span>
|
||||
<span class="s">accounts</span><span class="pi">:</span>
|
||||
<span class="pi">-</span> <span class="s">76561198012067051</span>
|
||||
|
||||
<span class="c1">#### TIME/DATE ##################################</span>
|
||||
<span class="pi">-</span> <span class="s">platform</span><span class="pi">:</span> <span class="s">time_date</span>
|
||||
<span class="s">display_options</span><span class="pi">:</span>
|
||||
<span class="pi">-</span> <span class="s1">'</span><span class="s">time'</span>
|
||||
<span class="pi">-</span> <span class="s1">'</span><span class="s">date'</span>
|
||||
<span class="pi">-</span> <span class="s">platform</span><span class="pi">:</span> <span class="s">worldclock</span>
|
||||
<span class="s">time_zone</span><span class="pi">:</span> <span class="s">Etc/UTC</span>
|
||||
<span class="s">name</span><span class="pi">:</span> <span class="s1">'</span><span class="s">UTC'</span>
|
||||
<span class="pi">-</span> <span class="s">platform</span><span class="pi">:</span> <span class="s">worldclock</span>
|
||||
<span class="s">time_zone</span><span class="pi">:</span> <span class="s">America/New_York</span>
|
||||
<span class="s">name</span><span class="pi">:</span> <span class="s1">'</span><span class="s">Ann</span><span class="nv"> </span><span class="s">Arbor'</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>You’ll notice that this example includes a secondary parameter section (under the steam section) as well as a better example of the way comments can be used to break down files into sections.</p>
|
||||
|
||||
<p>That about wraps it up.</p>
|
||||
|
||||
<p>If you have issues checkout <code class="highlighter-rouge">home-assistant.log</code> in the configuration directory as well as your indentations. If all else fails, head over to the <a href="https://gitter.im/balloob/home-assistant">Gitter Chatroom</a> and ask away.</p>
|
||||
|
||||
<h3><a class="title-link" name="debugging-multiple-configuration-files" href="#debugging-multiple-configuration-files"></a> Debugging multiple configuration files</h3>
|
||||
|
||||
<p>If you have many configuration files, the <code class="highlighter-rouge">check_config</code> script allows you to see how Home Assistant interprets them:</p>
|
||||
<ul>
|
||||
<li>Listing all loaded files: <code class="highlighter-rouge">hass --script check_config --files</code></li>
|
||||
<li>Viewing a component’s config: <code class="highlighter-rouge">hass --script check_config --info light</code></li>
|
||||
<li>Or all components’ config: <code class="highlighter-rouge">hass --script check_config --info all</code></li>
|
||||
</ul>
|
||||
|
||||
<p>You can get help from the command line using: <code class="highlighter-rouge">hass --script check_config --help</code></p>
|
||||
|
||||
<h3><a class="title-link" name="advanced-usage" href="#advanced-usage"></a> Advanced Usage</h3>
|
||||
|
||||
<p>We offer four advanced options to include whole directories at once.</p>
|
||||
<ul>
|
||||
<li><code class="highlighter-rouge">!include_dir_list</code> will return the content of a directory as a list with each file content being an entry in the list.</li>
|
||||
<li><code class="highlighter-rouge">!include_dir_named</code> will return the content of a directory as a dictionary which maps filename => content of file.</li>
|
||||
<li><code class="highlighter-rouge">!include_dir_merge_list</code> will return the content of a directory as a list by merging all files (which should contain a list) into 1 big list.</li>
|
||||
<li><code class="highlighter-rouge">!include_dir_merge_named</code> will return the content of a directory as a dictionary by loading each file and merging it into 1 big dictionary.</li>
|
||||
</ul>
|
||||
|
||||
<p>These work recursively. As an example using <code class="highlighter-rouge">!include_dir_* automation</code>, will include all 6 files shown below:</p>
|
||||
|
||||
<div class="language-bash highlighter-rouge"><pre class="highlight"><code>.
|
||||
└── .homeassistant
|
||||
├── automation
|
||||
│ ├── lights
|
||||
│ │ ├── turn_light_off_bedroom.yaml
|
||||
│ │ ├── turn_light_off_lounge.yaml
|
||||
│ │ ├── turn_light_on_bedroom.yaml
|
||||
│ │ └── turn_light_on_lounge.yaml
|
||||
│ ├── say_hello.yaml
|
||||
│ └── sensors
|
||||
│ └── react.yaml
|
||||
└── configuration.yaml <span class="o">(</span>not included<span class="o">)</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<h4><a class="title-link" name="example-include_dir_list" href="#example-include_dir_list"></a> Example: <code class="highlighter-rouge">!include_dir_list</code></h4>
|
||||
|
||||
<p><code class="highlighter-rouge">configuration.yaml</code></p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">automation</span><span class="pi">:</span>
|
||||
<span class="pi">-</span> <span class="s">alias</span><span class="pi">:</span> <span class="s">Automation 1</span>
|
||||
<span class="s">trigger</span><span class="pi">:</span>
|
||||
<span class="s">platform</span><span class="pi">:</span> <span class="s">state</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">device_tracker.iphone</span>
|
||||
<span class="s">to</span><span class="pi">:</span> <span class="s1">'</span><span class="s">home'</span>
|
||||
<span class="s">action</span><span class="pi">:</span>
|
||||
<span class="s">service</span><span class="pi">:</span> <span class="s">light.turn_on</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">light.entryway</span>
|
||||
<span class="pi">-</span> <span class="s">alias</span><span class="pi">:</span> <span class="s">Automation 2</span>
|
||||
<span class="s">trigger</span><span class="pi">:</span>
|
||||
<span class="s">platform</span><span class="pi">:</span> <span class="s">state</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">device_tracker.iphone</span>
|
||||
<span class="s">from</span><span class="pi">:</span> <span class="s1">'</span><span class="s">home'</span>
|
||||
<span class="s">action</span><span class="pi">:</span>
|
||||
<span class="s">service</span><span class="pi">:</span> <span class="s">light.turn_off</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">light.entryway</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>can be turned into:</p>
|
||||
|
||||
<p><code class="highlighter-rouge">configuration.yaml</code></p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">automation</span><span class="pi">:</span> <span class="kt">!include_dir_list</span> <span class="s">automation/presence/</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p><code class="highlighter-rouge">automation/presence/automation1.yaml</code></p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">alias</span><span class="pi">:</span> <span class="s">Automation 1</span>
|
||||
<span class="s">trigger</span><span class="pi">:</span>
|
||||
<span class="s">platform</span><span class="pi">:</span> <span class="s">state</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">device_tracker.iphone</span>
|
||||
<span class="s">to</span><span class="pi">:</span> <span class="s1">'</span><span class="s">home'</span>
|
||||
<span class="s">action</span><span class="pi">:</span>
|
||||
<span class="s">service</span><span class="pi">:</span> <span class="s">light.turn_on</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">light.entryway</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p><code class="highlighter-rouge">automation/presence/automation2.yaml</code></p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">alias</span><span class="pi">:</span> <span class="s">Automation 2</span>
|
||||
<span class="s">trigger</span><span class="pi">:</span>
|
||||
<span class="s">platform</span><span class="pi">:</span> <span class="s">state</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">device_tracker.iphone</span>
|
||||
<span class="s">from</span><span class="pi">:</span> <span class="s1">'</span><span class="s">home'</span>
|
||||
<span class="s">action</span><span class="pi">:</span>
|
||||
<span class="s">service</span><span class="pi">:</span> <span class="s">light.turn_off</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">light.entryway</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>It is important to note that each file must contain only <strong>one</strong> entry when using <code class="highlighter-rouge">!include_dir_list</code>.</p>
|
||||
|
||||
<h4><a class="title-link" name="example-include_dir_named" href="#example-include_dir_named"></a> Example: <code class="highlighter-rouge">!include_dir_named</code></h4>
|
||||
|
||||
<p><code class="highlighter-rouge">configuration.yaml</code></p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code>
|
||||
<span class="s">alexa</span><span class="pi">:</span>
|
||||
<span class="s">intents</span><span class="pi">:</span>
|
||||
<span class="s">LocateIntent</span><span class="pi">:</span>
|
||||
<span class="s">action</span><span class="pi">:</span>
|
||||
<span class="s">service</span><span class="pi">:</span> <span class="s">notify.pushover</span>
|
||||
<span class="s">data</span><span class="pi">:</span>
|
||||
<span class="s">message</span><span class="pi">:</span> <span class="s">Your location has been queried via Alexa.</span>
|
||||
<span class="s">speech</span><span class="pi">:</span>
|
||||
<span class="s">type</span><span class="pi">:</span> <span class="s">plaintext</span>
|
||||
<span class="s">text</span><span class="pi">:</span> <span class="pi">></span>
|
||||
<span class="no">{%- for state in states.device_tracker -%}</span>
|
||||
<span class="no">{%- if state.name.lower() == User.lower() -%}</span>
|
||||
<span class="no">{{ state.name }} is at {{ state.state }}</span>
|
||||
<span class="no">{%- endif -%}</span>
|
||||
<span class="no">{%- else -%}</span>
|
||||
<span class="no">I am sorry. Pootie! I do not know where {{User}} is.</span>
|
||||
<span class="no">{%- endfor -%}</span>
|
||||
<span class="s">WhereAreWeIntent</span><span class="pi">:</span>
|
||||
<span class="s">speech</span><span class="pi">:</span>
|
||||
<span class="s">type</span><span class="pi">:</span> <span class="s">plaintext</span>
|
||||
<span class="s">text</span><span class="pi">:</span> <span class="pi">></span>
|
||||
<span class="no">{%- if is_state('device_tracker.iphone', 'home') -%}</span>
|
||||
<span class="no">iPhone is home.</span>
|
||||
<span class="no">{%- else -%}</span>
|
||||
<span class="no">iPhone is not home.</span>
|
||||
<span class="no">{% endif %}</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>can be turned into:</p>
|
||||
|
||||
<p><code class="highlighter-rouge">configuration.yaml</code></p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">alexa</span><span class="pi">:</span>
|
||||
<span class="s">intents</span><span class="pi">:</span> <span class="kt">!include_dir_named</span> <span class="s">alexa/</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p><code class="highlighter-rouge">alexa/LocateIntent.yaml</code></p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code>
|
||||
<span class="s">action</span><span class="pi">:</span>
|
||||
<span class="s">service</span><span class="pi">:</span> <span class="s">notify.pushover</span>
|
||||
<span class="s">data</span><span class="pi">:</span>
|
||||
<span class="s">message</span><span class="pi">:</span> <span class="s">Your location has been queried via Alexa.</span>
|
||||
<span class="s">speech</span><span class="pi">:</span>
|
||||
<span class="s">type</span><span class="pi">:</span> <span class="s">plaintext</span>
|
||||
<span class="s">text</span><span class="pi">:</span> <span class="pi">></span>
|
||||
<span class="no">{%- for state in states.device_tracker -%}</span>
|
||||
<span class="no">{%- if state.name.lower() == User.lower() -%}</span>
|
||||
<span class="no">{{ state.name }} is at {{ state.state }}</span>
|
||||
<span class="no">{%- endif -%}</span>
|
||||
<span class="no">{%- else -%}</span>
|
||||
<span class="no">I am sorry. Pootie! I do not know where {{User}} is.</span>
|
||||
<span class="no">{%- endfor -%}</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p><code class="highlighter-rouge">alexa/WhereAreWeIntent.yaml</code></p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code>
|
||||
<span class="s">speech</span><span class="pi">:</span>
|
||||
<span class="s">type</span><span class="pi">:</span> <span class="s">plaintext</span>
|
||||
<span class="s">text</span><span class="pi">:</span> <span class="pi">></span>
|
||||
<span class="no">{%- if is_state('device_tracker.iphone', 'home') -%}</span>
|
||||
<span class="no">iPhone is home.</span>
|
||||
<span class="no">{%- else -%}</span>
|
||||
<span class="no">iPhone is not home.</span>
|
||||
<span class="no">{% endif %}</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<h4><a class="title-link" name="example-include_dir_merge_list" href="#example-include_dir_merge_list"></a> Example: <code class="highlighter-rouge">!include_dir_merge_list</code></h4>
|
||||
|
||||
<p><code class="highlighter-rouge">configuration.yaml</code></p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">automation</span><span class="pi">:</span>
|
||||
<span class="pi">-</span> <span class="s">alias</span><span class="pi">:</span> <span class="s">Automation 1</span>
|
||||
<span class="s">trigger</span><span class="pi">:</span>
|
||||
<span class="s">platform</span><span class="pi">:</span> <span class="s">state</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">device_tracker.iphone</span>
|
||||
<span class="s">to</span><span class="pi">:</span> <span class="s1">'</span><span class="s">home'</span>
|
||||
<span class="s">action</span><span class="pi">:</span>
|
||||
<span class="s">service</span><span class="pi">:</span> <span class="s">light.turn_on</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">light.entryway</span>
|
||||
<span class="pi">-</span> <span class="s">alias</span><span class="pi">:</span> <span class="s">Automation 2</span>
|
||||
<span class="s">trigger</span><span class="pi">:</span>
|
||||
<span class="s">platform</span><span class="pi">:</span> <span class="s">state</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">device_tracker.iphone</span>
|
||||
<span class="s">from</span><span class="pi">:</span> <span class="s1">'</span><span class="s">home'</span>
|
||||
<span class="s">action</span><span class="pi">:</span>
|
||||
<span class="s">service</span><span class="pi">:</span> <span class="s">light.turn_off</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">light.entryway</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>can be turned into:</p>
|
||||
|
||||
<p><code class="highlighter-rouge">configuration.yaml</code></p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">automation</span><span class="pi">:</span> <span class="kt">!include_dir_merge_list</span> <span class="s">automation/</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p><code class="highlighter-rouge">automation/presence.yaml</code></p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="pi">-</span> <span class="s">alias</span><span class="pi">:</span> <span class="s">Automation 1</span>
|
||||
<span class="s">trigger</span><span class="pi">:</span>
|
||||
<span class="s">platform</span><span class="pi">:</span> <span class="s">state</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">device_tracker.iphone</span>
|
||||
<span class="s">to</span><span class="pi">:</span> <span class="s1">'</span><span class="s">home'</span>
|
||||
<span class="s">action</span><span class="pi">:</span>
|
||||
<span class="s">service</span><span class="pi">:</span> <span class="s">light.turn_on</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">light.entryway</span>
|
||||
<span class="pi">-</span> <span class="s">alias</span><span class="pi">:</span> <span class="s">Automation 2</span>
|
||||
<span class="s">trigger</span><span class="pi">:</span>
|
||||
<span class="s">platform</span><span class="pi">:</span> <span class="s">state</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">device_tracker.iphone</span>
|
||||
<span class="s">from</span><span class="pi">:</span> <span class="s1">'</span><span class="s">home'</span>
|
||||
<span class="s">action</span><span class="pi">:</span>
|
||||
<span class="s">service</span><span class="pi">:</span> <span class="s">light.turn_off</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">light.entryway</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>It is important to note that when using <code class="highlighter-rouge">!include_dir_merge_list</code>, you must include a list in each file (each list item is denoted with a hyphen [-]). Each file may contain one or more entries.</p>
|
||||
|
||||
<h4><a class="title-link" name="example-include_dir_merge_named" href="#example-include_dir_merge_named"></a> Example: <code class="highlighter-rouge">!include_dir_merge_named</code></h4>
|
||||
|
||||
<p><code class="highlighter-rouge">configuration.yaml</code></p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">group</span><span class="pi">:</span>
|
||||
<span class="s">bedroom</span><span class="pi">:</span>
|
||||
<span class="s">name</span><span class="pi">:</span> <span class="s">Bedroom</span>
|
||||
<span class="s">entities</span><span class="pi">:</span>
|
||||
<span class="pi">-</span> <span class="s">light.bedroom_lamp</span>
|
||||
<span class="pi">-</span> <span class="s">light.bedroom_overhead</span>
|
||||
<span class="s">hallway</span><span class="pi">:</span>
|
||||
<span class="s">name</span><span class="pi">:</span> <span class="s">Hallway</span>
|
||||
<span class="s">entities</span><span class="pi">:</span>
|
||||
<span class="pi">-</span> <span class="s">light.hallway</span>
|
||||
<span class="pi">-</span> <span class="s">thermostat.home</span>
|
||||
<span class="s">front_yard</span><span class="pi">:</span>
|
||||
<span class="s">name</span><span class="pi">:</span> <span class="s">Front Yard</span>
|
||||
<span class="s">entities</span><span class="pi">:</span>
|
||||
<span class="pi">-</span> <span class="s">light.front_porch</span>
|
||||
<span class="pi">-</span> <span class="s">light.security</span>
|
||||
<span class="pi">-</span> <span class="s">light.pathway</span>
|
||||
<span class="pi">-</span> <span class="s">sensor.mailbox</span>
|
||||
<span class="pi">-</span> <span class="s">camera.front_porch</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>can be turned into:</p>
|
||||
|
||||
<p><code class="highlighter-rouge">configuration.yaml</code></p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">group</span><span class="pi">:</span> <span class="kt">!include_dir_merge_named</span> <span class="s">group/</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p><code class="highlighter-rouge">group/interior.yaml</code></p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">bedroom</span><span class="pi">:</span>
|
||||
<span class="s">name</span><span class="pi">:</span> <span class="s">Bedroom</span>
|
||||
<span class="s">entities</span><span class="pi">:</span>
|
||||
<span class="pi">-</span> <span class="s">light.bedroom_lamp</span>
|
||||
<span class="pi">-</span> <span class="s">light.bedroom_overhead</span>
|
||||
<span class="s">hallway</span><span class="pi">:</span>
|
||||
<span class="s">name</span><span class="pi">:</span> <span class="s">Hallway</span>
|
||||
<span class="s">entities</span><span class="pi">:</span>
|
||||
<span class="pi">-</span> <span class="s">light.hallway</span>
|
||||
<span class="pi">-</span> <span class="s">thermostat.home</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p><code class="highlighter-rouge">group/exterior.yaml</code></p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">front_yard</span><span class="pi">:</span>
|
||||
<span class="s">name</span><span class="pi">:</span> <span class="s">Front Yard</span>
|
||||
<span class="s">entities</span><span class="pi">:</span>
|
||||
<span class="pi">-</span> <span class="s">light.front_porch</span>
|
||||
<span class="pi">-</span> <span class="s">light.security</span>
|
||||
<span class="pi">-</span> <span class="s">light.pathway</span>
|
||||
<span class="pi">-</span> <span class="s">sensor.mailbox</span>
|
||||
<span class="pi">-</span> <span class="s">camera.front_porch</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
|
||||
</article>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer>
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid">
|
||||
<div class="grid__item">
|
||||
<div class="copyright">
|
||||
<a rel="me" href='https://twitter.com/home_assistant'><i class="icon-twitter"></i></a>
|
||||
<a rel="me" href='https://facebook.com/homeassistantio'><i class="icon-facebook"></i></a>
|
||||
<a rel="me" href='https://plus.google.com/110560654828510104551'><i class="icon-google-plus"></i></a>
|
||||
<a rel="me" href='https://github.com/home-assistant/home-assistant'><i class="icon-github"></i></a>
|
||||
|
||||
<div class="credit">
|
||||
Contact us at <a href='mailto:hello@home-assistant.io'>hello@home-assistant.io</a>.<br>
|
||||
Website powered by <a href='http://jekyllrb.com/'>Jekyll</a> and the <a href='https://github.com/coogie/oscailte'>Oscalite theme</a>.<br />
|
||||
Hosted by <a href='https://pages.github.com/'>GitHub</a> and served by <a href='https://cloudflare.com'>CloudFlare</a>.
|
||||
</div>
|
||||
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a><br /><span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">home-assistant.io</span> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
var _gaq=[['_setAccount','UA-57927901-1'],['_trackPageview']];
|
||||
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
|
||||
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
|
||||
s.parentNode.insertBefore(g,s)}(document,'script'));
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,224 +0,0 @@
|
|||
<!doctype html>
|
||||
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
|
||||
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
|
||||
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
|
||||
<!--[if gt IE 8]><!--> <html> <!--<![endif]-->
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>State Objects - Home Assistant</title>
|
||||
<meta name="author" content="Home Assistant">
|
||||
<meta name="description" content="Describes all there is to know about state objects in Home Assistant.">
|
||||
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<link rel="canonical" href="https://home-assistant.io/topics/state_object/">
|
||||
|
||||
<meta property="fb:app_id" content="338291289691179">
|
||||
<meta property="og:title" content="State Objects">
|
||||
<meta property="og:site_name" content="Home Assistant">
|
||||
<meta property="og:url" content="https://home-assistant.io/topics/state_object/">
|
||||
<meta property="og:type" content="article">
|
||||
<meta property="og:description" content="Describes all there is to know about state objects in Home Assistant.">
|
||||
<meta property="og:image" content="https://home-assistant.io/images/default-social.png">
|
||||
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:site" content="@home_assistant">
|
||||
|
||||
<meta name="twitter:title" content="State Objects">
|
||||
<meta name="twitter:description" content="Describes all there is to know about state objects in Home Assistant.">
|
||||
<meta name="twitter:image" content="https://home-assistant.io/images/default-social.png">
|
||||
|
||||
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet">
|
||||
<link href="/atom.xml" rel="alternate" title="Home Assistant" type="application/atom+xml">
|
||||
<link rel='shortcut icon' href='/images/favicon.ico' />
|
||||
<link rel='icon' type='image/png' href='/images/favicon-192x192.png' sizes='192x192' />
|
||||
</head>
|
||||
|
||||
<body >
|
||||
|
||||
<header>
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid">
|
||||
|
||||
<div class="grid__item three-tenths lap-two-sixths palm-one-whole ha-title">
|
||||
<a href="/" class="site-title">
|
||||
<img width='40' src='/demo/favicon-192x192.png'>
|
||||
<span>Home Assistant</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="grid__item seven-tenths lap-four-sixths palm-one-whole">
|
||||
<nav>
|
||||
<input type="checkbox" id="toggle">
|
||||
<label for="toggle" class="toggle" data-open="Main Menu" data-close="Close Menu"></label>
|
||||
<ul class="menu pull-right">
|
||||
|
||||
<li><a href="/getting-started/">Getting started</a></li>
|
||||
<li><a href="/components/">Components</a></li>
|
||||
<li><a href="/ecosystem/">Ecosystem</a></li>
|
||||
<li><a href="/cookbook/">Examples</a></li>
|
||||
<li><a href="/developers/">Developers</a></li>
|
||||
<li><a href="/blog/">Blog</a></li>
|
||||
<li><a href="/help/">Need help?</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
|
||||
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid grid-center">
|
||||
|
||||
<div class="grid__item two-thirds lap-one-whole palm-one-whole">
|
||||
|
||||
|
||||
<article class="page">
|
||||
|
||||
|
||||
<div class='edit-github'><a href='https://github.com/home-assistant/home-assistant.github.io/tree/current/source/_topics/state_object.markdown'>Edit this page on GitHub</a></div>
|
||||
|
||||
|
||||
|
||||
<header>
|
||||
<h1 class="title indent">
|
||||
State Objects
|
||||
</h1>
|
||||
</header>
|
||||
<hr class="divider">
|
||||
|
||||
|
||||
<p>Your devices are represented in Home Assistant as entities. The entities will write their current state to the state machine for other entities/templates/frontend to access. States are a current representation of the entity.</p>
|
||||
|
||||
<p>If you overwrite a state via the states dev tool or the API, it will not impact the actual device. If the device state is being polled, it will overwrite the state in the state machine the next polling.</p>
|
||||
|
||||
<p>All states will always have an entity id, a state and a timestamp when last updated and last changed.</p>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Field</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><code class="highlighter-rouge">state.state</code></td>
|
||||
<td>String representation of the current state of the entity. Example <code class="highlighter-rouge">off</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code class="highlighter-rouge">state.entity_id</code></td>
|
||||
<td>Entity ID. Format: <code class="highlighter-rouge"><domain>.<object_id></code>. Example: <code class="highlighter-rouge">light.kitchen</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code class="highlighter-rouge">state.domain</code></td>
|
||||
<td>Domain of the entity. Example: <code class="highlighter-rouge">light</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code class="highlighter-rouge">state.object_id</code></td>
|
||||
<td>Object ID of entity. Example: <code class="highlighter-rouge">kitchen</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code class="highlighter-rouge">state.name</code></td>
|
||||
<td>Name of the entity. Based on <code class="highlighter-rouge">friendly_name</code> attribute with fall back to object ID. Example: <code class="highlighter-rouge">Kitchen Ceiling</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code class="highlighter-rouge">state.last_updated</code></td>
|
||||
<td>Time the state was written to the state machine. Note that writing the exact same state including attributes will not result in this field being updated. Example: <code class="highlighter-rouge">14:10:03 13-03-2016</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code class="highlighter-rouge">state.last_changed</code></td>
|
||||
<td>Time the state changed. This is not updated when there are only updated attributes. Example: <code class="highlighter-rouge">14:10:03 13-03-2016</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code class="highlighter-rouge">state.attributes</code></td>
|
||||
<td>A dictionary with extra attributes related to the current state.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p>The attributes of an entity are optional. There are a few attributes that are used by Home Assistant for representing the entity in a specific way. Each component will also have it’s own attributes to represent extra state data about the entity. For example, the light component has attributes for the current brightness and color of the light. When an attribute is not available, Home Assistant will not write it to the state.</p>
|
||||
|
||||
<p>When using templates, attributes will be available by their name. For example <code class="highlighter-rouge">state.attributes.assumed_state</code>.</p>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Attribute</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><code class="highlighter-rouge">friendly_name</code></td>
|
||||
<td>Name of the entity. Example: <code class="highlighter-rouge">Kitchen Ceiling</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code class="highlighter-rouge">icon</code></td>
|
||||
<td>Icon to use for the entity in the frontend. Example: <code class="highlighter-rouge">mdi:home</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code class="highlighter-rouge">hidden</code></td>
|
||||
<td>Boolean if the entity should not be shown in the frontend. Example: <code class="highlighter-rouge">true</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code class="highlighter-rouge">entity_picture</code></td>
|
||||
<td>Url to a picture that should be used instead of showing the domain icon. Example: <code class="highlighter-rouge">http://example.com/picture.jpg</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code class="highlighter-rouge">assumed_state</code></td>
|
||||
<td>Boolean if the current state is an assumption. <a href="https://home-assistant.io/blog/2016/02/12/classifying-the-internet-of-things/#classifiers">More info</a> Example: <code class="highlighter-rouge">True</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code class="highlighter-rouge">unit_of_measurement</code></td>
|
||||
<td>The unit of measurement the state is expressed in. Used for grouping graphs or understanding the entity. Example: <code class="highlighter-rouge">°C</code>.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p>When an attribute contains spaces, you can retrieve it like this: <code class="highlighter-rouge">states.sensor.livingroom.attributes["Battery numeric"]</code>.</p>
|
||||
|
||||
|
||||
</article>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer>
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid">
|
||||
<div class="grid__item">
|
||||
<div class="copyright">
|
||||
<a rel="me" href='https://twitter.com/home_assistant'><i class="icon-twitter"></i></a>
|
||||
<a rel="me" href='https://facebook.com/homeassistantio'><i class="icon-facebook"></i></a>
|
||||
<a rel="me" href='https://plus.google.com/110560654828510104551'><i class="icon-google-plus"></i></a>
|
||||
<a rel="me" href='https://github.com/home-assistant/home-assistant'><i class="icon-github"></i></a>
|
||||
|
||||
<div class="credit">
|
||||
Contact us at <a href='mailto:hello@home-assistant.io'>hello@home-assistant.io</a>.<br>
|
||||
Website powered by <a href='http://jekyllrb.com/'>Jekyll</a> and the <a href='https://github.com/coogie/oscailte'>Oscalite theme</a>.<br />
|
||||
Hosted by <a href='https://pages.github.com/'>GitHub</a> and served by <a href='https://cloudflare.com'>CloudFlare</a>.
|
||||
</div>
|
||||
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a><br /><span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">home-assistant.io</span> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
var _gaq=[['_setAccount','UA-57927901-1'],['_trackPageview']];
|
||||
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
|
||||
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
|
||||
s.parentNode.insertBefore(g,s)}(document,'script'));
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,345 +0,0 @@
|
|||
<!doctype html>
|
||||
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
|
||||
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
|
||||
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
|
||||
<!--[if gt IE 8]><!--> <html> <!--<![endif]-->
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>Templating - Home Assistant</title>
|
||||
<meta name="author" content="Home Assistant">
|
||||
<meta name="description" content="Instructions how to use the templating feature of Home Assistant.">
|
||||
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<link rel="canonical" href="https://home-assistant.io/topics/templating/">
|
||||
|
||||
<meta property="fb:app_id" content="338291289691179">
|
||||
<meta property="og:title" content="Templating">
|
||||
<meta property="og:site_name" content="Home Assistant">
|
||||
<meta property="og:url" content="https://home-assistant.io/topics/templating/">
|
||||
<meta property="og:type" content="article">
|
||||
<meta property="og:description" content="Instructions how to use the templating feature of Home Assistant.">
|
||||
<meta property="og:image" content="https://home-assistant.io/images/default-social.png">
|
||||
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:site" content="@home_assistant">
|
||||
|
||||
<meta name="twitter:title" content="Templating">
|
||||
<meta name="twitter:description" content="Instructions how to use the templating feature of Home Assistant.">
|
||||
<meta name="twitter:image" content="https://home-assistant.io/images/default-social.png">
|
||||
|
||||
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet">
|
||||
<link href="/atom.xml" rel="alternate" title="Home Assistant" type="application/atom+xml">
|
||||
<link rel='shortcut icon' href='/images/favicon.ico' />
|
||||
<link rel='icon' type='image/png' href='/images/favicon-192x192.png' sizes='192x192' />
|
||||
</head>
|
||||
|
||||
<body >
|
||||
|
||||
<header>
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid">
|
||||
|
||||
<div class="grid__item three-tenths lap-two-sixths palm-one-whole ha-title">
|
||||
<a href="/" class="site-title">
|
||||
<img width='40' src='/demo/favicon-192x192.png'>
|
||||
<span>Home Assistant</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="grid__item seven-tenths lap-four-sixths palm-one-whole">
|
||||
<nav>
|
||||
<input type="checkbox" id="toggle">
|
||||
<label for="toggle" class="toggle" data-open="Main Menu" data-close="Close Menu"></label>
|
||||
<ul class="menu pull-right">
|
||||
|
||||
<li><a href="/getting-started/">Getting started</a></li>
|
||||
<li><a href="/components/">Components</a></li>
|
||||
<li><a href="/ecosystem/">Ecosystem</a></li>
|
||||
<li><a href="/cookbook/">Examples</a></li>
|
||||
<li><a href="/developers/">Developers</a></li>
|
||||
<li><a href="/blog/">Blog</a></li>
|
||||
<li><a href="/help/">Need help?</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
|
||||
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid grid-center">
|
||||
|
||||
<div class="grid__item two-thirds lap-one-whole palm-one-whole">
|
||||
|
||||
|
||||
<article class="page">
|
||||
|
||||
|
||||
<div class='edit-github'><a href='https://github.com/home-assistant/home-assistant.github.io/tree/current/source/_topics/templating.markdown'>Edit this page on GitHub</a></div>
|
||||
|
||||
|
||||
|
||||
<header>
|
||||
<h1 class="title indent">
|
||||
Templating
|
||||
</h1>
|
||||
</header>
|
||||
<hr class="divider">
|
||||
|
||||
|
||||
<p>This is an advanced feature of Home Assistant. You’ll need a basic understanding of the following things:</p>
|
||||
|
||||
<ul>
|
||||
<li><a href="/developers/architecture/">Home Assistant architecture</a>, especially states.</li>
|
||||
<li><a href="/topics/state_object/">State object</a></li>
|
||||
</ul>
|
||||
|
||||
<p>Templating is a powerful feature in Home Assistant that allows the user control over information that is going into and out of the system. It is used for:</p>
|
||||
|
||||
<ul>
|
||||
<li>Formatting outgoing messages in, for example, the <a href="/components/notify/">notify</a> and <a href="/components/alexa/">alexa</a> components.</li>
|
||||
<li>Process incoming data from sources that provide raw data, like <a href="/components/mqtt/">MQTT</a>, <a href="/components/sensor.rest/">REST sensor</a>, or the <a href="/components/sensor.command_line/">command line sensor</a>.</li>
|
||||
<li>[Advanced Automation templating]auto-template]</li>
|
||||
</ul>
|
||||
|
||||
<h2><a class="title-link" name="building-templates" href="#building-templates"></a> Building templates</h2>
|
||||
|
||||
<p>Templating in Home Assistant is powered by the <a href="http://jinja.pocoo.org/">Jinja2</a> templating engine. This means that we are using their syntax and make some custom Home Assistant variables available to templates during rendering. We will not go over the basics of the syntax, as Jinja2 does a lot better job at this in their <a href="http://jinja.pocoo.org/docs/dev/templates/">Jinja2 documentation</a>.</p>
|
||||
|
||||
<p class="note">
|
||||
The frontend has a template editor developer tool to help develop and debug templates.
|
||||
</p>
|
||||
|
||||
<p>Templates can get big pretty fast. To keep a clear overview, consider using YAML multiline strings to define your templates:</p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">script</span><span class="pi">:</span>
|
||||
<span class="s">msg_who_is_home</span><span class="pi">:</span>
|
||||
<span class="s">sequence</span><span class="pi">:</span>
|
||||
<span class="pi">-</span> <span class="s">service</span><span class="pi">:</span> <span class="s">notify.notify</span>
|
||||
<span class="s">message</span><span class="pi">:</span> <span class="pi">></span>
|
||||
<span class="no">{% if is_state('device_tracker.paulus', 'home') %}</span>
|
||||
<span class="no">Ha, Paulus is home!</span>
|
||||
<span class="no">{% else %}</span>
|
||||
<span class="no">Paulus is at {{ states('device_tracker.paulus') }}.</span>
|
||||
<span class="no">{% endif %}</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p><a href="http://jinja.pocoo.org/">Jinja2</a> supports a width variety of operations:</p>
|
||||
|
||||
<ul>
|
||||
<li><a href="http://jinja.pocoo.org/docs/dev/templates/#math">Mathematical operation</a></li>
|
||||
<li><a href="http://jinja.pocoo.org/docs/dev/templates/#comparisons">Comparisons</a></li>
|
||||
<li><a href="http://jinja.pocoo.org/docs/dev/templates/#logic">Logic</a></li>
|
||||
</ul>
|
||||
|
||||
<h2><a class="title-link" name="home-assistant-template-extensions" href="#home-assistant-template-extensions"></a> Home Assistant template extensions</h2>
|
||||
|
||||
<p>Home Assistant adds extensions to allow templates to access all of the current states:</p>
|
||||
|
||||
<ul>
|
||||
<li>Iterating <code class="highlighter-rouge">states</code> will yield each state sorted alphabetically by entity ID.</li>
|
||||
<li>Iterating <code class="highlighter-rouge">states.domain</code> will yield each state of that domain sorted alphabetically by entity ID.</li>
|
||||
<li><code class="highlighter-rouge">states.sensor.temperature</code> returns the state object for <code class="highlighter-rouge">sensor.temperature</code>.</li>
|
||||
<li><code class="highlighter-rouge">states('device_tracker.paulus')</code> will return the state string (not the object) of the given entity or <code class="highlighter-rouge">unknown</code> if it doesn’t exist.</li>
|
||||
<li><code class="highlighter-rouge">is_state('device_tracker.paulus', 'home')</code> will test if the given entity is specified state.</li>
|
||||
<li><code class="highlighter-rouge">is_state_attr('device_tracker.paulus', 'battery', 40)</code> will test if the given entity is specified state.</li>
|
||||
<li><code class="highlighter-rouge">now()</code> will be rendered as current time in your time zone.</li>
|
||||
<li><code class="highlighter-rouge">utcnow()</code> will be rendered as UTC time.</li>
|
||||
<li><code class="highlighter-rouge">as_timestamp</code> will convert datetime object or string to UNIX timestamp</li>
|
||||
<li><code class="highlighter-rouge">distance()</code> will measure the distance in meters between home, entity, coordinates.</li>
|
||||
<li><code class="highlighter-rouge">closest()</code> will find the closest entity.</li>
|
||||
<li><code class="highlighter-rouge">relative_time(timestamp)</code> will format the date time as relative time vs now (ie 7 seconds)</li>
|
||||
<li><code class="highlighter-rouge">float</code> will format the output as float.</li>
|
||||
<li><code class="highlighter-rouge">strptime(string, format)</code> will parse a string to a datetime based on a <a href="https://docs.python.org/3.4/library/datetime.html#strftime-and-strptime-behavior">format</a>.</li>
|
||||
<li>Filter <code class="highlighter-rouge">round(x)</code> will convert the input to a number and round it to <code class="highlighter-rouge">x</code> decimals.</li>
|
||||
<li>Filter <code class="highlighter-rouge">timestamp_local</code> will convert an UNIX timestamp to local time/data.</li>
|
||||
<li>Filter <code class="highlighter-rouge">timestamp_utc</code> will convert an UNIX timestamp to UTC time/data.</li>
|
||||
<li>Filter <code class="highlighter-rouge">timestamp_custom(format_string, local_boolean)</code> will convert an UNIX timestamp to a custom format, the use of a local timestamp is default, supporting <a href="https://docs.python.org/3/library/time.html#time.strftime">Python format options</a>.</li>
|
||||
<li>Filter <code class="highlighter-rouge">max</code> will obtain the larget item in a sequence.</li>
|
||||
<li>Filter <code class="highlighter-rouge">min</code> will obtain the smallest item in a sequence.</li>
|
||||
</ul>
|
||||
|
||||
<h2><a class="title-link" name="examples" href="#examples"></a> Examples</h2>
|
||||
|
||||
<h3><a class="title-link" name="states" href="#states"></a> States</h3>
|
||||
<p>The next two statements result in same value if state exists. The second one will result in an error if state does not exist.</p>
|
||||
|
||||
<div class="language-text highlighter-rouge"><pre class="highlight"><code>{{ states('device_tracker.paulus') }}
|
||||
{{ states.device_tracker.paulus.state }}
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<h3><a class="title-link" name="attributes" href="#attributes"></a> Attributes</h3>
|
||||
|
||||
<p>Print an attribute if state is defined</p>
|
||||
|
||||
<div class="language-text highlighter-rouge"><pre class="highlight"><code>{% if states.device_tracker.paulus %}
|
||||
{{ states.device_tracker.paulus.attributes.battery }}
|
||||
{% else %}
|
||||
??
|
||||
{% endif %}
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<h3><a class="title-link" name="sensor-states" href="#sensor-states"></a> Sensor states</h3>
|
||||
|
||||
<p>Print out a list of all the sensor states.</p>
|
||||
|
||||
<div class="language-text highlighter-rouge"><pre class="highlight"><code>{% for state in states.sensor %}
|
||||
{{ state.entity_id }}={{ state.state }},
|
||||
{% endfor %}
|
||||
|
||||
{% if is_state('device_tracker.paulus', 'home') %}
|
||||
Ha, Paulus is home!
|
||||
{% else %}
|
||||
Paulus is at {{ states('device_tracker.paulus') }}.
|
||||
{% endif %}
|
||||
|
||||
{{ states.sensor.temperature | float + 1 }}
|
||||
|
||||
{{ (states.sensor.temperature | float * 10) | round(2) }}
|
||||
|
||||
{% if states('sensor.temperature') | float > 20 %}
|
||||
It is warm!
|
||||
{%endif %}
|
||||
|
||||
{{ as_timestamp(states.binary_sensor.garage_door.last_changed) }}
|
||||
|
||||
{{ as_timestamp(now()) - as_timestamp(states.binary_sensor.garage_door.last_changed) }}
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<h3><a class="title-link" name="distance-examples" href="#distance-examples"></a> Distance examples</h3>
|
||||
|
||||
<p>If only 1 location is passed in, Home Assistant will measure the distance from home.</p>
|
||||
|
||||
<div class="language-text highlighter-rouge"><pre class="highlight"><code>Using Lat Lng coordinates: {{ distance(123.45, 123.45) }}
|
||||
|
||||
Using State: {{ distance(states.device_tracker.paulus) }}
|
||||
|
||||
These can also be combined in any combination:
|
||||
{{ distance(123.45, 123.45, 'device_tracker.paulus') }}
|
||||
{{ distance('device_tracker.anne_therese', 'device_tracker.paulus') }}
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<h3><a class="title-link" name="closest-examples" href="#closest-examples"></a> Closest examples</h3>
|
||||
|
||||
<p>Find entities closest to the Home Assistant location:</p>
|
||||
|
||||
<div class="language-text highlighter-rouge"><pre class="highlight"><code>Query all entities: {{ closest(states) }}
|
||||
Query all entities of a specific domain: {{ closest('states.device_tracker') }}
|
||||
Query all entities in group.children: {{ closest('group.children') }}
|
||||
Query all entities in group.children: {{ closest(states.group.children) }}
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>Find entities closest to a coordinate or another entity. All previous arguments still apply for 2nd argument.</p>
|
||||
|
||||
<div class="language-text highlighter-rouge"><pre class="highlight"><code>Closest to a coordinate: {{ closest(23.456, 23.456, 'group.children') }}
|
||||
Closest to an entity: {{ closest('zone.school', 'group.children') }}
|
||||
Closest to an entity: {{ closest(states.zone.school, 'group.children') }}
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<h3><a class="title-link" name="combined" href="#combined"></a> Combined</h3>
|
||||
<p>Since closest returns a state, we can combine it with distance too.</p>
|
||||
|
||||
<div class="language-text highlighter-rouge"><pre class="highlight"><code>{{ closest(states).name }} is {{ distance(closest(states)) }} meters away.
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<h2><a class="title-link" name="processing-incoming-data" href="#processing-incoming-data"></a> Processing incoming data</h2>
|
||||
|
||||
<p>The other part of templating is processing incoming data. It will allow you to modify incoming data and extract only the data you care about. This will work only for platforms and components that mentioned support for this in their documentation.</p>
|
||||
|
||||
<p>It depends per component or platform, but it is common to be able to define a template using the <code class="highlighter-rouge">value_template</code> configuration key. When a new value arrives, your template will be rendered while having access to the following values on top of the usual Home Assistant extensions:</p>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Variable</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><code class="highlighter-rouge">value</code></td>
|
||||
<td>The incoming value.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code class="highlighter-rouge">value_json</code></td>
|
||||
<td>The incoming value parsed as JSON.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="language-text highlighter-rouge"><pre class="highlight"><code># Incoming value:
|
||||
{"primes": [2, 3, 5, 7, 11, 13]}
|
||||
|
||||
# Extract third prime number
|
||||
{{ value_json.primes[2] }}
|
||||
|
||||
# Format output
|
||||
{{ "%+.1f" | value_json }}
|
||||
|
||||
# Math
|
||||
{{ value_json | float * 1024 }}
|
||||
{{ float(value_json) * (2**10) }}
|
||||
|
||||
# Timestamps
|
||||
{{ value_json.tst | timestamp_local }}
|
||||
{{ value_json.tst | timestamp_utc }}
|
||||
{{ value_json.tst | timestamp_custom('%Y' True) }}
|
||||
|
||||
# Square bracket notation
|
||||
{{ value_json["001"] }}
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
|
||||
</article>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer>
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid">
|
||||
<div class="grid__item">
|
||||
<div class="copyright">
|
||||
<a rel="me" href='https://twitter.com/home_assistant'><i class="icon-twitter"></i></a>
|
||||
<a rel="me" href='https://facebook.com/homeassistantio'><i class="icon-facebook"></i></a>
|
||||
<a rel="me" href='https://plus.google.com/110560654828510104551'><i class="icon-google-plus"></i></a>
|
||||
<a rel="me" href='https://github.com/home-assistant/home-assistant'><i class="icon-github"></i></a>
|
||||
|
||||
<div class="credit">
|
||||
Contact us at <a href='mailto:hello@home-assistant.io'>hello@home-assistant.io</a>.<br>
|
||||
Website powered by <a href='http://jekyllrb.com/'>Jekyll</a> and the <a href='https://github.com/coogie/oscailte'>Oscalite theme</a>.<br />
|
||||
Hosted by <a href='https://pages.github.com/'>GitHub</a> and served by <a href='https://cloudflare.com'>CloudFlare</a>.
|
||||
</div>
|
||||
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a><br /><span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">home-assistant.io</span> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
var _gaq=[['_setAccount','UA-57927901-1'],['_trackPageview']];
|
||||
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
|
||||
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
|
||||
s.parentNode.insertBefore(g,s)}(document,'script'));
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue