Site updated at 2016-10-17 16:26:13 UTC
This commit is contained in:
parent
8f48017769
commit
6bb71e64c4
23 changed files with 54 additions and 52 deletions
|
@ -91,9 +91,11 @@
|
|||
|
||||
<p>In the package <a href="https://github.com/home-assistant/home-assistant/blob/master/homeassistant/remote.py"><code class="highlighter-rouge">homeassistant.remote</code></a> a Python API on top of the <a href="/developers/api/">HTTP API</a> can be found.</p>
|
||||
|
||||
<p>This page is not a full documentation it’s more a collection of some example. A simple way to get all current entities is to visit the “Set State” page in the “Developer Tools”. For the examples below just choose one from the available entries. Here the sensor <code class="highlighter-rouge">sensor.office_temperature</code> and the switch <code class="highlighter-rouge">switch.livingroom_pin_2</code> are used.</p>
|
||||
<p>Note: This page is not full documentation for this API, but a collection of examples showing its use.</p>
|
||||
|
||||
<p>First import the module and setup the basics.</p>
|
||||
<p>A simple way to get all current entities is to visit the “Set State” page in the “Developer Tools”. For the examples below just choose one from the available entries. Here the sensor <code class="highlighter-rouge">sensor.office_temperature</code> and the switch <code class="highlighter-rouge">switch.livingroom_pin_2</code> are used.</p>
|
||||
|
||||
<p>First import the module and setup the basics:</p>
|
||||
|
||||
<div class="language-python highlighter-rouge"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">homeassistant.remote</span> <span class="kn">as</span> <span class="nn">remote</span>
|
||||
|
||||
|
@ -102,7 +104,7 @@
|
|||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>This snippets shows how to use the <code class="highlighter-rouge">homeassistant.remote</code> package in another way.</p>
|
||||
<p>Here’s another way to use the <code class="highlighter-rouge">homeassistant.remote</code> package:</p>
|
||||
|
||||
<div class="language-python highlighter-rouge"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">homeassistant.remote</span> <span class="kn">as</span> <span class="nn">remote</span>
|
||||
|
||||
|
@ -115,7 +117,7 @@
|
|||
|
||||
<h3><a class="title-link" name="get-configuration" href="#get-configuration"></a> Get configuration</h3>
|
||||
|
||||
<p>Get the current configuration of a Home Asssitant instance.</p>
|
||||
<p>Get the current configuration of a Home Assistant instance:</p>
|
||||
|
||||
<div class="language-python highlighter-rouge"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">homeassistant.remote</span> <span class="kn">as</span> <span class="nn">remote</span>
|
||||
|
||||
|
@ -127,7 +129,7 @@
|
|||
|
||||
<h3><a class="title-link" name="get-details-about-services-events-and-entitites" href="#get-details-about-services-events-and-entitites"></a> Get details about services, events, and entitites</h3>
|
||||
|
||||
<p>Similar to the output in the “Developer Tools” of the frontend.</p>
|
||||
<p>The output from this is similar to the output you’d find via the frontend, using the DevTools console.</p>
|
||||
|
||||
<div class="language-python highlighter-rouge"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">homeassistant.remote</span> <span class="kn">as</span> <span class="nn">remote</span>
|
||||
|
||||
|
@ -152,7 +154,7 @@
|
|||
|
||||
<h3><a class="title-link" name="get-the-state-of-an-entity" href="#get-the-state-of-an-entity"></a> Get the state of an entity</h3>
|
||||
|
||||
<p>To get the details of a single entity the <code class="highlighter-rouge">get_state</code> method is used.</p>
|
||||
<p>To get the details of a single entity, use <code class="highlighter-rouge">get_state</code>:</p>
|
||||
|
||||
<div class="language-python highlighter-rouge"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">homeassistant.remote</span> <span class="kn">as</span> <span class="nn">remote</span>
|
||||
|
||||
|
@ -166,13 +168,13 @@
|
|||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>The output is composed out of the details which are stored for this entity.</p>
|
||||
<p>This outputs the details which are stored for this entity, ie:</p>
|
||||
|
||||
<div class="language-bash highlighter-rouge"><pre class="highlight"><code>Office Temperature is 19 °C.
|
||||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>The exact same thing is working for a switch. The difference is that both entities have different attributes.</p>
|
||||
<p>Switches work the same way. The only difference is that both entities have different attributes.</p>
|
||||
|
||||
<div class="language-python highlighter-rouge"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">homeassistant.remote</span> <span class="kn">as</span> <span class="nn">remote</span>
|
||||
|
||||
|
@ -187,7 +189,7 @@
|
|||
|
||||
<h3><a class="title-link" name="set-the-state-of-an-entity" href="#set-the-state-of-an-entity"></a> Set the state of an entity</h3>
|
||||
|
||||
<p>Of course, it’s possible to set the state.</p>
|
||||
<p>Of course, it’s possible to set the state as well:</p>
|
||||
|
||||
<div class="language-python highlighter-rouge"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">homeassistant.remote</span> <span class="kn">as</span> <span class="nn">remote</span>
|
||||
<span class="kn">from</span> <span class="nn">homeassistant.const</span> <span class="kn">import</span> <span class="n">STATE_ON</span>
|
||||
|
@ -198,11 +200,11 @@
|
|||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>The state will be set to those value until the next update occurs.</p>
|
||||
<p>The state will be set to the new values until the next update occurs.</p>
|
||||
|
||||
<h3><a class="title-link" name="blinking-all-entites-of-a-domain" href="#blinking-all-entites-of-a-domain"></a> Blinking all entites of a domain</h3>
|
||||
|
||||
<p>If you want to turn on all entities of a domain, just use a service which was retrieved by <code class="highlighter-rouge">get_services</code>.</p>
|
||||
<p>If you want to turn on all entities of a domain, retrieve the service via <code class="highlighter-rouge">get_services</code> and act on that:</p>
|
||||
|
||||
<div class="language-python highlighter-rouge"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">time</span>
|
||||
<span class="kn">import</span> <span class="nn">homeassistant.remote</span> <span class="kn">as</span> <span class="nn">remote</span>
|
||||
|
@ -218,7 +220,7 @@
|
|||
|
||||
<h3><a class="title-link" name="control-a-single-entity" href="#control-a-single-entity"></a> Control a single entity</h3>
|
||||
|
||||
<p>To turn on or off a single switch. The ID of the entity is needed as attribute.</p>
|
||||
<p>To turn on or off a single switch, pass the ID of the entity:</p>
|
||||
|
||||
<div class="language-python highlighter-rouge"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">time</span>
|
||||
<span class="kn">import</span> <span class="nn">homeassistant.remote</span> <span class="kn">as</span> <span class="nn">remote</span>
|
||||
|
@ -235,9 +237,9 @@
|
|||
|
||||
<h3><a class="title-link" name="specify-a-timeout" href="#specify-a-timeout"></a> Specify a timeout</h3>
|
||||
|
||||
<p>The default timeout for an API call with <code class="highlighter-rouge">call_service</code> is 5 seconds. Service
|
||||
<p>The default timeout for an API call with <code class="highlighter-rouge">call_service</code> is 5 seconds. Services
|
||||
taking longer than this to return will raise
|
||||
<code class="highlighter-rouge">homeassistant.exceptions.HomeAssistantError: Timeout</code> unless provided with a
|
||||
<code class="highlighter-rouge">homeassistant.exceptions.HomeAssistantError: Timeout</code>, unless provided with a
|
||||
longer timeout.</p>
|
||||
|
||||
<div class="language-python highlighter-rouge"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">homeassistant.remote</span> <span class="kn">as</span> <span class="nn">remote</span>
|
||||
|
@ -259,7 +261,7 @@ longer timeout.</p>
|
|||
|
||||
<h3><a class="title-link" name="send-a-notification" href="#send-a-notification"></a> Send a notification</h3>
|
||||
|
||||
<p>The example uses the jabber notification platform to send a single message to the given recipient in the <code class="highlighter-rouge">configuration.yaml</code> file.</p>
|
||||
<p>The example uses the Jabber notification platform to send a single message to the given recipient in the <code class="highlighter-rouge">configuration.yaml</code> file:</p>
|
||||
|
||||
<div class="language-python highlighter-rouge"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">homeassistant.remote</span> <span class="kn">as</span> <span class="nn">remote</span>
|
||||
|
||||
|
@ -271,7 +273,7 @@ longer timeout.</p>
|
|||
</code></pre>
|
||||
</div>
|
||||
|
||||
<p>For more details please check the source of <a href="https://github.com/home-assistant/home-assistant/blob/master/homeassistant/remote.py">homeassistant.remote</a>.</p>
|
||||
<p>For more details, please check the source of <a href="https://github.com/home-assistant/home-assistant/blob/master/homeassistant/remote.py">homeassistant.remote</a>.</p>
|
||||
|
||||
|
||||
</article>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue