Site updated at 2017-07-29 20:48:07 UTC
This commit is contained in:
parent
e226901c2b
commit
e55d4ce725
31 changed files with 70 additions and 46 deletions
|
@ -79,12 +79,12 @@
|
|||
<h1>Another Take on Automation</h1>
|
||||
<p>AppDaemon is not meant to replace Home Assistant Automations and Scripts, rather complement them. For a lot of things, automations work well and can be very succinct. However, there is a class of more complex automations for which they become harder to use, and appdeamon then comes into its own. It brings quite a few things to the table:</p>
|
||||
<ul>
|
||||
<li>New paradigm - some problems require a procedural and/or iterative approach, and <code class="highlighter-rouge">AppDaemon</code> Apps are a much more natural fit for this. Recent enhancements to Home Assistant scripts and templates have made huge strides, but for the most complex scenarios, Apps can do things that Automations can’t</li>
|
||||
<li>New paradigm - Some problems require a procedural and/or iterative approach, and <code class="highlighter-rouge">AppDaemon</code> Apps are a much more natural fit for this. Recent enhancements to Home Assistant scripts and templates have made huge strides, but for the most complex scenarios, apps can do things that automations can’t.</li>
|
||||
<li>Ease of use - AppDaemon’s API is full of helper functions that make programming as easy and natural as possible. The functions and their operation are as “Pythonic” as possible, experienced Python programmers should feel right at home.</li>
|
||||
<li>Reuse - write a piece of code once and instantiate it as an app as many times as you need with different parameters e.g. a motion light program that you can use in 5 different places around your home. The code stays the same, you just dynamically add new instances of it in the config file</li>
|
||||
<li>Reuse - write a piece of code once and instantiate it as an app as many times as you need with different parameters e.g. a motion light program that you can use in 5 different places around your home. The code stays the same, you just dynamically add new instances of it in the config file.</li>
|
||||
<li>Dynamic - AppDaemon has been designed from the start to enable the user to make changes without requiring a restart of Home Assistant, thanks to it’s loose coupling. However, it is better than that - the user can make changes to code and AppDaemon will automatically reload the code, figure out which Apps were using it and restart them to use the new code with out the need to restart <code class="highlighter-rouge">AppDaemon</code> itself. It is also possible to change parameters for an individual or multiple apps and have them picked up dynamically, and for a final trick, removing or adding apps is also picked up dynamically. Testing cycles become a lot more efficient as a result.</li>
|
||||
<li>Complex logic - Python’s If/Else constructs are clearer and easier to code for arbitrarily complex nested logic</li>
|
||||
<li>Durable variables and state - variables can be kept between events to keep track of things like the number of times a motion sensor has been activated, or how long it has been since a door opened</li>
|
||||
<li>Durable variables and state - Variables can be kept between events to keep track of things like the number of times a motion sensor has been activated, or how long it has been since a door opened.</li>
|
||||
<li>All the power of Python - use any of Python’s libraries, create your own modules, share variables, refactor and re-use code, create a single app to do everything, or multiple apps for individual tasks - nothing is off limits!</li>
|
||||
</ul>
|
||||
<p>It is in fact a testament to Home Assistant’s open nature that a component like <code class="highlighter-rouge">AppDaemon</code> can be integrated so neatly and closely that it acts in all ways like an extension of the system, not a second class citizen. Part of the strength of Home Assistant’s underlying design is that it makes no assumptions whatever about what it is controlling or reacting to, or reporting state on. This is made achievable in part by the great flexibility of Python as a programming environment for Home Assistant, and carrying that forward has enabled me to use the same philosophy for <code class="highlighter-rouge">AppDaemon</code> - it took surprisingly little code to be able to respond to basic events and call services in a completely open ended manner - the bulk of the work after that was adding additonal functions to make things that were already possible easier.</p>
|
||||
|
@ -127,7 +127,7 @@
|
|||
<span class="bp">self</span><span class="o">.</span><span class="n">turn_off</span><span class="p">(</span><span class="s">"light.drive"</span><span class="p">)</span>
|
||||
</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>This is starting to get a little more complex in Home Assistant automations requiring an automation rule and two separate scripts.</p>
|
||||
<p>Now lets extend this with a somewhat artificial example to show something that is simple in AppDaemon but very difficult if not impossible using automations. Lets warn someone inside the house that there has been motion outside by flashing a lamp on and off 10 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 10 iterations.</p>
|
||||
<div class="language-python highlighter-rouge"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">homeassistant.appapi</span> <span class="kn">as</span> <span class="nn">appapi</span>
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@
|
|||
<li>A tool called <code class="highlighter-rouge">hassbian-config</code>.</li>
|
||||
</ul>
|
||||
<h3><a class="title-link" name="wireless-network" href="#wireless-network"></a> Wireless Network</h3>
|
||||
<p>After flashing the image to your SD Card open the partition <code class="highlighter-rouge">boot</code> and create a new file <code class="highlighter-rouge">wpa_supplicant.conf</code>. Edit the file and enter your network credentials. For more information visit <a href="https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md">Setting up Wifi for Raspbian</a>. During the start the file will automatically copied in the right folder and the network connection will be established. The file could look like this:</p>
|
||||
<p>After flashing the image to your SD Card open the partition <code class="highlighter-rouge">boot</code> and create a new file <code class="highlighter-rouge">wpa_supplicant.conf</code>. Edit the file and enter your network credentials. For more information visit <a href="https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md">Setting up Wifi for Raspbian</a>. During start the file will automatically be copied in the right folder and the network connection will be established. The file could look like this:</p>
|
||||
<div class="language-conf highlighter-rouge"><pre class="highlight"><code><span class="n">network</span>={
|
||||
<span class="n">ssid</span>=<span class="s2">"YOUR_SSID"</span>
|
||||
<span class="n">psk</span>=<span class="s2">"YOUR_PASSWORD"</span>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue