Site updated at 2017-05-28 16:56:49 UTC

This commit is contained in:
Travis CI 2017-05-28 16:56:49 +00:00
parent 8dad267f01
commit 35e2b7fbc4
25 changed files with 53 additions and 39 deletions

View file

@ -80,11 +80,25 @@
<li><strong>name</strong> (<em>Optional</em>): Name of the REST switch.</li>
<li><strong>body_on</strong> (<em>Optional</em>): The body of the POST request that commands the switch to become enabled. Default is “ON”. This value can be a <a href="/topics/templating/">template</a>, which is useful if the POST request needs to depend on the state of the system. For example, to enable remote-temperature-sensor tracking on a radio thermostat, one has to send the current value of the remote temperature sensor. On can achieve this using the template <code class="highlighter-rouge">'{"rem_temp":}'</code>.</li>
<li><strong>body_off</strong> (<em>Optional</em>): The body of the POST request that commands the switch to become disabled. Default is “OFF”. This value can also be a template.</li>
<li><strong>is_on_template</strong> (<em>Optional</em>): A <a href="/topics/templating/">template</a> that determines the state of the switch from the value returned by the GET request on the resource url. This template should compute to a boolean (True or False). Default is equivalent to <code class="highlighter-rouge">'{{ value.json == body_on }}'</code>. This means that by default, the state of the switch is on if and only if the response to the GET request matches <code class="highlighter-rouge">body_on</code>.</li>
<li><strong>is_on_template</strong> (<em>Optional</em>): A <a href="/topics/templating/">template</a> that determines the state of the switch from the value returned by the GET request on the resource url. This template should compute to a boolean (True or False). If the value is valid JSON, it will be available in the template as the variable value_json. See <a href="/docs/configuration/templating/#processing-incoming-data">this example</a> in the template docs. Default is equivalent to <code class="highlighter-rouge">'{{ value_json == body_on }}'</code>. This means that by default, the state of the switch is on if and only if the response to the GET request matches <code class="highlighter-rouge">body_on</code>.</li>
</ul>
<p class="note warning">
Make sure that the URL matches exactly your endpoint or resource.
</p>
<h2><a class="title-link" name="example" href="#example"></a> Example</h2>
<h3><a class="title-link" name="switch-with-templated-value" href="#switch-with-templated-value"></a> Switch with templated value</h3>
<p>This example shows a switch that uses a <a href="/topics/templating/">template</a> to allow Home Assistant to determine its state. In this example the REST endpoint returns this JSON response with true indicating the switch is on.</p>
<div class="language-json highlighter-rouge"><pre class="highlight"><code><span class="p">{</span><span class="nt">"is_active"</span><span class="p">:</span><span class="w"> </span><span class="s2">"true"</span><span class="p">}</span><span class="w">
</span></code></pre>
</div>
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="s">switch</span><span class="pi">:</span>
<span class="pi">-</span> <span class="s">platform</span><span class="pi">:</span> <span class="s">rest</span>
<span class="s">resource</span><span class="pi">:</span> <span class="s">http://&lt;address&gt;/led_endpoint</span>
<span class="s">body_on</span><span class="pi">:</span> <span class="s1">'</span><span class="s">{"active":</span><span class="nv"> </span><span class="s">"true"}'</span>
<span class="s">body_off</span><span class="pi">:</span> <span class="s1">'</span><span class="s">{"active":</span><span class="nv"> </span><span class="s">"false"}'</span>
<span class="s">is_on_template</span><span class="pi">:</span> <span class="s1">'</span><span class="s">{{value_json.is_active}}'</span>
</code></pre>
</div>
</article>
</div>
<aside id="sidebar" class="grid__item one-third lap-one-whole palm-one-whole">