Site updated at 2016-08-22 08:21:42 UTC

This commit is contained in:
Travis CI 2016-08-22 08:21:43 +00:00
parent f9d65cbe57
commit 4acb07bf8e
559 changed files with 18878 additions and 21688 deletions

View file

@ -115,20 +115,18 @@ The frontend has a template editor developer tool to help develop and debug temp
<p>Templates can get big pretty fast. To keep a clear overview, consider using YAML multiline strings to define your templates:</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="key">script</span>:
<span class="key">msg_who_is_home</span>:
<span class="key">sequence</span>:
- <span class="string"><span class="content">service: notify.notify</span></span>
<span class="key">data</span>:
<span class="key">message</span>: <span class="string"><span class="delimiter">&gt;</span><span class="content">
{% if is_state('device_tracker.paulus', 'home') %}
Ha, Paulus is home!
{% else %}
Paulus is at {{ states('device_tracker.paulus')) }}.
{% endif %}</span></span>
</pre></div>
</div>
<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">data</span><span class="pi">:</span>
<span class="s">message</span><span class="pi">:</span> <span class="pi">&gt;</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>
@ -144,22 +142,22 @@ The frontend has a template editor developer tool to help develop and debug temp
<p>Home Assistant adds extensions to allow templates to access all of the current states:</p>
<ul>
<li>Iterating <code>states</code> will yield each state sorted alphabetically by entity ID.</li>
<li>Iterating <code>states.domain</code> will yield each state of that domain sorted alphabetically by entity ID.</li>
<li><code>states.sensor.temperature</code> returns the state object for <code>sensor.temperature</code>.</li>
<li><code>states('device_tracker.paulus')</code> will return the state string (not the object) of the given entity or <code>unknown</code> if it doesnt exist.</li>
<li><code>is_state('device_tracker.paulus', 'home')</code> will test if the given entity is specified state.</li>
<li><code>is_state_attr('device_tracker.paulus', 'battery', 40)</code> will test if the given entity is specified state.</li>
<li><code>now</code> will be rendered as current time in your time zone.</li>
<li><code>utcnow</code> will be rendered as UTC time.</li>
<li><code>as_timestamp</code> will convert datetime object or string to UNIX timestamp</li>
<li><code>distance()</code> will measure the distance in meters between home, entity, coordinates.</li>
<li><code>closest()</code> will find the closest entity.</li>
<li><code>relative_time(timestamp)</code> will format the date time as relative time vs now (ie 7 seconds)</li>
<li><code>float</code> will format the output as float.</li>
<li>Filter <code>round(x)</code> will convert the input to a number and round it to <code>x</code> decimals.</li>
<li>Filter <code>timestamp_local</code> will convert an UNIX timestamp to local time/data.</li>
<li>Filter <code>timestamp_utc</code> will convert an UNIX timestamp to UTC time/data.</li>
<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 doesnt 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>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>
</ul>
<h2><a class="title-link" name="examples" href="#examples"></a> Examples</h2>
@ -167,36 +165,28 @@ The frontend has a template editor developer tool to help develop and debug temp
<h3><a class="title-link" name="states" href="#states"></a> States</h3>
<p>Next two statements result in same value if state exists. Second one will result in an error if state does not exist.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre>
{{ states('device_tracker.paulus') }}
<div class="language-text highlighter-rouge"><pre class="highlight"><code>{{ states('device_tracker.paulus') }}
{{ states.device_tracker.paulus.state }}
</pre></div>
</div>
</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="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre>
{% if states.device_tracker.paulus %}
<div class="language-text highlighter-rouge"><pre class="highlight"><code>{% if states.device_tracker.paulus %}
{{ states.device_tracker.paulus.attributes.battery }}
{% else %}
??
{% endif %}
</pre></div>
</div>
</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="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre>
{% for state in states.sensor %}
<div class="language-text highlighter-rouge"><pre class="highlight"><code>{% for state in states.sensor %}
{{ state.entity_id }}={{ state.state }},
{% endfor %}
@ -217,68 +207,54 @@ The frontend has a template editor developer tool to help develop and debug temp
{{ as_timestamp(states.binary_sensor.garage_door.last_changed) }}
{{ as_timestamp(now) - as_timestamp(states.binary_sensor.garage_door.last_changed) }}
</pre></div>
</div>
</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 will measure the distance from home.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre>
Using Lat Lng coordinates: {{ distance(123.45, 123.45) }}
<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') }}
</pre></div>
</div>
</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="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre>
Query all entities: {{ closest(states) }}
<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) }}
</pre></div>
</div>
</code></pre>
</div>
<p>Find entities closest to a coordinate or another entity. All previous arguments still apply for 2nd argument.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre>
Closest to a coordinate: {{ closest(23.456, 23.456, 'group.children') }}
<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') }}
</pre></div>
</div>
</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="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre>
{{ closest(states).name }} is {{ distance(closest(states)) }} meters away.
</pre></div>
</div>
<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>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>
<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>
@ -289,25 +265,24 @@ Closest to an entity: {{ closest(states.zone.school, 'group.children') }}
</thead>
<tbody>
<tr>
<td><code>value</code></td>
<td><code class="highlighter-rouge">value</code></td>
<td>The incoming value.</td>
</tr>
<tr>
<td><code>value_json</code></td>
<td><code class="highlighter-rouge">value_json</code></td>
<td>The incoming value parsed as JSON.</td>
</tr>
</tbody>
</table>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre># Incoming value:
{&quot;primes&quot;: [2, 3, 5, 7, 11, 13]}
<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
{{ &quot;%+.1f&quot; | value_json }}
{{ "%+.1f" | value_json }}
# Math
{{ value_json | float * 1024 }}
@ -316,8 +291,7 @@ Closest to an entity: {{ closest(states.zone.school, 'group.children') }}
# Timestamps
{{ value_json.tst | timestamp_local }}
{{ value_json.tst | timestamp_utc }}
</pre></div>
</div>
</code></pre>
</div>