280 lines
No EOL
12 KiB
HTML
280 lines
No EOL
12 KiB
HTML
<!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-raspberry-pi-all-in-one/'>Raspberry Pi All-In-One Installer </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 </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/'>OS X </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> |