Site updated at 2016-05-07 20:05:09 UTC

This commit is contained in:
Travis CI 2016-05-07 20:05:09 +00:00
parent 734e3c6515
commit 890a79eba3
300 changed files with 7312 additions and 1175 deletions

View file

@ -136,7 +136,7 @@
<li><a href='/getting-started/devices/'>Setting up devices </a></li>
<li><a href='/getting-started/customizing-devices/'>Customizing devices and services </a></li>
<li><a href='/getting-started/presence-detection/'>Presence Detection </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting configuration.yaml </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting </a></li>
</ul>
</li>
<li>
@ -146,6 +146,14 @@
<li><a href='/getting-started/automation-trigger/'>Triggers </a></li>
<li><a href='/getting-started/automation-condition/'>Conditions </a></li>
<li><a href='/getting-started/automation-action/'>Actions </a></li>
<li><a href='/getting-started/automation-templating/'>Templates </a></li>
</ul>
</li>
<li>
<a href='/getting-started/scripts/'>Scripts </a>
<ul>
<li><a href='/getting-started/scripts-service-calls/'>Service Calls </a></li>
<li><a href='/getting-started/scripts-conditions/'>Conditions </a></li>
</ul>
</li>
<li>

View file

@ -89,11 +89,16 @@
<hr class="divider">
<p>When an automation rule fires, it calls a service. For this service you can specify the entity_id that it should apply to and optional service parameters (to specify for example the brightness).</p>
<p>The action of an automation rule is what is being executed when a rule fires. The action part follows the <a href="/getting-started/scripts/">script syntax</a> which can be used to interact with anything via services or events. For services you can specify the entity_id that it should apply to and optional service parameters (to specify for example the brightness).</p>
<p>You can also call the service to activate <a href="/components/scene/">a scene</a> which will allow you to define how you want your devices to be and have Home Assistant call the right services.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="key">automation</span>:
<span class="comment"># Change the light in the kitchen and living room to 150 brightness and color red.</span>
<span class="key">trigger</span>:
<span class="key">platform</span>: <span class="string"><span class="content">sun</span></span>
<span class="key">event</span>: <span class="string"><span class="content">sunset</span></span>
<span class="key">action</span>:
<span class="key">service</span>: <span class="string"><span class="content">homeassistant.turn_on</span></span>
<span class="key">entity_id</span>:
@ -102,23 +107,26 @@
<span class="key">data</span>:
<span class="key">brightness</span>: <span class="string"><span class="content">150</span></span>
<span class="key">rgb_color</span>: <span class="string"><span class="content">[255, 0, 0]</span></span>
</pre></div>
</div>
</div>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="key">automation</span>:
<span class="key">automation 2</span>:
<span class="comment"># Notify me on my mobile phone of an event</span>
<span class="key">trigger</span>:
<span class="key">platform</span>: <span class="string"><span class="content">sun</span></span>
<span class="key">event</span>: <span class="string"><span class="content">sunset</span></span>
<span class="key">offset</span>: <span class="string"><span class="content">-00:30</span></span>
<span class="key">action</span>:
<span class="key">service</span>: <span class="string"><span class="content">notify.notify</span></span>
<span class="key">data</span>:
<span class="key">message</span>: <span class="string"><span class="content">Something just happened, better take a look!</span></span>
<span class="comment"># Actions are scripts so can also be a list of actions</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="content">Beautiful sunset!</span></span>
- <span class="string"><span class="content">delay: 0:35</span></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="content">Oh wow you really missed something great.</span></span>
</pre></div>
</div>
</div>
<p>If you want to specify multiple services to be called, or to include a delay, have a look at the <a href="/components/script/">script component</a>. If you want to describe the desired state of certain entities, check out the <a href="/components/scene/">scene component</a>.</p>
</article>
@ -152,7 +160,7 @@
<li><a href='/getting-started/devices/'>Setting up devices </a></li>
<li><a href='/getting-started/customizing-devices/'>Customizing devices and services </a></li>
<li><a href='/getting-started/presence-detection/'>Presence Detection </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting configuration.yaml </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting </a></li>
</ul>
</li>
<li>
@ -162,6 +170,14 @@
<li><a href='/getting-started/automation-trigger/'>Triggers </a></li>
<li><a href='/getting-started/automation-condition/'>Conditions </a></li>
<li><a class='active' href='/getting-started/automation-action/'>Actions </a></li>
<li><a href='/getting-started/automation-templating/'>Templates </a></li>
</ul>
</li>
<li>
<a href='/getting-started/scripts/'>Scripts </a>
<ul>
<li><a href='/getting-started/scripts-service-calls/'>Service Calls </a></li>
<li><a href='/getting-started/scripts-conditions/'>Conditions </a></li>
</ul>
</li>
<li>

View file

@ -91,20 +91,6 @@
<p>Conditions are an optional part of an automation rule and be used to prevent an action from happening when triggered. Conditions look very similar to triggers but are very different. A trigger will look at events happening in the system while a condition only looks at how the system looks right now. A trigger can observe that a switch is being turned on. A condition can only see if a switch is currently on or off.</p>
<p>An automation rule can have multiple conditions. By default the action will only fire if all conditions pass. An optional key <code>condition_type: 'or'</code> can be set on the automation rule to fire action if any condition matches. In the example below, the automation would trigger if the time is before 05:00 <em>OR</em> after 20:00.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="key">automation</span>:
<span class="key">condition_type</span>: <span class="string"><span class="content">or</span></span>
<span class="key">condition</span>:
- <span class="string"><span class="content">platform: time</span></span>
<span class="key">before</span>: <span class="string"><span class="content">'05:00'</span></span>
- <span class="string"><span class="content">platform: time</span></span>
<span class="key">after</span>: <span class="string"><span class="content">'20:00'</span></span>
</pre></div>
</div>
</div>
<p>If your triggers and conditions are exactly the same, you can use a shortcut to specify conditions. In this case, triggers that are not valid conditions will be ignored.</p>
<div class="highlighter-coderay"><div class="CodeRay">
@ -114,106 +100,8 @@
</div>
</div>
<h4><a class="title-link" name="numeric-state-condition" href="#numeric-state-condition"></a> Numeric state condition</h4>
<p>The available conditions for an automation are the same as for the script syntax. So see that page for a <a href="/getting-started/scripts-conditions/">full list of available conditions</a>.</p>
<p>This type of condition attempts to parse the state of specified entity as a number and triggers if the value matches all of the above or below thresholds.<br />
Either <code>above</code> or <code>below</code>, or both need to be specified. If both are used, the condition is true when the value is &gt;= <code>before</code> *and** &lt; <code>after</code>.<br />
You can optionally use a <code>value_template</code> to make the value of the entity the same type of value as the condition.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="key">automation</span>:
<span class="key">condition</span>:
<span class="key">platform</span>: <span class="string"><span class="content">numeric_state</span></span>
<span class="key">entity_id</span>: <span class="string"><span class="content">sensor.temperature</span></span>
<span class="key">above</span>: <span class="string"><span class="content">17</span></span>
<span class="key">below</span>: <span class="string"><span class="content">25</span></span>
</pre></div>
</div>
</div>
<h4><a class="title-link" name="state-condition" href="#state-condition"></a> State condition</h4>
<p>Tests if an entity is a specified state.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="key">automation</span>:
<span class="key">condition</span>:
<span class="key">platform</span>: <span class="string"><span class="content">state</span></span>
<span class="key">entity_id</span>: <span class="string"><span class="content">device_tracker.paulus</span></span>
<span class="key">state</span>: <span class="string"><span class="content">not_home</span></span>
<span class="comment"># optional: trigger only if state was this for last X time.</span>
<span class="key">for</span>:
<span class="key">hours</span>: <span class="string"><span class="content">1</span></span>
<span class="key">minutes</span>: <span class="string"><span class="content">10</span></span>
<span class="key">seconds</span>: <span class="string"><span class="content">5</span></span>
</pre></div>
</div>
</div>
<h4><a class="title-link" name="sun-condition" href="#sun-condition"></a> Sun condition</h4>
<p>The sun condition can test if the sun has already set or risen when a trigger occurs. The <code>before</code> and <code>after</code> keys can only be set to <code>sunset</code> or <code>sunrise</code>. They have a corresponding optional offset value (<code>before_offset</code>, <code>after_offset</code>) that can be added, similar to the <a href="#sun-trigger">sun trigger</a>.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="key">automation</span>:
<span class="key">condition</span>:
<span class="key">platform</span>: <span class="string"><span class="content">sun</span></span>
<span class="key">after</span>: <span class="string"><span class="content">sunset</span></span>
<span class="comment"># Optional offset value</span>
<span class="key">after_offset</span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">-1:00:00</span><span class="delimiter">&quot;</span></span>
</pre></div>
</div>
</div>
<h4><a class="title-link" name="template-condition" href="#template-condition"></a> Template condition</h4>
<p>The template condition will test if the [given template][template] renders a value equal to true. This is achieved by having the template result in a true boolean expression or by having the template render true.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="key">automation</span>:
<span class="key">condition</span>:
<span class="key">platform</span>: <span class="string"><span class="content">template</span></span>
<span class="key">value_template</span>: <span class="string"><span class="content">'{{ state.attributes.battery &gt; 50 }}'</span></span>
<span class="comment"># Or value_template could be:</span>
<span class="comment"># {% if state.attributes.battery &gt; 50 %}true{% else %}false{% endif %}</span>
</pre></div>
</div>
</div>
<h4><a class="title-link" name="time-condition" href="#time-condition"></a> Time condition</h4>
<p>The time condition can test if it is after a specified time, before a specified time or if it is a certain day of the week</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="key">automation</span>:
<span class="key">condition</span>:
<span class="key">platform</span>: <span class="string"><span class="content">time</span></span>
<span class="comment"># At least one of the following is required.</span>
<span class="key">after</span>: <span class="string"><span class="content">'15:00:00'</span></span>
<span class="key">before</span>: <span class="string"><span class="content">'23:00:00'</span></span>
<span class="key">weekday</span>:
- <span class="string"><span class="content">mon</span></span>
- <span class="string"><span class="content">wed</span></span>
- <span class="string"><span class="content">fri</span></span>
</pre></div>
</div>
</div>
<p>Valid values for <code>weekday</code> are (<code>sun</code>, <code>mon</code>, <code>tue</code>, <code>wed</code>, <code>thu</code>, <code>fri</code> &amp; <code>sat</code>)</p>
<h4><a class="title-link" name="zone-condition" href="#zone-condition"></a> Zone condition</h4>
<p>Zone conditions test if an entity is in a certain zone. For zone automation to work, you need to have setup a device tracker platform that supports reporting GPS coordinates. Currently this is limited to the <a href="/components/device_tracker.owntracks/">OwnTracks platform</a> and the <a href="/components/device_tracker.icloud/">iCloud platform</a>.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="key">automation</span>:
<span class="key">condition</span>:
<span class="key">platform</span>: <span class="string"><span class="content">zone</span></span>
<span class="key">entity_id</span>: <span class="string"><span class="content">device_tracker.paulus</span></span>
<span class="key">zone</span>: <span class="string"><span class="content">zone.home</span></span>
</pre></div>
</div>
</div>
</article>
@ -248,7 +136,7 @@ You can optionally use a <code>value_template</code> to make the value of the en
<li><a href='/getting-started/devices/'>Setting up devices </a></li>
<li><a href='/getting-started/customizing-devices/'>Customizing devices and services </a></li>
<li><a href='/getting-started/presence-detection/'>Presence Detection </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting configuration.yaml </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting </a></li>
</ul>
</li>
<li>
@ -258,6 +146,14 @@ You can optionally use a <code>value_template</code> to make the value of the en
<li><a href='/getting-started/automation-trigger/'>Triggers </a></li>
<li><a class='active' href='/getting-started/automation-condition/'>Conditions </a></li>
<li><a href='/getting-started/automation-action/'>Actions </a></li>
<li><a href='/getting-started/automation-templating/'>Templates </a></li>
</ul>
</li>
<li>
<a href='/getting-started/scripts/'>Scripts </a>
<ul>
<li><a href='/getting-started/scripts-service-calls/'>Service Calls </a></li>
<li><a href='/getting-started/scripts-conditions/'>Conditions </a></li>
</ul>
</li>
<li>

View file

@ -160,7 +160,7 @@
<p>Christmas is coming along and you decide to buy a remote switch to control the Christmas lights from Home Assistant. You cant claim to live in the house of the future if youre still manually turning on your Christmas lights!</p>
<p>We hook the switch up to Home Assistant and grab the entity ID0 from the developer tools: <code>switch.christmas_lights</code>. We will update the group to include the switch and will change our action. We are no longer able to call <code>light.turn_on</code> because we also want to turn on a switch. This is where <code>homeassistant.turn_on</code> comes to the rescue. This service is capable of turning any entity on.</p>
<p>We hook the switch up to Home Assistant and grab the entity ID from the developer tools: <code>switch.christmas_lights</code>. We will update the group to include the switch and will change our action. We are no longer able to call <code>light.turn_on</code> because we also want to turn on a switch. This is where <code>homeassistant.turn_on</code> comes to the rescue. This service is capable of turning any entity on.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="comment"># Example configuration.yaml entry</span>
@ -187,6 +187,16 @@
</div>
</div>
<h3><a class="title-link" name="learn-more" href="#learn-more"></a> Learn more</h3>
<ul>
<li><a href="/getting-started/automation-trigger/">Triggers</a></li>
<li><a href="/getting-started/automation-condition/">Conditions</a></li>
<li><a href="/getting-started/automation-action/">Actions</a></li>
<li><a href="/getting-started/automation-templating/">Templating</a> (advanced)</li>
</ul>
</article>
@ -220,7 +230,7 @@
<li><a href='/getting-started/devices/'>Setting up devices </a></li>
<li><a href='/getting-started/customizing-devices/'>Customizing devices and services </a></li>
<li><a href='/getting-started/presence-detection/'>Presence Detection </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting configuration.yaml </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting </a></li>
</ul>
</li>
<li>
@ -230,6 +240,14 @@
<li><a href='/getting-started/automation-trigger/'>Triggers </a></li>
<li><a href='/getting-started/automation-condition/'>Conditions </a></li>
<li><a href='/getting-started/automation-action/'>Actions </a></li>
<li><a href='/getting-started/automation-templating/'>Templates </a></li>
</ul>
</li>
<li>
<a href='/getting-started/scripts/'>Scripts </a>
<ul>
<li><a href='/getting-started/scripts-service-calls/'>Service Calls </a></li>
<li><a href='/getting-started/scripts-conditions/'>Conditions </a></li>
</ul>
</li>
<li>

View file

@ -178,7 +178,7 @@
<li><a href='/getting-started/devices/'>Setting up devices </a></li>
<li><a href='/getting-started/customizing-devices/'>Customizing devices and services </a></li>
<li><a href='/getting-started/presence-detection/'>Presence Detection </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting configuration.yaml </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting </a></li>
</ul>
</li>
<li>
@ -188,6 +188,14 @@
<li><a href='/getting-started/automation-trigger/'>Triggers </a></li>
<li><a href='/getting-started/automation-condition/'>Conditions </a></li>
<li><a href='/getting-started/automation-action/'>Actions </a></li>
<li><a href='/getting-started/automation-templating/'>Templates </a></li>
</ul>
</li>
<li>
<a href='/getting-started/scripts/'>Scripts </a>
<ul>
<li><a href='/getting-started/scripts-service-calls/'>Service Calls </a></li>
<li><a href='/getting-started/scripts-conditions/'>Conditions </a></li>
</ul>
</li>
<li>

View file

@ -0,0 +1,441 @@
<!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>Automation Templating - Home Assistant</title>
<meta name="author" content="Paulus Schoutsen">
<meta name="description" content="Advanced automation documentation using templating.">
<meta name="viewport" content="width=device-width">
<link rel="canonical" href="https://home-assistant.io/getting-started/automation-templating/">
<meta property="fb:app_id" content="338291289691179">
<meta property="og:title" content="Automation Templating">
<meta property="og:site_name" content="Home Assistant">
<meta property="og:url" content="https://home-assistant.io/getting-started/automation-templating/">
<meta property="og:type" content="website">
<meta property="og:description" content="Advanced automation documentation using templating.">
<meta property="og:image" content="https://home-assistant.io/images/home-assistant-logo-2164x2164.png">
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@home_assistant">
<meta name="twitter:title" content="Automation Templating">
<meta name="twitter:description" content="Advanced automation documentation using templating.">
<meta name="twitter:image" content="https://home-assistant.io/images/home-assistant-logo-2164x2164.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='/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">
Automation Templating
</h1>
</header>
<hr class="divider">
<p>In Home Assistant 0.19 we introduced a new powerful feature: variables in scripts and automations. This makes it possible to adjust your condition and action based on the information of the trigger.</p>
<p>The trigger data made is available during template rendering as the <code>trigger</code> variable.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="comment"># Example configuration.yaml entries</span>
<span class="key">automation</span>:
<span class="key">trigger</span>:
<span class="key">platform</span>: <span class="string"><span class="content">state</span></span>
<span class="key">entity_id</span>: <span class="string"><span class="content">device_tracker.paulus</span></span>
<span class="key">action</span>:
<span class="key">service</span>: <span class="string"><span class="content">notify.notify</span></span>
<span class="key">data_template</span>:
<span class="key">message</span>: <span class="string"><span class="delimiter">&gt;</span><span class="content">
Paulus just changed from {{ trigger.from_state.state }}
to {{ trigger.to_state.state }}</span></span>
<span class="key">automation 2</span>:
<span class="key">trigger</span>:
<span class="key">platform</span>: <span class="string"><span class="content">mqtt</span></span>
<span class="key">topic</span>: <span class="string"><span class="content">/notify/+</span></span>
<span class="key">action</span>:
<span class="key">service_template</span>: <span class="string"><span class="delimiter">&gt;</span><span class="content">
notify.{{ trigger.topic.split('/')[-1] }}</span></span>
<span class="key">data_template</span>:
<span class="key">message</span>: <span class="string"><span class="content">{% raw %}{{ trigger.payload }}</span></span>
</pre></div>
</div>
</div>
<h3><a class="title-link" name="available-trigger-data" href="#available-trigger-data"></a> Available Trigger Data</h3>
<p>The following tables show the available trigger data per platform.</p>
<table>
<thead>
<tr>
<th>Template variable</th>
<th>Data</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>trigger.platform</code></td>
<td>Hardcoded: <code>event</code>.</td>
</tr>
<tr>
<td><code>trigger.event</code></td>
<td>Event object that matched.</td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th>Template variable</th>
<th>Data</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>trigger.platform</code></td>
<td>Hardcoded: <code>mqtt</code>.</td>
</tr>
<tr>
<td><code>trigger.topic</code></td>
<td>Topic that received payload.</td>
</tr>
<tr>
<td><code>trigger.payload</code></td>
<td>Payload.</td>
</tr>
<tr>
<td><code>trigger.qos</code></td>
<td>QOS of payload.</td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th>Template variable</th>
<th>Data</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>trigger.platform</code></td>
<td>Hardcoded: <code>numeric_state</code></td>
</tr>
<tr>
<td><code>trigger.entity_id</code></td>
<td>Entity ID that we observe.</td>
</tr>
<tr>
<td><code>trigger.below</code></td>
<td>The below treshold, if any.</td>
</tr>
<tr>
<td><code>trigger.above</code></td>
<td>The above treshold, if any.</td>
</tr>
<tr>
<td><code>trigger.from_state</code></td>
<td>The previous state of the entity.</td>
</tr>
<tr>
<td><code>trigger.to_state</code></td>
<td>The new state that triggered trigger.</td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th>Template variable</th>
<th>Data</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>trigger.platform</code></td>
<td>Hardcoded: <code>state</code></td>
</tr>
<tr>
<td><code>trigger.entity_id</code></td>
<td>Entity ID that we observe.</td>
</tr>
<tr>
<td><code>trigger.from_state</code></td>
<td>The previous state of the entity.</td>
</tr>
<tr>
<td><code>trigger.to_state</code></td>
<td>The new state that triggered trigger.</td>
</tr>
<tr>
<td><code>trigger.for</code></td>
<td>Timedelta object how long state has been to state, if any.</td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th>Template variable</th>
<th>Data</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>trigger.platform</code></td>
<td>Hardcoded: <code>sun</code></td>
</tr>
<tr>
<td><code>trigger.event</code></td>
<td>The event that just happened: <code>sunset</code> or <code>sunrise</code>.</td>
</tr>
<tr>
<td><code>trigger.offset</code></td>
<td>Timedelta object with offset to the event, if any.</td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th>Template variable</th>
<th>Data</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>trigger.platform</code></td>
<td>Hardcoded: <code>template</code></td>
</tr>
<tr>
<td><code>trigger.entity_id</code></td>
<td>Entity ID that caused change.</td>
</tr>
<tr>
<td><code>trigger.from_state</code></td>
<td>Previous state of entity that caused change.</td>
</tr>
<tr>
<td><code>trigger.to_state</code></td>
<td>New state of entity that caused template to change.</td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th>Template variable</th>
<th>Data</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>trigger.platform</code></td>
<td>Hardcoded: <code>time</code></td>
</tr>
<tr>
<td><code>trigger.now</code></td>
<td>DateTime object that triggered the time trigger.</td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th>Template variable</th>
<th>Data</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>trigger.platform</code></td>
<td>Hardcoded: <code>zone</code></td>
</tr>
<tr>
<td><code>trigger.entity_id</code></td>
<td>Entity ID that we are observing.</td>
</tr>
<tr>
<td><code>trigger.from_state</code></td>
<td>Previous state of the entity.</td>
</tr>
<tr>
<td><code>trigger.to_state</code></td>
<td>New state of the entity.</td>
</tr>
<tr>
<td><code>trigger.zone</code></td>
<td>State object of zone</td>
</tr>
<tr>
<td><code>trigger.event</code></td>
<td>Event that trigger observed: <code>enter</code> or <code>leave</code>.</td>
</tr>
</tbody>
</table>
</article>
</div>
<aside id="sidebar" class="grid__item one-third lap-one-whole palm-one-whole">
<div class="grid">
<section class="aside-module grid__item one-whole lap-one-half">
<div class='edit-github'><a href='https://github.com/home-assistant/home-assistant.io/tree/master/source/getting-started/automation-templating.markdown'>Edit this page on GitHub</a></div>
<div class='section'>
<h1 class="title delta">Getting Started Guide</h1>
<ul class='divided sidebar-menu'>
<li>
<a href='/getting-started/'>Installation </a>
<ul>
<li><a href='/getting-started/installation-raspberry-pi/'>Raspberry Pi </a></li>
<li><a href='/getting-started/installation-docker/'>Docker </a></li>
<li><a href='/getting-started/installation-synology/'>Synology NAS </a></li>
<li><a href='/getting-started/installation-virtualenv/'>VirtualEnv Linux Instructions </a></li>
<li><a href='/getting-started/troubleshooting/'>Troubleshooting </a></li>
</ul>
</li>
<li>
Configuration
<ul>
<li><a href='/getting-started/configuration/'>Configuration.yaml </a></li>
<li><a href='/getting-started/devices/'>Setting up devices </a></li>
<li><a href='/getting-started/customizing-devices/'>Customizing devices and services </a></li>
<li><a href='/getting-started/presence-detection/'>Presence Detection </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting </a></li>
</ul>
</li>
<li>
<a href='/getting-started/automation/'>Automation </a>
<ul>
<li><a href='/getting-started/automation-create-first/'>Tutorial </a></li>
<li><a href='/getting-started/automation-trigger/'>Triggers </a></li>
<li><a href='/getting-started/automation-condition/'>Conditions </a></li>
<li><a href='/getting-started/automation-action/'>Actions </a></li>
<li><a class='active' href='/getting-started/automation-templating/'>Templates </a></li>
</ul>
</li>
<li>
<a href='/getting-started/scripts/'>Scripts </a>
<ul>
<li><a href='/getting-started/scripts-service-calls/'>Service Calls </a></li>
<li><a href='/getting-started/scripts-conditions/'>Conditions </a></li>
</ul>
</li>
<li>
<a href='/getting-started/autostart/'>Auto-start Home Assistant </a>
<ul>
<li><a href='/getting-started/autostart-systemd/'>Linux - SystemD </a></li>
<li><a href='/getting-started/autostart-upstart/'>Linux - Upstart </a></li>
<li><a href='/getting-started/autostart-macos/'>macOS </a></li>
<li><a href='/getting-started/autostart-synology/'>Synology NAS </a></li>
</ul>
</li>
<li><a href='/topics/'>Advanced Topics</a></li>
<li><a href='/getting-started/android/'>Add to Android Homescreen </a></li>
</ul>
</div>
</section>
</div>
</aside>
</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://github.com/home-assistant/home-assistant'><i class="icon-github"></i></a>
<div class="credit">
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>
</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>

View file

@ -139,13 +139,13 @@
<h4><a class="title-link" name="state-trigger" href="#state-trigger"></a> State trigger</h4>
<p>Triggers when the state of an entity changes. If only entity_id given will match all state changes.</p>
<p>Triggers when the state of tracked entities change. If only entity_id given will match all state changes.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="key">automation</span>:
<span class="key">trigger</span>:
<span class="key">platform</span>: <span class="string"><span class="content">state</span></span>
<span class="key">entity_id</span>: <span class="string"><span class="content">device_tracker.paulus</span></span>
<span class="key">entity_id</span>: <span class="string"><span class="content">device_tracker.paulus, device_tracker.anne_therese</span></span>
<span class="comment"># Optional</span>
<span class="key">from</span>: <span class="string"><span class="content">'not_home'</span></span>
<span class="key">to</span>: <span class="string"><span class="content">'home'</span></span>
@ -268,7 +268,7 @@
<li><a href='/getting-started/devices/'>Setting up devices </a></li>
<li><a href='/getting-started/customizing-devices/'>Customizing devices and services </a></li>
<li><a href='/getting-started/presence-detection/'>Presence Detection </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting configuration.yaml </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting </a></li>
</ul>
</li>
<li>
@ -278,6 +278,14 @@
<li><a class='active' href='/getting-started/automation-trigger/'>Triggers </a></li>
<li><a href='/getting-started/automation-condition/'>Conditions </a></li>
<li><a href='/getting-started/automation-action/'>Actions </a></li>
<li><a href='/getting-started/automation-templating/'>Templates </a></li>
</ul>
</li>
<li>
<a href='/getting-started/scripts/'>Scripts </a>
<ul>
<li><a href='/getting-started/scripts-service-calls/'>Service Calls </a></li>
<li><a href='/getting-started/scripts-conditions/'>Conditions </a></li>
</ul>
</li>
<li>

View file

@ -138,7 +138,7 @@ INFO [homeassistant.components.automation] Initialized rule Rain is over
<li><a href='/getting-started/devices/'>Setting up devices </a></li>
<li><a href='/getting-started/customizing-devices/'>Customizing devices and services </a></li>
<li><a href='/getting-started/presence-detection/'>Presence Detection </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting configuration.yaml </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting </a></li>
</ul>
</li>
<li>
@ -148,6 +148,14 @@ INFO [homeassistant.components.automation] Initialized rule Rain is over
<li><a href='/getting-started/automation-trigger/'>Triggers </a></li>
<li><a href='/getting-started/automation-condition/'>Conditions </a></li>
<li><a href='/getting-started/automation-action/'>Actions </a></li>
<li><a href='/getting-started/automation-templating/'>Templates </a></li>
</ul>
</li>
<li>
<a href='/getting-started/scripts/'>Scripts </a>
<ul>
<li><a href='/getting-started/scripts-service-calls/'>Service Calls </a></li>
<li><a href='/getting-started/scripts-conditions/'>Conditions </a></li>
</ul>
</li>
<li>

View file

@ -91,23 +91,35 @@
<p>When all your devices are set up its time to put the cherry on the pie: automation. Home Assistant offers <a href="/components/#automation">a few built-in automations</a> but mainly youll be using the automation component to set up your own rules.</p>
<p>Home Assistant offers a wide range of automations. In the next few pages well try to guide you through all the different possibilities and options. Besides this documentation there are also a couple of people who have made their automation configurations <a href="/cookbook/#example-configurationyaml">publicly available</a>.</p>
<h3><a class="title-link" name="the-basics-of-automation" href="#the-basics-of-automation"></a> The basics of automation</h3>
<p>Every automation rule consists of triggers, an action to be performed and optional conditions.</p>
<p>Before you can go ahead and create your own automations, its important to learn the basics. To explore the basics, lets have a look at the following example home automation rule:</p>
<p>Triggers can be anything observed in Home Assistant. For example, it can be a certain point in time or a person coming home, which can be observed by the state changing from <code>not_home</code> to <code>home</code>.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre>(trigger) When Paulus arrives home
(condition) and it is after sunset:
(action) Turn the lights in the living room on
</pre></div>
</div>
</div>
<p>Actions will call services within Home Assistant. For example, turn a light on, set the temperature on your thermostat or activate a scene.</p>
<p>The example consists of three different parts: a trigger, a condition and an action.</p>
<p>Conditions are used to prevent actions from firing unless certain conditions are met. For example, it is possible to only turn on the light if someone comes home and it is after a certain point in time.</p>
<p>The first line is the trigger of the automation rule. Triggers describe events that should trigger the automation rule. In this case it is a person arriving home, which can be observed in Home Assistant by observing the state of Paulus changing from not_home to home.</p>
<p>The difference between a condition and a trigger can be confusing. The difference is that the trigger looks at the event that is happening, e.g., a car engine turning on. Conditions looks at the current state of the system, e.g., is the car engine on.</p>
<p>The second line is the condition part of the automation rule. Conditions are optional tests that can limit an automation rule to only work in your specific use cases. A condition will test against the current state of the system. This includes the current time, devices, people and other things like the sun. In this case we only want to act when the sun has set.</p>
<p>The third part is the action which will be performed when a rule is triggered and all conditions are met.For example, it can turn a light on, set the temperature on your thermostat or activate a scene.</p>
<p class="note">
The difference between a condition and a trigger can be confusing as they are very similar. Triggers are looking at the actions while conditions look at the result: turning a light on vs a light being on.
</p>
<h3><a class="title-link" name="exploring-the-internal-state" href="#exploring-the-internal-state"></a> Exploring the internal state</h3>
<p>Automation rules are based on the internal state of Home Assistant. This is available for exploring in the app using the developer tools. The first icon will show you the available services and the second icon will show you the current devices.</p>
<p>Each device is represented in Home Assistant as an entity consisting of the following parts:</p>
<p>Automation rules interact directly with the internal state of Home Assistant so youll need to familiarize yourself with it. Home Assistant exposes its current state via the developer tools which are available at the bottom of the sidebar in the frontend. The <img src="/images/screenshots/developer-tool-states-icon.png" class="no-shadow" height="38" /> icon will show all currently available states. An entity can be anything. A light, a switch, a person and even the sun. A state consists of the following parts:</p>
<table>
<thead>
@ -136,25 +148,11 @@
</tbody>
</table>
<p>A service can be called to have Home Assistant perform an action. Turn on a light, run a script or enable a scene. Each service has a domain and a name. For example the service <code>light.turn_on</code> is capable of turning on any light device in your system. Services can be passed parameters to for example tell which device to turn on or what color to use.</p>
<p>State changes can be used as the source of triggers and the current state can be used in conditions.</p>
<h3><a class="title-link" name="further-reading" href="#further-reading"></a> Further reading</h3>
<p>Actions are all about calling services. To explore the available services open the <img src="/images/screenshots/developer-tool-services-icon.png" class="no-shadow" height="38" /> Services developer tool. Services allow to change anything. For example turn on a light, run a script or enable a scene. Each service has a domain and a name. For example the service <code>light.turn_on</code> is capable of turning on any light in your system. Services can be passed parameters to for example tell which device to turn on or what color to use.</p>
<ul>
<li>Learn how to make your <a href="/getting-started/automation-create-first/">first automation rule</a></li>
<li>Learn about the available <a href="/getting-started/automation-trigger/">automation triggers</a></li>
<li>Learn about the available <a href="/getting-started/automation-condition/">automation conditions</a></li>
<li>Learn about <a href="/components/script/">scripts</a> to help you trigger multiple actions and delays</li>
<li>Learn about <a href="/components/scene/">scenes</a> to help you set many entities at once to your liking</li>
<li>Setup a <a href="/components/#notifications">notification platform</a> to sent yourself messages</li>
<li>For more advanced automation using Python, write your own <a href="/developers/creating_components/">custom component</a>.</li>
<li>Check out the <a href="http://events.linuxfoundation.org/sites/events/files/slides/OpenIoT%202016%20-%20Automating%20your%20Home%20with%20Home%20Assistant.pdf">slides</a> from <a href="http://events.linuxfoundation.org/events/openiot-summit">OpenIoT 2016 summit</a></li>
</ul>
<p class="note warning">
Whenever you write the value <code>on</code> or <code>off</code>, surround it with quotes to avoid
the YAML parser interpreting the values as booleans.
</p>
<h3><a href="/getting-started/automation-create-first/">Next step: Your First Automation »</a></h3>
</article>
@ -189,7 +187,7 @@
<li><a href='/getting-started/devices/'>Setting up devices </a></li>
<li><a href='/getting-started/customizing-devices/'>Customizing devices and services </a></li>
<li><a href='/getting-started/presence-detection/'>Presence Detection </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting configuration.yaml </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting </a></li>
</ul>
</li>
<li>
@ -199,6 +197,14 @@
<li><a href='/getting-started/automation-trigger/'>Triggers </a></li>
<li><a href='/getting-started/automation-condition/'>Conditions </a></li>
<li><a href='/getting-started/automation-action/'>Actions </a></li>
<li><a href='/getting-started/automation-templating/'>Templates </a></li>
</ul>
</li>
<li>
<a href='/getting-started/scripts/'>Scripts </a>
<ul>
<li><a href='/getting-started/scripts-service-calls/'>Service Calls </a></li>
<li><a href='/getting-started/scripts-conditions/'>Conditions </a></li>
</ul>
</li>
<li>

View file

@ -146,7 +146,7 @@ Home Assistant has been uninstalled.
<li><a href='/getting-started/devices/'>Setting up devices </a></li>
<li><a href='/getting-started/customizing-devices/'>Customizing devices and services </a></li>
<li><a href='/getting-started/presence-detection/'>Presence Detection </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting configuration.yaml </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting </a></li>
</ul>
</li>
<li>
@ -156,6 +156,14 @@ Home Assistant has been uninstalled.
<li><a href='/getting-started/automation-trigger/'>Triggers </a></li>
<li><a href='/getting-started/automation-condition/'>Conditions </a></li>
<li><a href='/getting-started/automation-action/'>Actions </a></li>
<li><a href='/getting-started/automation-templating/'>Templates </a></li>
</ul>
</li>
<li>
<a href='/getting-started/scripts/'>Scripts </a>
<ul>
<li><a href='/getting-started/scripts-service-calls/'>Service Calls </a></li>
<li><a href='/getting-started/scripts-conditions/'>Conditions </a></li>
</ul>
</li>
<li>

View file

@ -169,7 +169,7 @@ exec /bin/sh /volume1/homeassistant/hass-daemon start
<li><a href='/getting-started/devices/'>Setting up devices </a></li>
<li><a href='/getting-started/customizing-devices/'>Customizing devices and services </a></li>
<li><a href='/getting-started/presence-detection/'>Presence Detection </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting configuration.yaml </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting </a></li>
</ul>
</li>
<li>
@ -179,6 +179,14 @@ exec /bin/sh /volume1/homeassistant/hass-daemon start
<li><a href='/getting-started/automation-trigger/'>Triggers </a></li>
<li><a href='/getting-started/automation-condition/'>Conditions </a></li>
<li><a href='/getting-started/automation-action/'>Actions </a></li>
<li><a href='/getting-started/automation-templating/'>Templates </a></li>
</ul>
</li>
<li>
<a href='/getting-started/scripts/'>Scripts </a>
<ul>
<li><a href='/getting-started/scripts-service-calls/'>Service Calls </a></li>
<li><a href='/getting-started/scripts-conditions/'>Conditions </a></li>
</ul>
</li>
<li>

View file

@ -194,7 +194,7 @@ $ sudo systemctl start home-assistant@[your user]
<li><a href='/getting-started/devices/'>Setting up devices </a></li>
<li><a href='/getting-started/customizing-devices/'>Customizing devices and services </a></li>
<li><a href='/getting-started/presence-detection/'>Presence Detection </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting configuration.yaml </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting </a></li>
</ul>
</li>
<li>
@ -204,6 +204,14 @@ $ sudo systemctl start home-assistant@[your user]
<li><a href='/getting-started/automation-trigger/'>Triggers </a></li>
<li><a href='/getting-started/automation-condition/'>Conditions </a></li>
<li><a href='/getting-started/automation-action/'>Actions </a></li>
<li><a href='/getting-started/automation-templating/'>Templates </a></li>
</ul>
</li>
<li>
<a href='/getting-started/scripts/'>Scripts </a>
<ul>
<li><a href='/getting-started/scripts-service-calls/'>Service Calls </a></li>
<li><a href='/getting-started/scripts-conditions/'>Conditions </a></li>
</ul>
</li>
<li>

View file

@ -147,7 +147,7 @@ $ sudo service hass-daemon stop
<li><a href='/getting-started/devices/'>Setting up devices </a></li>
<li><a href='/getting-started/customizing-devices/'>Customizing devices and services </a></li>
<li><a href='/getting-started/presence-detection/'>Presence Detection </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting configuration.yaml </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting </a></li>
</ul>
</li>
<li>
@ -157,6 +157,14 @@ $ sudo service hass-daemon stop
<li><a href='/getting-started/automation-trigger/'>Triggers </a></li>
<li><a href='/getting-started/automation-condition/'>Conditions </a></li>
<li><a href='/getting-started/automation-action/'>Actions </a></li>
<li><a href='/getting-started/automation-templating/'>Templates </a></li>
</ul>
</li>
<li>
<a href='/getting-started/scripts/'>Scripts </a>
<ul>
<li><a href='/getting-started/scripts-service-calls/'>Service Calls </a></li>
<li><a href='/getting-started/scripts-conditions/'>Conditions </a></li>
</ul>
</li>
<li>

View file

@ -131,7 +131,7 @@
<li><a href='/getting-started/devices/'>Setting up devices </a></li>
<li><a href='/getting-started/customizing-devices/'>Customizing devices and services </a></li>
<li><a href='/getting-started/presence-detection/'>Presence Detection </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting configuration.yaml </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting </a></li>
</ul>
</li>
<li>
@ -141,6 +141,14 @@
<li><a href='/getting-started/automation-trigger/'>Triggers </a></li>
<li><a href='/getting-started/automation-condition/'>Conditions </a></li>
<li><a href='/getting-started/automation-action/'>Actions </a></li>
<li><a href='/getting-started/automation-templating/'>Templates </a></li>
</ul>
</li>
<li>
<a href='/getting-started/scripts/'>Scripts </a>
<ul>
<li><a href='/getting-started/scripts-service-calls/'>Service Calls </a></li>
<li><a href='/getting-started/scripts-conditions/'>Conditions </a></li>
</ul>
</li>
<li>

View file

@ -244,7 +244,7 @@ The other properties (like name) are specified using mappings. Note that the sec
<li><a href='/getting-started/devices/'>Setting up devices </a></li>
<li><a href='/getting-started/customizing-devices/'>Customizing devices and services </a></li>
<li><a href='/getting-started/presence-detection/'>Presence Detection </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting configuration.yaml </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting </a></li>
</ul>
</li>
<li>
@ -254,6 +254,14 @@ The other properties (like name) are specified using mappings. Note that the sec
<li><a href='/getting-started/automation-trigger/'>Triggers </a></li>
<li><a href='/getting-started/automation-condition/'>Conditions </a></li>
<li><a href='/getting-started/automation-action/'>Actions </a></li>
<li><a href='/getting-started/automation-templating/'>Templates </a></li>
</ul>
</li>
<li>
<a href='/getting-started/scripts/'>Scripts </a>
<ul>
<li><a href='/getting-started/scripts-service-calls/'>Service Calls </a></li>
<li><a href='/getting-started/scripts-conditions/'>Conditions </a></li>
</ul>
</li>
<li>

View file

@ -160,7 +160,7 @@ You may have to create the <code>www</code> directory yourself as it is not made
<li><a href='/getting-started/devices/'>Setting up devices </a></li>
<li><a class='active' href='/getting-started/customizing-devices/'>Customizing devices and services </a></li>
<li><a href='/getting-started/presence-detection/'>Presence Detection </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting configuration.yaml </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting </a></li>
</ul>
</li>
<li>
@ -170,6 +170,14 @@ You may have to create the <code>www</code> directory yourself as it is not made
<li><a href='/getting-started/automation-trigger/'>Triggers </a></li>
<li><a href='/getting-started/automation-condition/'>Conditions </a></li>
<li><a href='/getting-started/automation-action/'>Actions </a></li>
<li><a href='/getting-started/automation-templating/'>Templates </a></li>
</ul>
</li>
<li>
<a href='/getting-started/scripts/'>Scripts </a>
<ul>
<li><a href='/getting-started/scripts-service-calls/'>Service Calls </a></li>
<li><a href='/getting-started/scripts-conditions/'>Conditions </a></li>
</ul>
</li>
<li>

View file

@ -192,7 +192,7 @@ Each group exists of a name and a list of entity IDs. Entity IDs can be retrieve
<li><a class='active' href='/getting-started/devices/'>Setting up devices </a></li>
<li><a href='/getting-started/customizing-devices/'>Customizing devices and services </a></li>
<li><a href='/getting-started/presence-detection/'>Presence Detection </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting configuration.yaml </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting </a></li>
</ul>
</li>
<li>
@ -202,6 +202,14 @@ Each group exists of a name and a list of entity IDs. Entity IDs can be retrieve
<li><a href='/getting-started/automation-trigger/'>Triggers </a></li>
<li><a href='/getting-started/automation-condition/'>Conditions </a></li>
<li><a href='/getting-started/automation-action/'>Actions </a></li>
<li><a href='/getting-started/automation-templating/'>Templates </a></li>
</ul>
</li>
<li>
<a href='/getting-started/scripts/'>Scripts </a>
<ul>
<li><a href='/getting-started/scripts-service-calls/'>Service Calls </a></li>
<li><a href='/getting-started/scripts-conditions/'>Conditions </a></li>
</ul>
</li>
<li>

View file

@ -178,7 +178,7 @@ $ hass --open-ui
<li><a href='/getting-started/devices/'>Setting up devices </a></li>
<li><a href='/getting-started/customizing-devices/'>Customizing devices and services </a></li>
<li><a href='/getting-started/presence-detection/'>Presence Detection </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting configuration.yaml </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting </a></li>
</ul>
</li>
<li>
@ -188,6 +188,14 @@ $ hass --open-ui
<li><a href='/getting-started/automation-trigger/'>Triggers </a></li>
<li><a href='/getting-started/automation-condition/'>Conditions </a></li>
<li><a href='/getting-started/automation-action/'>Actions </a></li>
<li><a href='/getting-started/automation-templating/'>Templates </a></li>
</ul>
</li>
<li>
<a href='/getting-started/scripts/'>Scripts </a>
<ul>
<li><a href='/getting-started/scripts-service-calls/'>Service Calls </a></li>
<li><a href='/getting-started/scripts-conditions/'>Conditions </a></li>
</ul>
</li>
<li>

View file

@ -150,7 +150,7 @@ When using boot2docker on OS X you are unable to map the local time to your Dock
<li><a href='/getting-started/devices/'>Setting up devices </a></li>
<li><a href='/getting-started/customizing-devices/'>Customizing devices and services </a></li>
<li><a href='/getting-started/presence-detection/'>Presence Detection </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting configuration.yaml </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting </a></li>
</ul>
</li>
<li>
@ -160,6 +160,14 @@ When using boot2docker on OS X you are unable to map the local time to your Dock
<li><a href='/getting-started/automation-trigger/'>Triggers </a></li>
<li><a href='/getting-started/automation-condition/'>Conditions </a></li>
<li><a href='/getting-started/automation-action/'>Actions </a></li>
<li><a href='/getting-started/automation-templating/'>Templates </a></li>
</ul>
</li>
<li>
<a href='/getting-started/scripts/'>Scripts </a>
<ul>
<li><a href='/getting-started/scripts-service-calls/'>Service Calls </a></li>
<li><a href='/getting-started/scripts-conditions/'>Conditions </a></li>
</ul>
</li>
<li>

View file

@ -168,7 +168,7 @@ $ hass
<li><a href='/getting-started/devices/'>Setting up devices </a></li>
<li><a href='/getting-started/customizing-devices/'>Customizing devices and services </a></li>
<li><a href='/getting-started/presence-detection/'>Presence Detection </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting configuration.yaml </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting </a></li>
</ul>
</li>
<li>
@ -178,6 +178,14 @@ $ hass
<li><a href='/getting-started/automation-trigger/'>Triggers </a></li>
<li><a href='/getting-started/automation-condition/'>Conditions </a></li>
<li><a href='/getting-started/automation-action/'>Actions </a></li>
<li><a href='/getting-started/automation-templating/'>Templates </a></li>
</ul>
</li>
<li>
<a href='/getting-started/scripts/'>Scripts </a>
<ul>
<li><a href='/getting-started/scripts-service-calls/'>Service Calls </a></li>
<li><a href='/getting-started/scripts-conditions/'>Conditions </a></li>
</ul>
</li>
<li>

View file

@ -373,7 +373,7 @@ Thats it… youre all set to go</p>
<li><a href='/getting-started/devices/'>Setting up devices </a></li>
<li><a href='/getting-started/customizing-devices/'>Customizing devices and services </a></li>
<li><a href='/getting-started/presence-detection/'>Presence Detection </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting configuration.yaml </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting </a></li>
</ul>
</li>
<li>
@ -383,6 +383,14 @@ Thats it… youre all set to go</p>
<li><a href='/getting-started/automation-trigger/'>Triggers </a></li>
<li><a href='/getting-started/automation-condition/'>Conditions </a></li>
<li><a href='/getting-started/automation-action/'>Actions </a></li>
<li><a href='/getting-started/automation-templating/'>Templates </a></li>
</ul>
</li>
<li>
<a href='/getting-started/scripts/'>Scripts </a>
<ul>
<li><a href='/getting-started/scripts-service-calls/'>Service Calls </a></li>
<li><a href='/getting-started/scripts-conditions/'>Conditions </a></li>
</ul>
</li>
<li>

View file

@ -268,7 +268,7 @@ sudo chown hass /srv/hass
<li><a href='/getting-started/devices/'>Setting up devices </a></li>
<li><a href='/getting-started/customizing-devices/'>Customizing devices and services </a></li>
<li><a href='/getting-started/presence-detection/'>Presence Detection </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting configuration.yaml </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting </a></li>
</ul>
</li>
<li>
@ -278,6 +278,14 @@ sudo chown hass /srv/hass
<li><a href='/getting-started/automation-trigger/'>Triggers </a></li>
<li><a href='/getting-started/automation-condition/'>Conditions </a></li>
<li><a href='/getting-started/automation-action/'>Actions </a></li>
<li><a href='/getting-started/automation-templating/'>Templates </a></li>
</ul>
</li>
<li>
<a href='/getting-started/scripts/'>Scripts </a>
<ul>
<li><a href='/getting-started/scripts-service-calls/'>Service Calls </a></li>
<li><a href='/getting-started/scripts-conditions/'>Conditions </a></li>
</ul>
</li>
<li>

View file

@ -159,7 +159,7 @@ OwnTracks communicates directly with your MQTT broker, no data will pass through
<li><a href='/getting-started/devices/'>Setting up devices </a></li>
<li><a href='/getting-started/customizing-devices/'>Customizing devices and services </a></li>
<li><a class='active' href='/getting-started/presence-detection/'>Presence Detection </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting configuration.yaml </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting </a></li>
</ul>
</li>
<li>
@ -169,6 +169,14 @@ OwnTracks communicates directly with your MQTT broker, no data will pass through
<li><a href='/getting-started/automation-trigger/'>Triggers </a></li>
<li><a href='/getting-started/automation-condition/'>Conditions </a></li>
<li><a href='/getting-started/automation-action/'>Actions </a></li>
<li><a href='/getting-started/automation-templating/'>Templates </a></li>
</ul>
</li>
<li>
<a href='/getting-started/scripts/'>Scripts </a>
<ul>
<li><a href='/getting-started/scripts-service-calls/'>Service Calls </a></li>
<li><a href='/getting-started/scripts-conditions/'>Conditions </a></li>
</ul>
</li>
<li>

View file

@ -0,0 +1,320 @@
<!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>Conditions - Home Assistant</title>
<meta name="author" content="Paulus Schoutsen">
<meta name="description" content="Documentation about all available conditions.">
<meta name="viewport" content="width=device-width">
<link rel="canonical" href="https://home-assistant.io/getting-started/scripts-conditions/">
<meta property="fb:app_id" content="338291289691179">
<meta property="og:title" content="Conditions">
<meta property="og:site_name" content="Home Assistant">
<meta property="og:url" content="https://home-assistant.io/getting-started/scripts-conditions/">
<meta property="og:type" content="website">
<meta property="og:description" content="Documentation about all available conditions.">
<meta property="og:image" content="https://home-assistant.io/images/home-assistant-logo-2164x2164.png">
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@home_assistant">
<meta name="twitter:title" content="Conditions">
<meta name="twitter:description" content="Documentation about all available conditions.">
<meta name="twitter:image" content="https://home-assistant.io/images/home-assistant-logo-2164x2164.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='/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">
Conditions
</h1>
</header>
<hr class="divider">
<p>Conditions can be used within a script or automation to prevent further execution. A condition will look at the system right now. For example a condition can test if a switch is currently turned on or off.</p>
<h4><a class="title-link" name="and-condition" href="#and-condition"></a> AND condition</h4>
<p>Test multiple conditions in 1 condition statement. Passes if all embedded conditions are valid.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="key">condition</span>: <span class="string"><span class="content">and</span></span>
<span class="key">conditions</span>:
- <span class="string"><span class="content">condition: state</span></span>
<span class="key">entity_id</span>: <span class="string"><span class="content">'device_tracker.paulus'</span></span>
<span class="key">state</span>: <span class="string"><span class="content">'home'</span></span>
- <span class="string"><span class="content">condition: numeric_state</span></span>
<span class="key">entity_id</span>: <span class="string"><span class="content">'sensor.temperature'</span></span>
<span class="key">below</span>: <span class="string"><span class="content">'20'</span></span>
</pre></div>
</div>
</div>
<h4><a class="title-link" name="numeric-state-condition" href="#numeric-state-condition"></a> Numeric state condition</h4>
<p>This type of condition attempts to parse the state of specified entity as a number and triggers if the value matches all of the above or below thresholds.</p>
<p>For above, the condition passes if <code>value &gt;= above</code>. For below, the condition passes if <code>value &lt;= below</code>. If both <code>below</code> and <code>above</code> are specified, both tests have to pass.</p>
<p>You can optionally use a <code>value_template</code> to process the value of the state before testing it.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="key">condition</span>: <span class="string"><span class="content">numeric_state</span></span>
<span class="key">entity_id</span>: <span class="string"><span class="content">sensor.temperature</span></span>
<span class="key">above</span>: <span class="string"><span class="content">17</span></span>
<span class="key">below</span>: <span class="string"><span class="content">25</span></span>
<span class="comment"># If your sensor value needs to be adjusted</span>
<span class="key">value_template</span>:
</pre></div>
</div>
</div>
<h4><a class="title-link" name="or-condition" href="#or-condition"></a> OR condition</h4>
<p>Test multiple conditions in 1 condition statement. Passes if any embedded conditions is valid.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="key">condition</span>: <span class="string"><span class="content">or</span></span>
<span class="key">conditions</span>:
- <span class="string"><span class="content">condition: state</span></span>
<span class="key">entity_id</span>: <span class="string"><span class="content">'device_tracker.paulus'</span></span>
<span class="key">state</span>: <span class="string"><span class="content">'home'</span></span>
- <span class="string"><span class="content">condition: numeric_state</span></span>
<span class="key">entity_id</span>: <span class="string"><span class="content">'sensor.temperature'</span></span>
<span class="key">below</span>: <span class="string"><span class="content">'20'</span></span>
</pre></div>
</div>
</div>
<h4><a class="title-link" name="state-condition" href="#state-condition"></a> State condition</h4>
<p>Tests if an entity is a specified state.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="key">condition</span>: <span class="string"><span class="content">state</span></span>
<span class="key">entity_id</span>: <span class="string"><span class="content">device_tracker.paulus</span></span>
<span class="key">state</span>: <span class="string"><span class="content">not_home</span></span>
<span class="comment"># optional: trigger only if state was this for last X time.</span>
<span class="key">for</span>:
<span class="key">hours</span>: <span class="string"><span class="content">1</span></span>
<span class="key">minutes</span>: <span class="string"><span class="content">10</span></span>
<span class="key">seconds</span>: <span class="string"><span class="content">5</span></span>
</pre></div>
</div>
</div>
<h4><a class="title-link" name="sun-condition" href="#sun-condition"></a> Sun condition</h4>
<p>The sun condition can test if the sun has already set or risen when a trigger occurs. The <code>before</code> and <code>after</code> keys can only be set to <code>sunset</code> or <code>sunrise</code>. They have a corresponding optional offset value (<code>before_offset</code>, <code>after_offset</code>) that can be added, similar to the <a href="#sun-trigger">sun trigger</a>.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="key">condition</span>: <span class="string"><span class="content">sun</span></span>
<span class="key">after</span>: <span class="string"><span class="content">sunset</span></span>
<span class="comment"># Optional offset value</span>
<span class="key">after_offset</span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">-1:00:00</span><span class="delimiter">&quot;</span></span>
</pre></div>
</div>
</div>
<h4><a class="title-link" name="template-condition" href="#template-condition"></a> Template condition</h4>
<p>The template condition will test if the [given template][template] renders a value equal to true. This is achieved by having the template result in a true boolean expression or by having the template render true.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="key">condition</span>: <span class="string"><span class="content">template</span></span>
<span class="key">value_template</span>: <span class="string"><span class="content">'{{ state.attributes.battery &gt; 50 }}'</span></span>
</pre></div>
</div>
</div>
<p>Within an automation, template conditions also have access to the <code>trigger</code> variable as <a href="/getting-started/automation-templating/">described here</a>.</p>
<h4><a class="title-link" name="time-condition" href="#time-condition"></a> Time condition</h4>
<p>The time condition can test if it is after a specified time, before a specified time or if it is a certain day of the week</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="key">condition</span>: <span class="string"><span class="content">time</span></span>
<span class="comment"># At least one of the following is required.</span>
<span class="key">after</span>: <span class="string"><span class="content">'15:00:00'</span></span>
<span class="key">before</span>: <span class="string"><span class="content">'23:00:00'</span></span>
<span class="key">weekday</span>:
- <span class="string"><span class="content">mon</span></span>
- <span class="string"><span class="content">wed</span></span>
- <span class="string"><span class="content">fri</span></span>
</pre></div>
</div>
</div>
<p>Valid values for <code>weekday</code> are <code>mon</code>, <code>tue</code>, <code>wed</code>, <code>thu</code>, <code>fri</code>, <code>sat</code>, <code>sun</code>.</p>
<h4><a class="title-link" name="zone-condition" href="#zone-condition"></a> Zone condition</h4>
<p>Zone conditions test if an entity is in a certain zone. For zone automation to work, you need to have setup a device tracker platform that supports reporting GPS coordinates. Currently this is limited to the <a href="/components/device_tracker.owntracks/">OwnTracks platform</a> and the <a href="/components/device_tracker.icloud/">iCloud platform</a>.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="key">condition</span>: <span class="string"><span class="content">zone</span></span>
<span class="key">entity_id</span>: <span class="string"><span class="content">device_tracker.paulus</span></span>
<span class="key">zone</span>: <span class="string"><span class="content">zone.home</span></span>
</pre></div>
</div>
</div>
</article>
</div>
<aside id="sidebar" class="grid__item one-third lap-one-whole palm-one-whole">
<div class="grid">
<section class="aside-module grid__item one-whole lap-one-half">
<div class='edit-github'><a href='https://github.com/home-assistant/home-assistant.io/tree/master/source/getting-started/scripts-conditions.markdown'>Edit this page on GitHub</a></div>
<div class='section'>
<h1 class="title delta">Getting Started Guide</h1>
<ul class='divided sidebar-menu'>
<li>
<a href='/getting-started/'>Installation </a>
<ul>
<li><a href='/getting-started/installation-raspberry-pi/'>Raspberry Pi </a></li>
<li><a href='/getting-started/installation-docker/'>Docker </a></li>
<li><a href='/getting-started/installation-synology/'>Synology NAS </a></li>
<li><a href='/getting-started/installation-virtualenv/'>VirtualEnv Linux Instructions </a></li>
<li><a href='/getting-started/troubleshooting/'>Troubleshooting </a></li>
</ul>
</li>
<li>
Configuration
<ul>
<li><a href='/getting-started/configuration/'>Configuration.yaml </a></li>
<li><a href='/getting-started/devices/'>Setting up devices </a></li>
<li><a href='/getting-started/customizing-devices/'>Customizing devices and services </a></li>
<li><a href='/getting-started/presence-detection/'>Presence Detection </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting </a></li>
</ul>
</li>
<li>
<a href='/getting-started/automation/'>Automation </a>
<ul>
<li><a href='/getting-started/automation-create-first/'>Tutorial </a></li>
<li><a href='/getting-started/automation-trigger/'>Triggers </a></li>
<li><a href='/getting-started/automation-condition/'>Conditions </a></li>
<li><a href='/getting-started/automation-action/'>Actions </a></li>
<li><a href='/getting-started/automation-templating/'>Templates </a></li>
</ul>
</li>
<li>
<a href='/getting-started/scripts/'>Scripts </a>
<ul>
<li><a href='/getting-started/scripts-service-calls/'>Service Calls </a></li>
<li><a class='active' href='/getting-started/scripts-conditions/'>Conditions </a></li>
</ul>
</li>
<li>
<a href='/getting-started/autostart/'>Auto-start Home Assistant </a>
<ul>
<li><a href='/getting-started/autostart-systemd/'>Linux - SystemD </a></li>
<li><a href='/getting-started/autostart-upstart/'>Linux - Upstart </a></li>
<li><a href='/getting-started/autostart-macos/'>macOS </a></li>
<li><a href='/getting-started/autostart-synology/'>Synology NAS </a></li>
</ul>
</li>
<li><a href='/topics/'>Advanced Topics</a></li>
<li><a href='/getting-started/android/'>Add to Android Homescreen </a></li>
</ul>
</div>
</section>
</div>
</aside>
</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://github.com/home-assistant/home-assistant'><i class="icon-github"></i></a>
<div class="credit">
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>
</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>

View file

@ -0,0 +1,261 @@
<!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>Service Calls - Home Assistant</title>
<meta name="author" content="Paulus Schoutsen">
<meta name="description" content="Instructions how to call services in Home Assistant.">
<meta name="viewport" content="width=device-width">
<link rel="canonical" href="https://home-assistant.io/getting-started/scripts-service-calls/">
<meta property="fb:app_id" content="338291289691179">
<meta property="og:title" content="Service Calls">
<meta property="og:site_name" content="Home Assistant">
<meta property="og:url" content="https://home-assistant.io/getting-started/scripts-service-calls/">
<meta property="og:type" content="website">
<meta property="og:description" content="Instructions how to call services in Home Assistant.">
<meta property="og:image" content="https://home-assistant.io/images/home-assistant-logo-2164x2164.png">
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@home_assistant">
<meta name="twitter:title" content="Service Calls">
<meta name="twitter:description" content="Instructions how to call services in Home Assistant.">
<meta name="twitter:image" content="https://home-assistant.io/images/home-assistant-logo-2164x2164.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='/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">
Service Calls
</h1>
</header>
<hr class="divider">
<p>Various components allow calling services when a certain event occurs. The most common one is calling a service when an automation trigger happens. But a service can also be called from a script or via the Amazon Echo.</p>
<p>The configuration options to call a config are the same between all components and are described on this page.</p>
<p>Examples on this page will be given as part of an automation component configuration but different approaches can be used for other components too.</p>
<p class="note">
Use the <img src="/images/screenshots/developer-tool-services-icon.png" class="no-shadow" height="38" /> service developer tool in the frontend to discover available services.
</p>
<h3><a class="title-link" name="the-basics" href="#the-basics"></a> The basics</h3>
<p>Call the service <code>homeassistant.turn_on</code> on the entity <code>group.living_room</code>. This will turn all members of <code>group.living_room</code> on. You can also omit <code>entity_id</code> and it will turn on all possible entities.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="key">service</span>: <span class="string"><span class="content">homeassistant.turn_on</span></span>
<span class="key">entity_id</span>: <span class="string"><span class="content">group.living_room</span></span>
</pre></div>
</div>
</div>
<h3><a class="title-link" name="passing-data-to-the-service-call" href="#passing-data-to-the-service-call"></a> Passing data to the service call</h3>
<p>You can also specify other parameters beside the entity to target. For example, the light turn on service allows specifying the brightness.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="key">service</span>: <span class="string"><span class="content">light.turn_on</span></span>
<span class="key">entity_id</span>: <span class="string"><span class="content">group.living_room</span></span>
<span class="key">data</span>:
<span class="key">brightness</span>: <span class="string"><span class="content">120</span></span>
<span class="key">rgb_color</span>: <span class="string"><span class="content">[255, 0, 0]</span></span>
</pre></div>
</div>
</div>
<h3><a class="title-link" name="use-templates-to-decide-which-service-to-call" href="#use-templates-to-decide-which-service-to-call"></a> Use templates to decide which service to call</h3>
<p>You can use <a href="/topics/templating/">templating</a> support to dynamically choose which service to call. For example, you can call a certain service based on if a light is on.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="key">service_template</span>: <span class="string"><span class="delimiter">&gt;</span><span class="content">
{% if states.sensor.temperature | float &gt; 15 %}
switch.turn_on
{% else %}
switch.turn_off
{% endif %}</span></span>
<span class="key">entity_id</span>: <span class="string"><span class="content">switch.ac</span></span>
</pre></div>
</div>
</div>
<h3><a class="title-link" name="use-templates-to-determine-the-attributes" href="#use-templates-to-determine-the-attributes"></a> Use templates to determine the attributes</h3>
<p>Templates can also be used for the data that you pass to the service call.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="key">service</span>: <span class="string"><span class="content">thermostat.set_temperature</span></span>
<span class="key">data_template</span>:
<span class="key">entity_id</span>: <span class="string"><span class="delimiter">&gt;</span><span class="content">
{% if is_state('device_tracker.paulus', 'home') %}
thermostat.upstairs
{% else %}
thermostat.downstairs
{% endif %}</span></span>
<span class="key">temperature</span>: <span class="string"><span class="content">{{ 22 - distance(states.device_tracker.paulus) }}</span></span>
</pre></div>
</div>
</div>
</article>
</div>
<aside id="sidebar" class="grid__item one-third lap-one-whole palm-one-whole">
<div class="grid">
<section class="aside-module grid__item one-whole lap-one-half">
<div class='edit-github'><a href='https://github.com/home-assistant/home-assistant.io/tree/master/source/getting-started/scripts-service-calls.markdown'>Edit this page on GitHub</a></div>
<div class='section'>
<h1 class="title delta">Getting Started Guide</h1>
<ul class='divided sidebar-menu'>
<li>
<a href='/getting-started/'>Installation </a>
<ul>
<li><a href='/getting-started/installation-raspberry-pi/'>Raspberry Pi </a></li>
<li><a href='/getting-started/installation-docker/'>Docker </a></li>
<li><a href='/getting-started/installation-synology/'>Synology NAS </a></li>
<li><a href='/getting-started/installation-virtualenv/'>VirtualEnv Linux Instructions </a></li>
<li><a href='/getting-started/troubleshooting/'>Troubleshooting </a></li>
</ul>
</li>
<li>
Configuration
<ul>
<li><a href='/getting-started/configuration/'>Configuration.yaml </a></li>
<li><a href='/getting-started/devices/'>Setting up devices </a></li>
<li><a href='/getting-started/customizing-devices/'>Customizing devices and services </a></li>
<li><a href='/getting-started/presence-detection/'>Presence Detection </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting </a></li>
</ul>
</li>
<li>
<a href='/getting-started/automation/'>Automation </a>
<ul>
<li><a href='/getting-started/automation-create-first/'>Tutorial </a></li>
<li><a href='/getting-started/automation-trigger/'>Triggers </a></li>
<li><a href='/getting-started/automation-condition/'>Conditions </a></li>
<li><a href='/getting-started/automation-action/'>Actions </a></li>
<li><a href='/getting-started/automation-templating/'>Templates </a></li>
</ul>
</li>
<li>
<a href='/getting-started/scripts/'>Scripts </a>
<ul>
<li><a class='active' href='/getting-started/scripts-service-calls/'>Service Calls </a></li>
<li><a href='/getting-started/scripts-conditions/'>Conditions </a></li>
</ul>
</li>
<li>
<a href='/getting-started/autostart/'>Auto-start Home Assistant </a>
<ul>
<li><a href='/getting-started/autostart-systemd/'>Linux - SystemD </a></li>
<li><a href='/getting-started/autostart-upstart/'>Linux - Upstart </a></li>
<li><a href='/getting-started/autostart-macos/'>macOS </a></li>
<li><a href='/getting-started/autostart-synology/'>Synology NAS </a></li>
</ul>
</li>
<li><a href='/topics/'>Advanced Topics</a></li>
<li><a href='/getting-started/android/'>Add to Android Homescreen </a></li>
</ul>
</div>
</section>
</div>
</aside>
</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://github.com/home-assistant/home-assistant'><i class="icon-github"></i></a>
<div class="credit">
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>
</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>

View file

