Site updated at 2018-02-12 22:29:39 UTC
This commit is contained in:
parent
cdedb52594
commit
1f6e533860
28 changed files with 86 additions and 75 deletions
|
@ -128,7 +128,7 @@
|
|||
</code></pre>
|
||||
</div>
|
||||
<p>This is starting to get a little more complex in Home Assistant automations, requiring an automation rule and two separate scripts.</p>
|
||||
<p>Now let’s extend this with a somewhat artificial example to show something that is simple in AppDaemon but very difficult if not impossible using automations. Let’s warn someone inside the house that there has been motion outside by flashing a lamp on and off ten times. We are reacting to the motion as before by turning on the light and setting a timer to turn it off again, but in addition, we set a 1-second timer to run <code class="highlighter-rouge">flash_warning()</code>, which, when called, toggles the inside light and sets another timer to call itself a second later. To avoid re-triggering forever, it keeps a count of how many times it has been activated and bales out after ten iterations.</p>
|
||||
<p>Now let’s extend this with a somewhat artificial example to show something that is simple in AppDaemon but very difficult if not impossible using automations. Let’s warn someone inside the house that there has been motion outside by flashing a lamp on and off ten times. We are reacting to the motion as before by turning on the light and setting a timer to turn it off again, but in addition, we set a 1-second timer to run <code class="highlighter-rouge">flash_warning()</code>, which, when called, toggles the inside light and sets another timer to call itself a second later. To avoid re-triggering forever, it keeps a count of how many times it has been activated and bails out after ten iterations.</p>
|
||||
<div class="language-python highlighter-rouge"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">appdaemon.appapi</span> <span class="kn">as</span> <span class="nn">appapi</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">MotionLights</span><span class="p">(</span><span class="n">appapi</span><span class="o">.</span><span class="n">AppDaemon</span><span class="p">):</span>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue