338 lines
No EOL
16 KiB
HTML
338 lines
No EOL
16 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>Automation Trigger - Home Assistant</title>
|
||
<meta name="author" content="Paulus Schoutsen">
|
||
<meta name="description" content="All the different ways how automations can be triggered.">
|
||
|
||
<meta name="viewport" content="width=device-width">
|
||
<link rel="canonical" href="https://home-assistant.io/getting-started/automation-trigger/">
|
||
|
||
<meta property="fb:app_id" content="338291289691179">
|
||
<meta property="og:title" content="Automation Trigger">
|
||
<meta property="og:site_name" content="Home Assistant">
|
||
<meta property="og:url" content="https://home-assistant.io/getting-started/automation-trigger/">
|
||
<meta property="og:type" content="website">
|
||
<meta property="og:description" content="All the different ways how automations can be triggered.">
|
||
<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 Trigger">
|
||
<meta name="twitter:description" content="All the different ways how automations can be triggered.">
|
||
<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 Trigger
|
||
</h1>
|
||
</header>
|
||
<hr class="divider">
|
||
|
||
|
||
<p>Triggers are what starts the processing of an automation rule. It is possible to specify multiple triggers for the same rule. Once a trigger starts, Home Assistant will validate the conditions, if any, and call the action.</p>
|
||
|
||
<h4><a class="title-link" name="event-trigger" href="#event-trigger"></a> Event trigger</h4>
|
||
<p>Triggers when an event is being processed. Events are the raw building blocks of Home Assistant. You can match events on just the event name or also require specific event data to be present.</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">event</span></span>
|
||
<span class="key">event_type</span>: <span class="string"><span class="content">MY_CUSTOM_EVENT</span></span>
|
||
<span class="comment"># optional</span>
|
||
<span class="key">event_data</span>:
|
||
<span class="key">mood</span>: <span class="string"><span class="content">happy</span></span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
|
||
<h4><a class="title-link" name="mqtt-trigger" href="#mqtt-trigger"></a> MQTT trigger</h4>
|
||
<p>Triggers when a specific message is received on given topic. Optionally can match on the payload being sent over the topic.</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">mqtt</span></span>
|
||
<span class="key">topic</span>: <span class="string"><span class="content">living_room/switch/ac</span></span>
|
||
<span class="comment"># Optional</span>
|
||
<span class="key">payload</span>: <span class="string"><span class="content">'on'</span></span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
|
||
<h4><a class="title-link" name="numeric-state-trigger" href="#numeric-state-trigger"></a> Numeric state trigger</h4>
|
||
<p>On state change of a specified entity, attempts to parse the state as a number and triggers if value is above and/or below a threshold.</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">numeric_state</span></span>
|
||
<span class="key">entity_id</span>: <span class="string"><span class="content">sensor.temperature</span></span>
|
||
<span class="comment"># Optional</span>
|
||
<span class="key">value_template</span>: <span class="string"><span class="content">'{{ state.attributes.battery }}'</span></span>
|
||
<span class="comment"># At least one of the following required</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-trigger" href="#state-trigger"></a> State trigger</h4>
|
||
|
||
<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, 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>
|
||
<span class="comment"># If given, will trigger when state has been the to state for 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>
|
||
|
||
<p class="note warning">
|
||
Use quotes around your values for <code>from</code> and <code>to</code> to avoid the YAML parser interpreting values as booleans.
|
||
</p>
|
||
|
||
<h4><a class="title-link" name="sun-trigger" href="#sun-trigger"></a> Sun trigger</h4>
|
||
<p>Trigger when the sun is setting or rising. An optional time offset can be given to have it trigger for example 45 minutes before sunset, when dusk is setting in.</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">sun</span></span>
|
||
<span class="comment"># Possible values: sunset, sunrise</span>
|
||
<span class="key">event</span>: <span class="string"><span class="content">sunset</span></span>
|
||
<span class="comment"># Optional time offset. This example is 45 minutes.</span>
|
||
<span class="key">offset</span>: <span class="string"><span class="content">'-00:45:00'</span></span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
|
||
<h4><a class="title-link" name="template-trigger" href="#template-trigger"></a> Template trigger</h4>
|
||
|
||
<p>Template triggers work by evaluating a [template] on each state change. The trigger will fire if the state change caused the template to render ‘true’. This is achieved by having the template result in a true boolean expression (<code>{{ is_state('device_tracker.paulus', 'home') }}</code>) or by having the template render ‘true’ (example below).</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">template</span></span>
|
||
<span class="key">value_template</span>: <span class="string"><span class="content">'{% if is_state('device_tracker.paulus', 'home') %}true{% endif %}'</span></span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
|
||
<h4><a class="title-link" name="time-trigger" href="#time-trigger"></a> Time trigger</h4>
|
||
|
||
<p>Time can be triggered in many ways. The most common is to specify <code>after</code> and trigger at a specific point in time each day. Alternatively, you can also match if the hour, minute or second of the current time has a specific value. You can prefix the value with a <code>/</code> to match whenever the value is divisible by that number. You cannot use <code>after</code> together with hour, minute or second.</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">time</span></span>
|
||
<span class="comment"># Matches every hour at 5 minutes past whole</span>
|
||
<span class="key">minutes</span>: <span class="string"><span class="content">5</span></span>
|
||
<span class="key">seconds</span>: <span class="string"><span class="content">0</span></span>
|
||
|
||
<span class="key">automation 2</span>:
|
||
<span class="key">trigger</span>:
|
||
<span class="key">platform</span>: <span class="string"><span class="content">time</span></span>
|
||
<span class="comment"># When 'after' is used, you cannot also match on hour, minute, seconds.</span>
|
||
<span class="comment"># Military time format.</span>
|
||
<span class="key">after</span>: <span class="string"><span class="content">'15:32:00'</span></span>
|
||
|
||
<span class="key">automation 3</span>:
|
||
<span class="key">trigger</span>:
|
||
<span class="key">platform</span>: <span class="string"><span class="content">time</span></span>
|
||
<span class="comment"># You can also match on interval. This will match every 5 minutes</span>
|
||
<span class="key">minutes</span>: <span class="string"><span class="content">'/5'</span></span>
|
||
<span class="key">seconds</span>: <span class="string"><span class="content">0</span></span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
|
||
<h4><a class="title-link" name="zone-trigger" href="#zone-trigger"></a> Zone trigger</h4>
|
||
|
||
<p>Zone triggers can trigger when an entity is entering or leaving the 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> as well as 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">trigger</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>
|
||
<span class="comment"># Event is either enter or leave</span>
|
||
<span class="key">event</span>: <span class="string"><span class="content">enter</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/automation-trigger.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 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>
|
||
<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> |