Site updated at 2017-03-18 17:12:07 UTC
This commit is contained in:
parent
7573fcba68
commit
67179bf8fe
994 changed files with 1768 additions and 68252 deletions
|
@ -3,17 +3,14 @@
|
|||
<!--[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="Home Assistant">
|
||||
<meta name="description" content="Documentation about all available conditions.">
|
||||
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<link rel="canonical" href="https://home-assistant.io/docs/scripts/conditions/">
|
||||
|
||||
<meta property="fb:app_id" content="338291289691179">
|
||||
<meta property="og:title" content="Conditions">
|
||||
<meta property="og:site_name" content="Home Assistant">
|
||||
|
@ -21,39 +18,31 @@
|
|||
<meta property="og:type" content="article">
|
||||
<meta property="og:description" content="Documentation about all available conditions.">
|
||||
<meta property="og:image" content="https://home-assistant.io/images/default-social.png">
|
||||
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:site" content="@home_assistant">
|
||||
|
||||
<meta name="twitter:title" content="Conditions">
|
||||
<meta name="twitter:description" content="Documentation about all available conditions.">
|
||||
<meta name="twitter:image" content="https://home-assistant.io/images/default-social.png">
|
||||
|
||||
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet">
|
||||
<link href="/atom.xml" rel="alternate" title="Home Assistant" type="application/atom+xml">
|
||||
<link rel='shortcut icon' href='/images/favicon.ico' />
|
||||
<link rel='icon' type='image/png' href='/images/favicon-192x192.png' sizes='192x192' />
|
||||
</head>
|
||||
|
||||
<body >
|
||||
|
||||
<header>
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid">
|
||||
|
||||
<div class="grid__item three-tenths lap-two-sixths palm-one-whole ha-title">
|
||||
<a href="/" class="site-title">
|
||||
<img width='40' src='/demo/favicon-192x192.png'>
|
||||
<span>Home Assistant</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="grid__item seven-tenths lap-four-sixths palm-one-whole">
|
||||
<nav>
|
||||
<input type="checkbox" id="toggle">
|
||||
<label for="toggle" class="toggle" data-open="Main Menu" data-close="Close Menu"></label>
|
||||
<ul class="menu pull-right">
|
||||
|
||||
<li><a href="/getting-started/">Getting started</a></li>
|
||||
<li><a href="/components/">Components</a></li>
|
||||
<li><a href="/docs/">Docs</a></li>
|
||||
|
@ -64,40 +53,23 @@
|
|||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
|
||||
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid grid-center">
|
||||
|
||||
<div class="grid__item two-thirds lap-one-whole palm-one-whole">
|
||||
|
||||
|
||||
<article class="page">
|
||||
|
||||
|
||||
<div class='edit-github'><a href='https://github.com/home-assistant/home-assistant.github.io/tree/current/source/_docs/scripts/conditions.markdown'>Edit this page on GitHub</a></div>
|
||||
|
||||
|
||||
|
||||
<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>
|
||||
|
||||
<h3><a class="title-link" name="and-condition" href="#and-condition"></a> AND condition</h3>
|
||||
|
||||
<p>Test multiple conditions in 1 condition statement. Passes if all embedded conditions are valid.</p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">condition</span><span class="pi">:</span>
|
||||
<span class="s">condition</span><span class="pi">:</span> <span class="s">and</span>
|
||||
<span class="s">conditions</span><span class="pi">:</span>
|
||||
|
@ -109,11 +81,8 @@
|
|||
<span class="s">below</span><span class="pi">:</span> <span class="s1">'</span><span class="s">20'</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<h3><a class="title-link" name="or-condition" href="#or-condition"></a> OR condition</h3>
|
||||
|
||||
<p>Test multiple conditions in 1 condition statement. Passes if any embedded conditions is valid.</p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">condition</span><span class="pi">:</span>
|
||||
<span class="s">condition</span><span class="pi">:</span> <span class="s">or</span>
|
||||
<span class="s">conditions</span><span class="pi">:</span>
|
||||
|
@ -125,12 +94,9 @@
|
|||
<span class="s">below</span><span class="pi">:</span> <span class="s1">'</span><span class="s">20'</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<h3><a class="title-link" name="mixed--and-and-or-conditions" href="#mixed--and-and-or-conditions"></a> MIXED AND and OR conditions</h3>
|
||||
|
||||
<p>Test multiple AND and OR conditions in 1 condition statement. Passes if any embedded conditions is valid.
|
||||
This allows you to mix several AND and OR conditions together.</p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">condition</span><span class="pi">:</span>
|
||||
<span class="s">condition</span><span class="pi">:</span> <span class="s">and</span>
|
||||
<span class="s">conditions</span><span class="pi">:</span>
|
||||
|
@ -147,15 +113,10 @@ This allows you to mix several AND and OR conditions together.</p>
|
|||
<span class="s">below</span><span class="pi">:</span> <span class="s1">'</span><span class="s">20'</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<h3><a class="title-link" name="numeric-state-condition" href="#numeric-state-condition"></a> Numeric state condition</h3>
|
||||
|
||||
<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 class="highlighter-rouge">value >= above</code>. For below, the condition passes if <code class="highlighter-rouge">value <= below</code>. If both <code class="highlighter-rouge">below</code> and <code class="highlighter-rouge">above</code> are specified, both tests have to pass.</p>
|
||||
|
||||
<p>You can optionally use a <code class="highlighter-rouge">value_template</code> to process the value of the state before testing it.</p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">condition</span><span class="pi">:</span>
|
||||
<span class="s">condition</span><span class="pi">:</span> <span class="s">numeric_state</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">sensor.temperature</span>
|
||||
|
@ -165,11 +126,8 @@ This allows you to mix several AND and OR conditions together.</p>
|
|||
<span class="s">value_template</span><span class="pi">:</span> <span class="pi">{{</span> <span class="nv">float(state.state) + 2</span> <span class="pi">}}</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<h3><a class="title-link" name="state-condition" href="#state-condition"></a> State condition</h3>
|
||||
|
||||
<p>Tests if an entity is a specified state.</p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">condition</span><span class="pi">:</span>
|
||||
<span class="s">condition</span><span class="pi">:</span> <span class="s">state</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">device_tracker.paulus</span>
|
||||
|
@ -181,11 +139,8 @@ This allows you to mix several AND and OR conditions together.</p>
|
|||
<span class="s">seconds</span><span class="pi">:</span> <span class="s">5</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<h3><a class="title-link" name="sun-condition" href="#sun-condition"></a> Sun condition</h3>
|
||||
|
||||
<p>The sun condition can test if the sun has already set or risen when a trigger occurs. The <code class="highlighter-rouge">before</code> and <code class="highlighter-rouge">after</code> keys can only be set to <code class="highlighter-rouge">sunset</code> or <code class="highlighter-rouge">sunrise</code>. They have a corresponding optional offset value (<code class="highlighter-rouge">before_offset</code>, <code class="highlighter-rouge">after_offset</code>) that can be added, similar to the <a href="/getting-started/automation-trigger/#sun-trigger">sun trigger</a>.</p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">condition</span><span class="pi">:</span>
|
||||
<span class="s">condition</span><span class="pi">:</span> <span class="s">sun</span>
|
||||
<span class="s">after</span><span class="pi">:</span> <span class="s">sunset</span>
|
||||
|
@ -193,23 +148,16 @@ This allows you to mix several AND and OR conditions together.</p>
|
|||
<span class="s">after_offset</span><span class="pi">:</span> <span class="s2">"</span><span class="s">-1:00:00"</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<h3><a class="title-link" name="template-condition" href="#template-condition"></a> Template condition</h3>
|
||||
|
||||
<p>The template condition will test if the <a href="/topics/templating/">given template</a> 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="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">condition</span><span class="pi">:</span>
|
||||
<span class="s">condition</span><span class="pi">:</span> <span class="s">template</span>
|
||||
<span class="s">value_template</span><span class="pi">:</span> <span class="s1">'</span><span class="s">{{</span><span class="nv"> </span><span class="s">states.device_tracker.iphone.attributes.battery</span><span class="nv"> </span><span class="s">></span><span class="nv"> </span><span class="s">50</span><span class="nv"> </span><span class="s">}}'</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>Within an automation, template conditions also have access to the <code class="highlighter-rouge">trigger</code> variable as <a href="/getting-started/automation-templating/">described here</a>.</p>
|
||||
|
||||
<h3><a class="title-link" name="time-condition" href="#time-condition"></a> Time condition</h3>
|
||||
|
||||
<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="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">condition</span><span class="pi">:</span>
|
||||
<span class="s">condition</span><span class="pi">:</span> <span class="s">time</span>
|
||||
<span class="c1"># At least one of the following is required.</span>
|
||||
|
@ -221,23 +169,17 @@ This allows you to mix several AND and OR conditions together.</p>
|
|||
<span class="pi">-</span> <span class="s">fri</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>Valid values for <code class="highlighter-rouge">weekday</code> are <code class="highlighter-rouge">mon</code>, <code class="highlighter-rouge">tue</code>, <code class="highlighter-rouge">wed</code>, <code class="highlighter-rouge">thu</code>, <code class="highlighter-rouge">fri</code>, <code class="highlighter-rouge">sat</code>, <code class="highlighter-rouge">sun</code>.
|
||||
Time condition windows can span across the midnight threshold. In the example above, the condition window is from 3pm to 2am.</p>
|
||||
|
||||
<h3><a class="title-link" name="zone-condition" href="#zone-condition"></a> Zone condition</h3>
|
||||
|
||||
<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="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">condition</span><span class="pi">:</span>
|
||||
<span class="s">condition</span><span class="pi">:</span> <span class="s">zone</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">device_tracker.paulus</span>
|
||||
<span class="s">zone</span><span class="pi">:</span> <span class="s">zone.home</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<h3><a class="title-link" name="examples" href="#examples"></a> Examples</h3>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code> <span class="s">condition</span><span class="pi">:</span>
|
||||
<span class="pi">-</span> <span class="s">condition</span><span class="pi">:</span> <span class="s">numeric_state</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">sun.sun</span>
|
||||
|
@ -254,18 +196,10 @@ Time condition windows can span across the midnight threshold. In the example ab
|
|||
<span class="s">state</span><span class="pi">:</span> <span class="s1">'</span><span class="s">off'</span>
|
||||
</code></pre>
|
||||
</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='section'>
|
||||
<h1 class="title delta">Topics</h1>
|
||||
|
@ -452,13 +386,10 @@ Time condition windows can span across the midnight threshold. In the example ab
|
|||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer>
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid">
|
||||
|
@ -468,7 +399,6 @@ Time condition windows can span across the midnight threshold. In the example ab
|
|||
<a rel="me" href='https://facebook.com/homeassistantio'><i class="icon-facebook"></i></a>
|
||||
<a rel="me" href='https://plus.google.com/110560654828510104551'><i class="icon-google-plus"></i></a>
|
||||
<a rel="me" href='https://github.com/home-assistant/home-assistant'><i class="icon-github"></i></a>
|
||||
|
||||
<div class="credit">
|
||||
Contact us at <a href='mailto:hello@home-assistant.io'>hello@home-assistant.io</a>.<br>
|
||||
Website powered by <a href='http://jekyllrb.com/'>Jekyll</a> and the <a href='https://github.com/coogie/oscailte'>Oscalite theme</a>.<br />
|
||||
|
@ -480,7 +410,6 @@ Time condition windows can span across the midnight threshold. In the example ab
|
|||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
var _gaq=[['_setAccount','UA-57927901-1'],['_trackPageview']];
|
||||
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
|
||||
|
@ -488,4 +417,4 @@ Time condition windows can span across the midnight threshold. In the example ab
|
|||
s.parentNode.insertBefore(g,s)}(document,'script'));
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
@ -3,17 +3,14 @@
|
|||
<!--[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="Home Assistant">
|
||||
<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/docs/scripts/">
|
||||
|
||||
<meta property="fb:app_id" content="338291289691179">
|
||||
<meta property="og:title" content="Script Syntax">
|
||||
<meta property="og:site_name" content="Home Assistant">
|
||||
|
@ -21,39 +18,31 @@
|
|||
<meta property="og:type" content="article">
|
||||
<meta property="og:description" content="Documention for the Home Assistant Script Syntax.">
|
||||
<meta property="og:image" content="https://home-assistant.io/images/default-social.png">
|
||||
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:site" content="@home_assistant">
|
||||
|
||||
<meta name="twitter:title" content="Script Syntax">
|
||||
<meta name="twitter:description" content="Documention for the Home Assistant Script Syntax.">
|
||||
<meta name="twitter:image" content="https://home-assistant.io/images/default-social.png">
|
||||
|
||||
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet">
|
||||
<link href="/atom.xml" rel="alternate" title="Home Assistant" type="application/atom+xml">
|
||||
<link rel='shortcut icon' href='/images/favicon.ico' />
|
||||
<link rel='icon' type='image/png' href='/images/favicon-192x192.png' sizes='192x192' />
|
||||
</head>
|
||||
|
||||
<body >
|
||||
|
||||
<header>
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid">
|
||||
|
||||
<div class="grid__item three-tenths lap-two-sixths palm-one-whole ha-title">
|
||||
<a href="/" class="site-title">
|
||||
<img width='40' src='/demo/favicon-192x192.png'>
|
||||
<span>Home Assistant</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="grid__item seven-tenths lap-four-sixths palm-one-whole">
|
||||
<nav>
|
||||
<input type="checkbox" id="toggle">
|
||||
<label for="toggle" class="toggle" data-open="Main Menu" data-close="Close Menu"></label>
|
||||
<ul class="menu pull-right">
|
||||
|
||||
<li><a href="/getting-started/">Getting started</a></li>
|
||||
<li><a href="/components/">Components</a></li>
|
||||
<li><a href="/docs/">Docs</a></li>
|
||||
|
@ -64,38 +53,22 @@
|
|||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
|
||||
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid grid-center">
|
||||
|
||||
<div class="grid__item two-thirds lap-one-whole palm-one-whole">
|
||||
|
||||
|
||||
<article class="page">
|
||||
|
||||
|
||||
<div class='edit-github'><a href='https://github.com/home-assistant/home-assistant.github.io/tree/current/source/_docs/scripts.markdown'>Edit this page on GitHub</a></div>
|
||||
|
||||
|
||||
|
||||
<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="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="c1"># Example script component containing script syntax</span>
|
||||
<span class="s">script</span><span class="pi">:</span>
|
||||
<span class="s">example_script</span><span class="pi">:</span>
|
||||
|
@ -108,11 +81,8 @@
|
|||
<span class="s">message</span><span class="pi">:</span> <span class="s1">'</span><span class="s">Turned</span><span class="nv"> </span><span class="s">on</span><span class="nv"> </span><span class="s">the</span><span class="nv"> </span><span class="s">ceiling</span><span class="nv"> </span><span class="s">light!'</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<h3><a class="title-link" name="call-a-service" href="#call-a-service"></a> Call a Service</h3>
|
||||
|
||||
<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="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">alias</span><span class="pi">:</span> <span class="s">Bedroom lights on</span>
|
||||
<span class="s">service</span><span class="pi">:</span> <span class="s">light.turn_on</span>
|
||||
<span class="s">data</span><span class="pi">:</span>
|
||||
|
@ -120,62 +90,47 @@
|
|||
<span class="s">brightness</span><span class="pi">:</span> <span class="s">100</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<h3><a class="title-link" name="test-a-condition" href="#test-a-condition"></a> Test a Condition</h3>
|
||||
|
||||
<p>While executing a script you can add a condition to stop further execution. When a condition does not return <code class="highlighter-rouge">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="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">condition</span><span class="pi">:</span> <span class="s">state</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">device_tracker.paulus</span>
|
||||
<span class="s">state</span><span class="pi">:</span> <span class="s1">'</span><span class="s">home'</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<h3><a class="title-link" name="delay" href="#delay"></a> Delay</h3>
|
||||
|
||||
<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="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="c1"># Waits 1 hour</span>
|
||||
<span class="s">delay</span><span class="pi">:</span> <span class="s">01:00</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="c1"># Waits 1 minute, 30 seconds</span>
|
||||
<span class="s">delay</span><span class="pi">:</span> <span class="s">00:01:30</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="c1"># Waits 1 minute</span>
|
||||
<span class="s">delay</span><span class="pi">:</span>
|
||||
<span class="c1"># supports seconds, minutes, hours, days</span>
|
||||
<span class="s">minutes</span><span class="pi">:</span> <span class="s">1</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="c1"># Waits however many minutes input_slider.minute_delay is set to</span>
|
||||
<span class="c1"># Valid formats include HH:MM and HH:MM:SS</span>
|
||||
<span class="s">delay</span><span class="pi">:</span> <span class="s1">'</span><span class="s">00:{{</span><span class="nv"> </span><span class="s">states.input_slider.minute_delay.state</span><span class="nv"> </span><span class="s">|</span><span class="nv"> </span><span class="s">int</span><span class="nv"> </span><span class="s">}}:00'</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
<h3><a class="title-link" name="wait" href="#wait"></a> Wait</h3>
|
||||
|
||||
<p>Wait until some things are complete. We support at the moment <code class="highlighter-rouge">wait_template</code> for waiting until a condition is <code class="highlighter-rouge">true</code>, see also on <a href="/getting-started/automation-trigger/#template-trigger">Template-Trigger</a>. It is possible to set a timeout after that will the script abort his execution. Timeout have same syntax as <code class="highlighter-rouge">delay</code>.</p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="c1"># wait until media player have stop the playing</span>
|
||||
<span class="s">wait_template</span><span class="pi">:</span> <span class="s2">"</span><span class="s">{{</span><span class="nv"> </span><span class="s">states.media_player.floor.states</span><span class="nv"> </span><span class="s">==</span><span class="nv"> </span><span class="s">'stop'</span><span class="nv"> </span><span class="s">}}"</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="c1"># wait until a valve is < 10 or abort after 1 minutes.</span>
|
||||
<span class="s">wait_template</span><span class="pi">:</span> <span class="s2">"</span><span class="s">{{</span><span class="nv"> </span><span class="s">states.climate.kitchen.attributes.valve</span><span class="nv"> </span><span class="s"><</span><span class="nv"> </span><span class="s">10</span><span class="nv"> </span><span class="s">}}"</span>
|
||||
<span class="s">timeout</span><span class="pi">:</span> <span class="s">00:01:00</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<h3><a class="title-link" name="fire-an-event" href="#fire-an-event"></a> Fire an Event</h3>
|
||||
|
||||
<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="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">event</span><span class="pi">:</span> <span class="s">LOGBOOK_ENTRY</span>
|
||||
<span class="s">event_data</span><span class="pi">:</span>
|
||||
<span class="s">name</span><span class="pi">:</span> <span class="s">Paulus</span>
|
||||
|
@ -184,19 +139,10 @@
|
|||
<span class="s">domain</span><span class="pi">:</span> <span class="s">light</span>
|
||||
</code></pre>
|
||||
</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='section'>
|
||||
<h1 class="title delta">Topics</h1>
|
||||
|
@ -383,13 +329,10 @@
|
|||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer>
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid">
|
||||
|
@ -399,7 +342,6 @@
|
|||
<a rel="me" href='https://facebook.com/homeassistantio'><i class="icon-facebook"></i></a>
|
||||
<a rel="me" href='https://plus.google.com/110560654828510104551'><i class="icon-google-plus"></i></a>
|
||||
<a rel="me" href='https://github.com/home-assistant/home-assistant'><i class="icon-github"></i></a>
|
||||
|
||||
<div class="credit">
|
||||
Contact us at <a href='mailto:hello@home-assistant.io'>hello@home-assistant.io</a>.<br>
|
||||
Website powered by <a href='http://jekyllrb.com/'>Jekyll</a> and the <a href='https://github.com/coogie/oscailte'>Oscalite theme</a>.<br />
|
||||
|
@ -411,7 +353,6 @@
|
|||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
var _gaq=[['_setAccount','UA-57927901-1'],['_trackPageview']];
|
||||
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
|
||||
|
@ -419,4 +360,4 @@
|
|||
s.parentNode.insertBefore(g,s)}(document,'script'));
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
@ -3,17 +3,14 @@
|
|||
<!--[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="Home Assistant">
|
||||
<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/docs/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">
|
||||
|
@ -21,39 +18,31 @@
|
|||
<meta property="og:type" content="article">
|
||||
<meta property="og:description" content="Instructions how to call services in Home Assistant.">
|
||||
<meta property="og:image" content="https://home-assistant.io/images/default-social.png">
|
||||
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:site" content="@home_assistant">
|
||||
|
||||
<meta name="twitter:title" content="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/default-social.png">
|
||||
|
||||
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet">
|
||||
<link href="/atom.xml" rel="alternate" title="Home Assistant" type="application/atom+xml">
|
||||
<link rel='shortcut icon' href='/images/favicon.ico' />
|
||||
<link rel='icon' type='image/png' href='/images/favicon-192x192.png' sizes='192x192' />
|
||||
</head>
|
||||
|
||||
<body >
|
||||
|
||||
<header>
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid">
|
||||
|
||||
<div class="grid__item three-tenths lap-two-sixths palm-one-whole ha-title">
|
||||
<a href="/" class="site-title">
|
||||
<img width='40' src='/demo/favicon-192x192.png'>
|
||||
<span>Home Assistant</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="grid__item seven-tenths lap-four-sixths palm-one-whole">
|
||||
<nav>
|
||||
<input type="checkbox" id="toggle">
|
||||
<label for="toggle" class="toggle" data-open="Main Menu" data-close="Close Menu"></label>
|
||||
<ul class="menu pull-right">
|
||||
|
||||
<li><a href="/getting-started/">Getting started</a></li>
|
||||
<li><a href="/components/">Components</a></li>
|
||||
<li><a href="/docs/">Docs</a></li>
|
||||
|
@ -64,57 +53,34 @@
|
|||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
|
||||
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid grid-center">
|
||||
|
||||
<div class="grid__item two-thirds lap-one-whole palm-one-whole">
|
||||
|
||||
|
||||
<article class="page">
|
||||
|
||||
|
||||
<div class='edit-github'><a href='https://github.com/home-assistant/home-assistant.github.io/tree/current/source/_docs/scripts/service-calls.markdown'>Edit this page on GitHub</a></div>
|
||||
|
||||
|
||||
|
||||
<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 class="highlighter-rouge">homeassistant.turn_on</code> on the entity <code class="highlighter-rouge">group.living_room</code>. This will turn all members of <code class="highlighter-rouge">group.living_room</code> on. You can also omit <code class="highlighter-rouge">entity_id</code> and it will turn on all possible entities.</p>
|
||||
|
||||
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">service</span><span class="pi">:</span> <span class="s">homeassistant.turn_on</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">group.living_room</span>
|
||||
</code></pre>
|
||||
</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="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">service</span><span class="pi">:</span> <span class="s">light.turn_on</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">group.living_room</span>
|
||||
<span class="s">data</span><span class="pi">:</span>
|
||||
|
@ -122,11 +88,8 @@ Use the <img src="/images/screenshots/developer-tool-services-icon.png" class="n
|
|||
<span class="s">rgb_color</span><span class="pi">:</span> <span class="pi">[</span><span class="nv">255</span><span class="pi">,</span> <span class="nv">0</span><span class="pi">,</span> <span class="nv">0</span><span class="pi">]</span>
|
||||
</code></pre>
|
||||
</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="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">service_template</span><span class="pi">:</span> <span class="pi">></span>
|
||||
<span class="no">{% if states.sensor.temperature | float > 15 %}</span>
|
||||
<span class="no">switch.turn_on</span>
|
||||
|
@ -136,21 +99,15 @@ Use the <img src="/images/screenshots/developer-tool-services-icon.png" class="n
|
|||
<span class="s">entity_id</span><span class="pi">:</span> <span class="s">switch.ac</span>
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<h3><a class="title-link" name="using-the-services-developer-tool" href="#using-the-services-developer-tool"></a> Using the Services Developer Tool</h3>
|
||||
|
||||
<p>You can use the Services Developer Tool to test data to pass in a service call.
|
||||
For example, you may test turning on or off a ‘group’ (See [groups] for more info)</p>
|
||||
|
||||
<p>To turn a group on or off, pass the following info:
|
||||
Domain: <code class="highlighter-rouge">homeassistant</code>
|
||||
Service: <code class="highlighter-rouge">turn_on</code>
|
||||
Service Data: <code class="highlighter-rouge"><span class="p">{</span><span class="w"> </span><span class="nt">"entity_id"</span><span class="p">:</span><span class="w"> </span><span class="s2">"group.kitchen"</span><span class="w"> </span><span class="p">}</span></code></p>
|
||||
|
||||
<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="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">service</span><span class="pi">:</span> <span class="s">thermostat.set_temperature</span>
|
||||
<span class="s">data_template</span><span class="pi">:</span>
|
||||
<span class="s">entity_id</span><span class="pi">:</span> <span class="pi">></span>
|
||||
|
@ -162,19 +119,10 @@ Service Data: <code class="highlighter-rouge"><span class="p">{</span><span clas
|
|||
<span class="s">temperature</span><span class="pi">:</span> <span class="pi">{{</span> <span class="nv">22 - distance(states.device_tracker.paulus)</span> <span class="pi">}}</span>
|
||||
</code></pre>
|
||||
</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='section'>
|
||||
<h1 class="title delta">Topics</h1>
|
||||
|
@ -361,13 +309,10 @@ Service Data: <code class="highlighter-rouge"><span class="p">{</span><span clas
|
|||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer>
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid">
|
||||
|
@ -377,7 +322,6 @@ Service Data: <code class="highlighter-rouge"><span class="p">{</span><span clas
|
|||
<a rel="me" href='https://facebook.com/homeassistantio'><i class="icon-facebook"></i></a>
|
||||
<a rel="me" href='https://plus.google.com/110560654828510104551'><i class="icon-google-plus"></i></a>
|
||||
<a rel="me" href='https://github.com/home-assistant/home-assistant'><i class="icon-github"></i></a>
|
||||
|
||||
<div class="credit">
|
||||
Contact us at <a href='mailto:hello@home-assistant.io'>hello@home-assistant.io</a>.<br>
|
||||
Website powered by <a href='http://jekyllrb.com/'>Jekyll</a> and the <a href='https://github.com/coogie/oscailte'>Oscalite theme</a>.<br />
|
||||
|
@ -389,7 +333,6 @@ Service Data: <code class="highlighter-rouge"><span class="p">{</span><span clas
|
|||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
var _gaq=[['_setAccount','UA-57927901-1'],['_trackPageview']];
|
||||
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
|
||||
|
@ -397,4 +340,4 @@ Service Data: <code class="highlighter-rouge"><span class="p">{</span><span clas
|
|||
s.parentNode.insertBefore(g,s)}(document,'script'));
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue