Site updated at 2018-01-27 19:39:56 UTC

This commit is contained in:
Travis CI 2018-01-27 19:39:56 +00:00
parent 50afaf1c94
commit 53a7f38cfc
28 changed files with 121 additions and 67 deletions

View file

@ -76,7 +76,7 @@
<hr class="divider">
<p>The <code class="highlighter-rouge">mqtt</code> binary sensor platform uses an MQTT message payload to set the binary sensor to one of two states: <code class="highlighter-rouge">on</code> or <code class="highlighter-rouge">off</code>.</p>
<p>The binary sensor state will be updated only after a new message is published on <code class="highlighter-rouge">state_topic</code> matching <code class="highlighter-rouge">payload_on</code> or <code class="highlighter-rouge">payload_off</code>. If these messages are published with the <code class="highlighter-rouge">retain</code> flag set, the binary sensor will receive an instant state update after subscription and Home Assistant will display the correct state on startup. Otherwise, the initial state displayed in Home Assistant will be <code class="highlighter-rouge">unknown</code>.</p>
<p>The <code class="highlighter-rouge">mqtt</code> binary sensor platform optionally supports an <code class="highlighter-rouge">availability_topic</code> to receive online and offline messages (birth and LWT messages) from the MQTT device. During normal operation, if the MQTT cover device goes offline (i.e. publishes <code class="highlighter-rouge">payload_not_available</code> to <code class="highlighter-rouge">availability_topic</code>), Home Assistant will display the binary sensor as <code class="highlighter-rouge">unavailable</code>. If these messages are published with the <code class="highlighter-rouge">retain</code> flag set, the binary sensor will receive an instant update after subscription and Home Assistant will display the correct availability state of the binary sensor when Home Assistant starts up. If the <code class="highlighter-rouge">retain</code> flag is not set, Home Assistant will display the binary sensor as <code class="highlighter-rouge">unavailable</code> when Home Assistant starts up. If no <code class="highlighter-rouge">availability_topic</code> is defined, Home Assistant will consider the MQTT device to be available.</p>
<p>The <code class="highlighter-rouge">mqtt</code> binary sensor platform optionally supports an <code class="highlighter-rouge">availability_topic</code> to receive online and offline messages (birth and LWT messages) from the MQTT device. During normal operation, if the MQTT cover device goes offline (i.e., publishes <code class="highlighter-rouge">payload_not_available</code> to <code class="highlighter-rouge">availability_topic</code>), Home Assistant will display the binary sensor as <code class="highlighter-rouge">unavailable</code>. If these messages are published with the <code class="highlighter-rouge">retain</code> flag set, the binary sensor will receive an instant update after subscription and Home Assistant will display the correct availability state of the binary sensor when Home Assistant starts up. If the <code class="highlighter-rouge">retain</code> flag is not set, Home Assistant will display the binary sensor as <code class="highlighter-rouge">unavailable</code> when Home Assistant starts up. If no <code class="highlighter-rouge">availability_topic</code> is defined, Home Assistant will consider the MQTT device to be available.</p>
<p>To use an MQTT binary sensor in your installation, add the following to your <code class="highlighter-rouge">configuration.yaml</code> file:</p>
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="c1"># Example configuration.yaml entry</span>
<span class="s">binary_sensor</span><span class="pi">:</span>
@ -135,6 +135,9 @@
</dd>
</dl>
</div>
<h2><a class="title-link" name="examples" href="#examples"></a> Examples</h2>
<p>In this section, you will find some real-life examples of how to use this sensor.</p>
<h3><a class="title-link" name="full-configuration" href="#full-configuration"></a> Full configuration</h3>
<p>To test, you can use the command line tool <code class="highlighter-rouge">mosquitto_pub</code> shipped with <code class="highlighter-rouge">mosquitto</code> or the <code class="highlighter-rouge">mosquitto-clients</code> package to send MQTT messages. To set the state of the binary sensor manually:</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span>mosquitto_pub -h 127.0.0.1 -t home-assistant/window/contact -m <span class="s2">"OFF"</span>
</code></pre>
@ -155,6 +158,24 @@
<span class="s">value_template</span><span class="pi">:</span> <span class="s1">'</span><span class="s">{{</span><span class="nv"> </span><span class="s">value.x</span><span class="nv"> </span><span class="s">}}'</span>
</code></pre>
</div>
<h3><a class="title-link" name="get-the-state-of-a-device-with-espeasy" href="#get-the-state-of-a-device-with-espeasy"></a> Get the state of a device with ESPEasy</h3>
<p>Assuming that you have flashed your ESP8266 unit with <a href="https://github.com/letscontrolit/ESPEasy">ESPEasy</a>. Under “Config” is a name (“Unit Name:”) set for your device (here its “bathroom”). A configuration for a “Controller” for MQTT with the protocol “OpenHAB MQTT” is present and the entries (“Controller Subscribe:” and “Controller Publish:”) are adjusted to match your needs. In this example, the topics are prefixed with “home”. Also, add a “Switch Input” in the “Devices” tap with the name “switch” and “button” as value.</p>
<p>As soon as the unit is online, you will get the state of the attached button.</p>
<div class="language-bash highlighter-rouge"><pre class="highlight"><code>home/bathroom/status Connected
...
home/bathroom/switch/button 1
</code></pre>
</div>
<p>The configuration will look like the example below:</p>
<div class="language-yaml highlighter-rouge"><pre class="highlight"><code><span class="c1"># Example configuration.yml entry</span>
<span class="s">binary_sensor</span><span class="pi">:</span>
<span class="pi">-</span> <span class="s">platform</span><span class="pi">:</span> <span class="s">mqtt</span>
<span class="s">name</span><span class="pi">:</span> <span class="s">Bathroom</span>
<span class="s">state_topic</span><span class="pi">:</span> <span class="s2">"</span><span class="s">home/bathroom/switch/button"</span>
<span class="s">payload_on</span><span class="pi">:</span> <span class="s2">"</span><span class="s">1"</span>
<span class="s">payload_off</span><span class="pi">:</span> <span class="s2">"</span><span class="s">0"</span>
</code></pre>
</div>
</article>
</div>
<aside id="sidebar" class="grid__item one-third lap-one-whole palm-one-whole">