@ -0,0 +1,279 @@
<!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>Script Syntax - Home Assistant</title>
<meta name="author" content="Paulus Schoutsen">
<meta name="description" content="Documention for the Home Assistant Script Syntax.">
<meta name="viewport" content="width=device-width">
<link rel="canonical" href="https://home-assistant.io/getting-started/scripts/">
<meta property="fb:app_id" content="338291289691179">
<meta property="og:title" content="Script Syntax">
<meta property="og:site_name" content="Home Assistant">
<meta property="og:url" content="https://home-assistant.io/getting-started/scripts/">
<meta property="og:type" content="website">
<meta property="og:description" content="Documention for the Home Assistant Script Syntax.">
<meta property="og:image" content="https://home-assistant.io/images/home-assistant-logo-2164x2164.png">
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@home_assistant">
<meta name="twitter:title" content="Script Syntax">
<meta name="twitter:description" content="Documention for the Home Assistant Script Syntax.">
<meta name="twitter:image" content="https://home-assistant.io/images/home-assistant-logo-2164x2164.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='/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">
Script Syntax
</h1>
</header>
<hr class="divider">
<p>Scripts are a sequence of actions that Home Assistant will execute. Scripts are available as an entity through the standalone <a href="/components/script/">Script component</a> but can also be embedded in <a href="/getting-started/automation-action/">automations</a> and <a href="/components/alexa/">Alexa/Amazon Echo</a> configurations.</p>
<p>The script syntax basic structure is a list of key/value maps that contain actions. If a script contains only 1 action, the wrapping list can be omitted.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="comment"># Example script component containing script syntax</span>
<span class="key">script</span>:
<span class="key">example_script</span>:
<span class="key">sequence</span>:
<span class="comment"># This is written using the Script Syntax</span>
- <span class="string"><span class="content">service: light.turn_on</span></span>
<span class="key">entity_id</span>: <span class="string"><span class="content">light.ceiling</span></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="content">'Turned on the ceiling light!'</span></span>
</pre></div>
</div>
</div>
<h4><a class="title-link" name="call-a-service" href="#call-a-service"></a> Call a Service</h4>
<p>The most important one is the action to call a service. This can be done in various ways. For all the different possibilities, have a look at the <a href="/getting-started/scripts-service-calls/">service calls page</a>.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="key">alias</span>: <span class="string"><span class="content">Bedroom lights on</span></span>
<span class="key">service</span>: <span class="string"><span class="content">light.turn_on</span></span>
<span class="key">data</span>:
<span class="key">entity_id</span>: <span class="string"><span class="content">group.bedroom</span></span>
<span class="key">brightness</span>: <span class="string"><span class="content">100</span></span>
</pre></div>
</div>
</div>
<h4><a class="title-link" name="test-a-condition" href="#test-a-condition"></a> Test a Condition</h4>
<p>While executing a script you can add a condition to stop further execution. When a condition does not return <code>true</code>, the script will finish. There are many different conditions which are documented at the <a href="/getting-started/scripts-conditions/">conditions page</a>.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="key">condition</span>: <span class="string"><span class="content">state</span></span>
<span class="key">entity_id</span>: <span class="string"><span class="content">device_tracker.paulus</span></span>
<span class="key">state</span>: <span class="string"><span class="content">'home'</span></span>
</pre></div>
</div>
</div>
<h4><a class="title-link" name="delay" href="#delay"></a> Delay</h4>
<p>Delays are useful for temporarily suspending your script and start it at a later moment. We support different syntaxes for a delay as shown below.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="comment"># Waits 1 hour</span>
<span class="key">delay</span>: <span class="string"><span class="content">01:00</span></span>
</pre></div>
</div>
</div>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="comment"># Waits 1 minute, 30 seconds</span>
<span class="key">delay</span>: <span class="string"><span class="content">00:01:30</span></span>
</pre></div>
</div>
</div>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="comment"># Waits 1 minute</span>
<span class="key">delay</span>:
<span class="comment"># supports seconds, minutes, hours, days</span>
<span class="key">minutes</span>: <span class="string"><span class="content">1</span></span>
</pre></div>
</div>
</div>
<h4><a class="title-link" name="fire-an-event" href="#fire-an-event"></a> Fire an Event</h4>
<p>This action allows you to fire an event. Events can be used for many things. It could trigger an automation or indicate to another component that something is happening. For instance, in the below example it is used to create an entry in the logbook.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="key">event</span>: <span class="string"><span class="content">LOGBOOK_ENTRY</span></span>
<span class="key">event_data</span>:
<span class="key">name</span>: <span class="string"><span class="content">Paulus</span></span>
<span class="key">message</span>: <span class="string"><span class="content">is waking up</span></span>
<span class="key">entity_id</span>: <span class="string"><span class="content">device_tracker.paulus</span></span>
<span class="key">domain</span>: <span class="string"><span class="content">light</span></span>
</pre></div>
</div>
</div>
</article>
</div>
<aside id="sidebar" class="grid__item one-third lap-one-whole palm-one-whole">
<div class="grid">
<section class="aside-module grid__item one-whole lap-one-half">
<div class='edit-github'><a href='https://github.com/home-assistant/home-assistant.io/tree/master/source/getting-started/scripts.markdown'>Edit this page on GitHub</a></div>
<div class='section'>
<h1 class="title delta">Getting Started Guide</h1>
<ul class='divided sidebar-menu'>
<li>
<a href='/getting-started/'>Installation </a>
<ul>
<li><a href='/getting-started/installation-raspberry-pi/'>Raspberry Pi </a></li>
<li><a href='/getting-started/installation-docker/'>Docker </a></li>
<li><a href='/getting-started/installation-synology/'>Synology NAS </a></li>
<li><a href='/getting-started/installation-virtualenv/'>VirtualEnv Linux Instructions </a></li>
<li><a href='/getting-started/troubleshooting/'>Troubleshooting </a></li>
</ul>
</li>
<li>
Configuration
<ul>
<li><a href='/getting-started/configuration/'>Configuration.yaml </a></li>
<li><a href='/getting-started/devices/'>Setting up devices </a></li>
<li><a href='/getting-started/customizing-devices/'>Customizing devices and services </a></li>
<li><a href='/getting-started/presence-detection/'>Presence Detection </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting </a></li>
</ul>
</li>
<li>
<a href='/getting-started/automation/'>Automation </a>
<ul>
<li><a href='/getting-started/automation-create-first/'>Tutorial </a></li>
<li><a href='/getting-started/automation-trigger/'>Triggers </a></li>
<li><a href='/getting-started/automation-condition/'>Conditions </a></li>
<li><a href='/getting-started/automation-action/'>Actions </a></li>
<li><a href='/getting-started/automation-templating/'>Templates </a></li>
</ul>
</li>
<li>
<a class='active' href='/getting-started/scripts/'>Scripts </a>
<ul>
<li><a href='/getting-started/scripts-service-calls/'>Service Calls </a></li>
<li><a href='/getting-started/scripts-conditions/'>Conditions </a></li>
</ul>
</li>
<li>
<a href='/getting-started/autostart/'>Auto-start Home Assistant </a>
<ul>
<li><a href='/getting-started/autostart-systemd/'>Linux - SystemD </a></li>
<li><a href='/getting-started/autostart-upstart/'>Linux - Upstart </a></li>
<li><a href='/getting-started/autostart-macos/'>macOS </a></li>
<li><a href='/getting-started/autostart-synology/'>Synology NAS </a></li>
</ul>
</li>
<li><a href='/topics/'>Advanced Topics</a></li>
<li><a href='/getting-started/android/'>Add to Android Homescreen </a></li>
</ul>
</div>
</section>
</div>
</aside>
</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://github.com/home-assistant/home-assistant'><i class="icon-github"></i></a>
<div class="credit">
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>
</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>

View file

@ -207,7 +207,7 @@ Whenever you report an issue, be aware that we are volunteers who do not have ac
<li><a href='/getting-started/devices/'>Setting up devices </a></li>
<li><a href='/getting-started/customizing-devices/'>Customizing devices and services </a></li>
<li><a href='/getting-started/presence-detection/'>Presence Detection </a></li>
<li><a class='active' href='/getting-started/troubleshooting-configuration/'>Troubleshooting configuration.yaml </a></li>
<li><a class='active' href='/getting-started/troubleshooting-configuration/'>Troubleshooting </a></li>
</ul>
</li>
<li>
@ -217,6 +217,14 @@ Whenever you report an issue, be aware that we are volunteers who do not have ac
<li><a href='/getting-started/automation-trigger/'>Triggers </a></li>
<li><a href='/getting-started/automation-condition/'>Conditions </a></li>
<li><a href='/getting-started/automation-action/'>Actions </a></li>
<li><a href='/getting-started/automation-templating/'>Templates </a></li>
</ul>
</li>
<li>
<a href='/getting-started/scripts/'>Scripts </a>
<ul>
<li><a href='/getting-started/scripts-service-calls/'>Service Calls </a></li>
<li><a href='/getting-started/scripts-conditions/'>Conditions </a></li>
</ul>
</li>
<li>

View file

@ -201,7 +201,7 @@ chrome -&gt; settings -&gt; site settings -&gt; storage -&gt; search for your UR
<li><a href='/getting-started/devices/'>Setting up devices </a></li>
<li><a href='/getting-started/customizing-devices/'>Customizing devices and services </a></li>
<li><a href='/getting-started/presence-detection/'>Presence Detection </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting configuration.yaml </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting </a></li>
</ul>
</li>
<li>
@ -211,6 +211,14 @@ chrome -&gt; settings -&gt; site settings -&gt; storage -&gt; search for your UR
<li><a href='/getting-started/automation-trigger/'>Triggers </a></li>
<li><a href='/getting-started/automation-condition/'>Conditions </a></li>
<li><a href='/getting-started/automation-action/'>Actions </a></li>
<li><a href='/getting-started/automation-templating/'>Templates </a></li>
</ul>
</li>
<li>
<a href='/getting-started/scripts/'>Scripts </a>
<ul>
<li><a href='/getting-started/scripts-service-calls/'>Service Calls </a></li>
<li><a href='/getting-started/scripts-conditions/'>Conditions </a></li>
</ul>
</li>
<li>