606 lines
38 KiB
XML
606 lines
38 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
||
<feed xmlns="http://www.w3.org/2005/Atom">
|
||
|
||
<title><![CDATA[Category: How-To | Home Assistant]]></title>
|
||
<link href="https://home-assistant.io/blog/categories/how-to/atom.xml" rel="self"/>
|
||
<link href="https://home-assistant.io/"/>
|
||
<updated>2016-06-04T15:39:47+00:00</updated>
|
||
<id>https://home-assistant.io/</id>
|
||
<author>
|
||
<name><![CDATA[Paulus Schoutsen]]></name>
|
||
|
||
</author>
|
||
<generator uri="http://octopress.org/">Octopress</generator>
|
||
|
||
|
||
<entry>
|
||
<title type="html"><![CDATA[Static website]]></title>
|
||
<link href="https://home-assistant.io/blog/2016/04/07/static-website/"/>
|
||
<updated>2016-04-07T06:28:00+00:00</updated>
|
||
<id>https://home-assistant.io/blog/2016/04/07/static-website</id>
|
||
<content type="html"><![CDATA[<p>The frontend of Home Assistant is served with the help of a local web server. If you have <a href="/getting-started/devices/#customizing-devices-and-services">customized</a> your installation you already use this functionality. The content of your folder <code>www</code> in your Home Assistant configuration directory (<code>.homeassistant</code>) is available under <code>/local</code> (eg. <a href="https://localhost:8123/local">https://localhost:8123/local</a>).</p>
|
||
|
||
<p>But there is more you can do! You can not only host images for customization there but HTML files or even web applications including CSS and Javascript.</p>
|
||
|
||
<p class="img">
|
||
<img src="https://home-assistant.io/images/blog/2016-04-display/ha-display.png" />
|
||
</p>
|
||
|
||
<!--more-->
|
||
|
||
<p>In the past the buzz word “Smart mirror” was used a couple of times in our <a href="https://gitter.im/balloob/home-assistant">chatroom</a> and even made it into the <a href="https://github.com/home-assistant/home-assistant/issues/1392">issue tracker</a>. The existing solutions (<a href="http://docs.smart-mirror.io/">Smart mirror</a>, <a href="http://michaelteeuw.nl/tagged/magicmirror">MagicMirror</a>, and <a href="https://github.com/HannahMitt/HomeMirror">HomeMirror</a>) seems to be overkill if you already have Home Assistant running somewhere in your house or apartment. Why not simple display a web page served by Home Assistant on the tablet? No app and no Raspberry Pi running in the background.</p>
|
||
|
||
<p>There are plenty of ways to achieve this…<a href="/developers/rest_api/">RESTful API</a>, <a href="/developers/python_api/">Python API</a>, or one of the <a href="/components/#history">history components</a>. If it is to be a web page I’m using the <a href="/components/mqtt_eventstream/">MQTT Eventstream component</a> and <a href="http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt.javascript.git/tree/src">mqttws31.js</a>.</p>
|
||
|
||
<p>The <a href="https://pypi.python.org/pypi/hbmqtt">HBMQTT</a> broker provides websockets support for MQTT and mqttws31.js included in web page gives you access to the MQTT messages. It’s a matter of minutes. OK, it took a little longer because I’m not a Javascript guy to create the software part that will show details about your environment. The source is available at <a href="https://github.com/fabaff/home-assistant-display">https://github.com/fabaff/home-assistant-display</a> and the screenshot above shows the result. I guess that every person who is familiar with Javascript would be able to reduce the amount of code and to make it more flexible. Well, it’s a only prototype and showcase to include an image in this blog post.</p>
|
||
|
||
<p>I hope that this little article could give you an idea of extending Home Assistant in an unconventional way.</p>
|
||
|
||
]]></content>
|
||
</entry>
|
||
|
||
<entry>
|
||
<title type="html"><![CDATA[Multi-room audio with Snapcast, Mopidy, and Home Assistant]]></title>
|
||
<link href="https://home-assistant.io/blog/2016/02/18/multi-room-audio-with-snapcast/"/>
|
||
<updated>2016-02-18T05:10:56+00:00</updated>
|
||
<id>https://home-assistant.io/blog/2016/02/18/multi-room-audio-with-snapcast</id>
|
||
<content type="html"><![CDATA[<p>Would you like to listen to music in every room in your home, controlled from one source? Then multi-room audio is for you.</p>
|
||
|
||
<p>Multi-room audio can be achieved by having a computer attached to speakers in every room. On each computer, services run to play and/or control the audio. With this DIY approach, the kind of computer and speakers is very much up to you. It could be your desktop computer with attached powered speakers, your HTPC hooked up to your TV and receiver, a Raspberry Pi with Amp or DAC, or even an Android device.</p>
|
||
|
||
<p>You’ll need two key software packages, besides Home Assistant. The first is <a href="https://www.mopidy.com/">Mopidy</a>, a music server that can play local files, or connect to streaming music services like Spotify. The second is <a href="https://github.com/badaix/snapcast/">Snapcast</a>, which enables synchronized audio streaming across your network. Both can be integrated into Home Assistant. Each room audio device will run an instance of the Snapcast client, and optionally a Mopidy instance. Your server will run a special instance of Mopidy and the Snapcast server.</p>
|
||
|
||
<p>Finally, you also need a player to control Mopidy. Any MPD-compatible player will work, and there are several <a href="https://docs.mopidy.com/en/latest/ext/web/#ext-web">Mopidy-only web-based options</a> available. On Android, <a href="https://play.google.com/store/apps/details?id=se.anil.remotedy">Remotedy</a> is particularly nice since you can access multiple Mopidy instances in one place.</p>
|
||
|
||
<p>Home Assistant will provide device status, and volume control for each room. If you want to play music in all your rooms (on all your clients), access the server instance of Mopidy. If you want to play music only in a specific room, access that specific Mopidy instance. If you’re using a web UI for Mopidy, you can add links to each instance in Home Assistant with the <a href="/components/weblink/">weblink</a> component.</p>
|
||
|
||
<p class="img">
|
||
<img src="https://home-assistant.io/images/blog/2016-02-snapcast/diagram.png" />
|
||
</p>
|
||
|
||
<!--more-->
|
||
|
||
<h2>Staging</h2>
|
||
|
||
<ul>
|
||
<li><a href="https://www.mopidy.com/">Install</a> Mopidy (2.0.0 or greater)</li>
|
||
<li><a href="https://github.com/badaix/snapcast/releases/">Download</a> and <a href="https://github.com/badaix/snapcast/tree/v0.5.0-beta-1#installation">Install</a> Snapcast (0.5.0 or greater)</li>
|
||
</ul>
|
||
|
||
<h2>Configure Mopidy</h2>
|
||
|
||
<p>Mopidy can be run with multiple configuration files, each extending the previous file. This is helpful when we’re running multiple instances with varying functionality.</p>
|
||
|
||
<h3>core.conf</h3>
|
||
<p>The core configuration is shared between all instances:</p>
|
||
|
||
<div class="highlighter-coderay"><div class="CodeRay">
|
||
<div class="code"><pre>[mpd]
|
||
hostname = ::
|
||
|
||
[http]
|
||
hostname = ::
|
||
|
||
[audio]
|
||
output = alsasink
|
||
|
||
[spotify]
|
||
username = <redacted>
|
||
password = <redacted>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
|
||
<h3>local.conf</h3>
|
||
<p>Add the local configuration on computers that have local media files:</p>
|
||
|
||
<div class="highlighter-coderay"><div class="CodeRay">
|
||
<div class="code"><pre>[local]
|
||
media_dir = <your/music/here>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
|
||
<h3>snapcast.conf</h3>
|
||
<p>Finally, the Mopidy instance that connects with Snapcast needs special configuration. Run on a different port to avoid conflicts if you have a second Mopidy instance running on your computer. The audio output is sent to a named pipe - Snapcast will read from there. Note that you may have to adjust the audio output attribute depending on your system and audio sources.</p>
|
||
|
||
<div class="highlighter-coderay"><div class="CodeRay">
|
||
<div class="code"><pre>[mpd]
|
||
hostname = ::
|
||
port = 6601
|
||
|
||
[http]
|
||
hostname = ::
|
||
port = 6681
|
||
|
||
[audio]
|
||
output = audioresample ! audio/x-raw,rate=48000,channels=2,format=S16LE ! audioconvert ! wavenc ! filesink location=/tmp/snapfifo
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
|
||
<h2>Run Mopidy</h2>
|
||
|
||
<p>To run a room-specific instance:</p>
|
||
|
||
<div class="highlighter-coderay"><div class="CodeRay">
|
||
<div class="code"><pre>$ mopidy --config $CONF_DIR/core.conf
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
|
||
<p>To run a room-specific instance with local media:</p>
|
||
|
||
<div class="highlighter-coderay"><div class="CodeRay">
|
||
<div class="code"><pre>$ mopidy --config $CONF_DIR/core.conf:$CONF_DIR/local.conf
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
|
||
<p>To run the special Snapcast-connected instance (with local media):</p>
|
||
|
||
<div class="highlighter-coderay"><div class="CodeRay">
|
||
<div class="code"><pre>$ mopidy --config $CONF_DIR/core.conf:$CONF_DIR/local.conf:$CONF_DIR/snapcast.conf
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
|
||
<h2>Run Snapcast</h2>
|
||
|
||
<p>Start the <code>snapserver</code> on the same server running Mopidy with the snapcast configuration.</p>
|
||
|
||
<div class="highlighter-coderay"><div class="CodeRay">
|
||
<div class="code"><pre>$ snapserver # or use systemd
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
|
||
<p>Start the <code>snapclient</code> on computers that will be playing audio.</p>
|
||
|
||
<div class="highlighter-coderay"><div class="CodeRay">
|
||
<div class="code"><pre>$ snapclient # or use systemd, add -h <server host> if necessary
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
|
||
<h2>Configure Snapcast</h2>
|
||
|
||
<p>There are a number of snapcast configuration options, but the one relevant to Home Assistant is the client names. You can set them in the snapserver configuration file, by default located at <code>~/.config/Snapcast/settings.json</code>. Only edit this file while the <code>snapserver</code> is not running. Modify the <code>name</code> JSON value to your liking - this is how the client will be named in Home Assistant.</p>
|
||
|
||
<h2>Configure Home Assistant</h2>
|
||
|
||
<p>Use the <a href="/components/media_player.mpd/">mpd</a> and <a href="/components/media_player.snapcast/">snapcast</a> components. Optionally, use <a href="/components/weblink/">weblink</a> to provide easy access to a Mopidy web UI.</p>
|
||
|
||
<div class="highlighter-coderay"><div class="CodeRay">
|
||
<div class="code"><pre><span class="key">media_player</span>:
|
||
- <span class="string"><span class="content">platform: snapcast</span></span>
|
||
<span class="key">host</span>: <span class="string"><span class="content">xxxxx</span></span>
|
||
- <span class="string"><span class="content">platform: mpd</span></span>
|
||
<span class="key">server</span>: <span class="string"><span class="content">xxxx</span></span>
|
||
<span class="key">location</span>: <span class="string"><span class="content">Multi-Room Controller</span></span>
|
||
- <span class="string"><span class="content">platform: mpd</span></span>
|
||
<span class="key">server</span>: <span class="string"><span class="content">xxx</span></span>
|
||
<span class="key">location</span>: <span class="string"><span class="content">Room 1</span></span>
|
||
|
||
<span class="key">weblink</span>:
|
||
<span class="key">entities</span>:
|
||
- <span class="string"><span class="content">name: Multi-Room Player</span></span>
|
||
<span class="key">url</span>: <span class="string"><span class="content">xxxx</span></span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
|
||
]]></content>
|
||
</entry>
|
||
|
||
<entry>
|
||
<title type="html"><![CDATA[Smarter SmartThings with MQTT and Home Assistant]]></title>
|
||
<link href="https://home-assistant.io/blog/2016/02/09/smarter-smart-things-with-mqtt-and-home-assistant/"/>
|
||
<updated>2016-02-09T07:44:00+00:00</updated>
|
||
<id>https://home-assistant.io/blog/2016/02/09/Smarter-Smart-Things-with-MQTT-and-Home-Assistant</id>
|
||
<content type="html"><![CDATA[<p><em>This is a guest post by Home Assistant users <a href="https://github.com/jer">Jeremiah Wuenschel</a> and <a href="https://github.com/stjohnjohnson">St. John Johnson</a>.</em></p>
|
||
|
||
<p>So you own a <a href="http://smartthings.com">SmartThings</a> Hub. You probably bought it when you were looking to get into the whole Home Automation hobby because it worked with pretty much everything and offered you the ability to automate <strong>anything.</strong> After a week of ownership, you realized that building dashboards and automating required writing way more Groovy then you expected. Then one day you were browsing <a href="https://www.reddit.com/r/homeautomation">reddit</a> and discovered the amazingness that is Home Assistant! A solution that offered dashboards, graphs, working support for Nest, and REAL EASY automation!</p>
|
||
|
||
<p>You spent your weekend getting everything set up, showing it off to your significant other, but in the end you got stumped when it came to integrating with all your existing SmartThings toys. What do I do now? Should I buy another hub? Should I just buy a Z-Wave stick?</p>
|
||
|
||
<p>That’s where we came in. We wanted a solution that can bridge the awesomeness of Home Assistant with the SmartThings hub that works with almost everything.</p>
|
||
|
||
<p class="img">
|
||
<img src="https://home-assistant.io/images/blog/2016-02-smartthings/splash.png" />
|
||
</p>
|
||
|
||
<!--more-->
|
||
|
||
<h2>Glossary</h2>
|
||
|
||
<p>This is going to be a pretty detailed tutorial on setting up our SmartThings bridge. However, there are a couple key terms that <em>might</em> be new to you:</p>
|
||
|
||
<ul>
|
||
<li><a href="https://en.wikipedia.org/wiki/MQTT">MQTT</a>: A lightweight message protocol for listening and publishing events that happen. Many home automation platforms have built in support for this <a href="/components/mqtt/">(especially Home Assistant)</a>.</li>
|
||
<li><a href="https://www.docker.com/">Docker</a>: A tool for running applications that are self-contained. No need for installing any dependencies or worrying about conflicts. Installs easily on Linux and OSX.</li>
|
||
</ul>
|
||
|
||
<h2>Setting up the Bridge</h2>
|
||
|
||
<h3>MQTT</h3>
|
||
|
||
<p>Assuming that you already have Home Assistant and Smart Things running, you will first want to get an MQTT broker running. There are a handful of <a href="http://mosquitto.org/">MQTT</a> <a href="https://github.com/emqtt/emqttd">brokers</a> available in Open Source land. We chose <a href="http://www.mosca.io/">Mosca</a> for its simplicity.</p>
|
||
|
||
<p>There is very little you need to do to get Mosca running. The easiest approach is to use <a href="https://www.docker.com/">Docker</a>, and run a command like the following:</p>
|
||
|
||
<div class="highlighter-coderay"><div class="CodeRay">
|
||
<div class="code"><pre>$ docker run \
|
||
-d \
|
||
--name="mqtt" \
|
||
-v /opt/mosca:/db \
|
||
-p 1883:1883 \
|
||
matteocollina/mosca
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
|
||
<p>This will start Mosca up inside of a docker container, while keeping persistent storage for Mosca in <code>/opt/mosca</code>. The default configuration is the only thing we need to get things up and running.</p>
|
||
|
||
<p>If you don’t want to mess with Docker and can get node.js installed without trouble, the <a href="https://github.com/mcollina/mosca#standalone">standalone</a> instructions are all you need.</p>
|
||
|
||
<h3>MQTT Bridge</h3>
|
||
|
||
<p>This is the small piece of magic that bridges the gap between MQTT and SmartThings. It is a node.js app, and like Mosca it is probably easiest to install with Docker:</p>
|
||
|
||
<div class="highlighter-coderay"><div class="CodeRay">
|
||
<div class="code"><pre>$ docker run \
|
||
-d \
|
||
--name="mqtt-bridge" \
|
||
-v /opt/mqtt-bridge:/config \
|
||
-p 8080:8080 \
|
||
stjohnjohnson/smartthings-mqtt-bridge
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
|
||
<p>The code for this bridge is <a href="https://github.com/stjohnjohnson/smartthings-mqtt-bridge">on Github</a> if you want to start it up independently.</p>
|
||
|
||
<p>The MQTT Bridge only needs to know where your MQTT broker lives. If you are using these docker commands as-is, edit <code>/opt/mqtt-bridge/config.yml</code> to look like this:</p>
|
||
|
||
<div class="highlighter-coderay"><div class="CodeRay">
|
||
<div class="code"><pre><span class="head"><span class="head">---</span></span>
|
||
<span class="key">mqtt</span>:
|
||
<span class="key">host</span>: <span class="string"><span class="content"><IP of the host></span></span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
|
||
<p>Restart the bridge, and you are ready to go:</p>
|
||
|
||
<div class="highlighter-coderay"><div class="CodeRay">
|
||
<div class="code"><pre>$ docker restart mqtt-bridge
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
|
||
<h3>SmartThings Device</h3>
|
||
|
||
<p>The next step (and possibly the most confusing) is the device type. Go to the <a href="https://graph.api.smartthings.com/ide/devices">Smart Things Device IDE</a> and <code>Create New Device Handler</code>. Choose <code>From Code</code> and paste in the <a href="https://github.com/stjohnjohnson/smartthings-mqtt-bridge/blob/master/devicetypes/stj/mqtt-bridge.src/mqtt-bridge.groovy">MQTT Bridge Device Code</a>. Click <code>Save</code>, <code>Publish</code>, and then <code>For Me</code>.</p>
|
||
|
||
<p>Now to install your new Device Handler. Go back to <code>My Devices</code> in the IDE, and click <code>New Device</code>. Enter a name, and pick any random set of characters for the Device Network Id (this will automatically update later). For Type, scroll to the bottom of the list and find your newly created <code>MQTT Bridge</code>. Fill in the other boxes however you like.</p>
|
||
|
||
<p>Go back to <code>My Devices</code>, and click on your new device in the list. This will bring up a page that allows you to edit your device’s Preferences. Click <code>edit</code> and fill in the 3 pieces of information it asks for.</p>
|
||
|
||
<ul>
|
||
<li>MQTT Bridge IP Address: <IP address of the MQTT Bridge from the previous step></li>
|
||
<li>MQTT Bridge Port: <8080 if you have changed nothing in the previous commands></li>
|
||
<li>MQTT Bridge MAC Address: <Mac address of machine running the Bridge code></li>
|
||
</ul>
|
||
|
||
<p>This will create the link between SmartThings and the MQTT Bridge.</p>
|
||
|
||
<h3>SmartThings App</h3>
|
||
|
||
<p>The last step is to setup the SmartApp. After this, any registered devices will start sending their events to MQTT.</p>
|
||
|
||
<p>Go to the <a href="https://graph.api.smartthings.com/ide/apps">Smart App IDE</a>. Click <code>New SmartApp</code>, followed by <code>From Code</code>. Paste in the <a href="https://github.com/stjohnjohnson/smartthings-mqtt-bridge/blob/master/smartapps/stj/mqtt-bridge.src/mqtt-bridge.groovy">MQTT Bridge SmartApp code</a> and click <code>Save</code>. Click <code>Publish</code> and then <code>For Me</code>. In the SmartThings mobile app, add the new SmartApp and configure it with your devices and MQTT Bridge device. Clicking <code>done</code> will subscribe SmartThings to your MQTT broker and begin 2-way propagation of events.</p>
|
||
|
||
<h3>Configure Home Assistant</h3>
|
||
|
||
<p>To add SmartThings devices to Home Assistant over MQTT, first enable MQTT in Home Assistant:</p>
|
||
|
||
<div class="highlighter-coderay"><div class="CodeRay">
|
||
<div class="code"><pre><span class="key">mqtt</span>:
|
||
<span class="key">broker</span>: <span class="string"><span class="content">localhost</span></span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
|
||
<p>Replace <code>localhost</code> with the location of the running MQTT Broker. Devices from the MQTT Bridge are published to the path <code>smartthings/<Device Name>/<Atribute></code></p>
|
||
|
||
<p>For example, my Dimmer Z-Wave Lamp is called “Fireplace Lights” in SmartThings. The following topics are published:</p>
|
||
|
||
<table>
|
||
<thead>
|
||
<tr>
|
||
<th>Topic</th>
|
||
<th>Description</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>smartthings/Fireplace Lights/level</td>
|
||
<td>Brightness (0-99)</td>
|
||
</tr>
|
||
<tr>
|
||
<td>smartthings/Fireplace Lights/switch</td>
|
||
<td>Switch State (on/off)</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
|
||
<p>Here is an example Home Assistant config:</p>
|
||
|
||
<div class="highlighter-coderay"><div class="CodeRay">
|
||
<div class="code"><pre><span class="key">switch</span>:
|
||
<span class="key">platform</span>: <span class="string"><span class="content">mqtt</span></span>
|
||
<span class="key">name</span>: <span class="string"><span class="delimiter">"</span><span class="content">Fireplace Lights</span><span class="delimiter">"</span></span>
|
||
<span class="key">state_topic</span>: <span class="string"><span class="delimiter">"</span><span class="content">smartthings/Fireplace Lights/switch</span><span class="delimiter">"</span></span>
|
||
<span class="key">command_topic</span>: <span class="string"><span class="delimiter">"</span><span class="content">smartthings/Fireplace Lights/switch</span><span class="delimiter">"</span></span>
|
||
<span class="key">brightness_state_topic</span>: <span class="string"><span class="delimiter">"</span><span class="content">smartthings/Fireplace Lights/level</span><span class="delimiter">"</span></span>
|
||
<span class="key">brightness_command_topic</span>: <span class="string"><span class="delimiter">"</span><span class="content">smartthings/Fireplace Lights/level</span><span class="delimiter">"</span></span>
|
||
<span class="key">payload_on</span>: <span class="string"><span class="delimiter">"</span><span class="content">on</span><span class="delimiter">"</span></span>
|
||
<span class="key">payload_off</span>: <span class="string"><span class="delimiter">"</span><span class="content">off</span><span class="delimiter">"</span></span>
|
||
<span class="key">retain</span>: <span class="string"><span class="content">true</span></span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
|
||
<p>We recommend <code>retain: true</code> for every MQTT device in order to keep states in sync when things become disconnected.</p>
|
||
|
||
<p>Start digging through the <a href="/components/mqtt/">MQTT Components</a> in Home Assistant to find which components map to the new events being published to MQTT.</p>
|
||
|
||
<h3>Configuring with Docker-Compose</h3>
|
||
|
||
<p>Our personal preference for starting the whole suite of software is to use a single Docker-Compose file. Just create a file called <code>docker-compose.yml</code> like this:</p>
|
||
|
||
<div class="highlighter-coderay"><div class="CodeRay">
|
||
<div class="code"><pre><span class="key">mqtt</span>:
|
||
<span class="key">image</span>: <span class="string"><span class="content">matteocollina/mosca</span></span>
|
||
<span class="key">ports</span>:
|
||
- <span class="string"><span class="content">1883:1883</span></span>
|
||
|
||
<span class="key">mqttbridge</span>:
|
||
<span class="key">image</span>: <span class="string"><span class="content">stjohnjohnson/smartthings-mqtt-bridge</span></span>
|
||
<span class="key">volumes</span>:
|
||
- <span class="string"><span class="content">./mqtt-bridge:/config</span></span>
|
||
<span class="key">ports</span>:
|
||
- <span class="string"><span class="content">8080:8080</span></span>
|
||
<span class="key">links</span>:
|
||
- <span class="string"><span class="content">mqtt</span></span>
|
||
|
||
<span class="key">homeassistant</span>:
|
||
<span class="key">image</span>: <span class="string"><span class="content">homeassistant/home-assistant:latest</span></span>
|
||
<span class="key">ports</span>:
|
||
- <span class="string"><span class="content">80:80</span></span>
|
||
<span class="key">volumes</span>:
|
||
- <span class="string"><span class="content">./home-assistant:/config</span></span>
|
||
- <span class="string"><span class="content">/etc/localtime:/etc/localtime:ro</span></span>
|
||
<span class="key">links</span>:
|
||
- <span class="string"><span class="content">mqtt</span></span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
|
||
<p>This will start home-assistant, MQTT, and the Bridge, in dependency order. All config can reference the name of the docker container instead of using IP addresses (e.g. mqtt for the broker host in Home Assistant).</p>
|
||
|
||
<h3>How it works</h3>
|
||
|
||
<p><strong>HTTP Endpoint</strong>: There are really only 2 ways to communicate with the SmartThings hub that we could find. The easiest approach is to create a RESTful SmartApp authenticated with OAuth that provides state changes via HTTP directly. This approach is pretty straightforward to implement, but it requires communication with the SmartThings cloud service, and can’t be done entirely on your LAN. We hoped to keep all communication internal, and came up with a second approach.</p>
|
||
|
||
<p><strong>Custom Device Type:</strong> SmartThings custom device types allow developers to define handlers for HTTP events received directly over the local network by the SmartThings hub. Messages received are authenticated by MAC address, and can contain arbitrary strings in their payload. Since a Device Type is only ever tied to a single device, we need to add a SmartApp to the mix in order to translate events between individual devices and our special Home Assistant Bridge device. Here is what we have so far:</p>
|
||
|
||
<div class="highlighter-coderay"><div class="CodeRay">
|
||
<div class="code"><pre>Z-Wave Switch |
|
||
Zigbee motion sensor |<---> Bridge App <---> Bridge Device Type <---> <Local network>
|
||
Z-Wave light bulb |
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
|
||
<p>On the Home Assistant side, there is a powerful platform available based on the MQTT lightweight message bus protocol. Everything from lights to switches to temperature sensors can be defined in Home Assistant as an MQTT component, so it makes for a convenient integration point. This requires an MQTT broker for handling the message bus, and one last piece to translate between the HTTP that SmartThings supports and MQTT.</p>
|
||
|
||
<p>Here is the final sequence of events:</p>
|
||
|
||
<p class="img">
|
||
<a href="https://home-assistant.io/images/blog/2016-02-smartthings/SmartThings-HomeAssistant.png">
|
||
<img src="https://home-assistant.io/images/blog/2016-02-smartthings/SmartThings-HomeAssistant.png" alt="SmartThings Bridge Sequence" />
|
||
</a>
|
||
SmartThings Bridge Sequence
|
||
</p>
|
||
|
||
<p>There are a lot of stops along the way for these events, but each piece is a simple translation layer to shuttle the events between systems.</p>
|
||
|
||
<h3>Future Improvements</h3>
|
||
<ul>
|
||
<li><strong>Raspberry pi</strong>: There is a lot of interest in getting this running on the Raspberry Pi. It only requires binaries compiled for ARM, so we plan to get ARM-compatible versions of the containers going at some point.</li>
|
||
<li><strong>Authentication for MQTT</strong>: At the moment, the MQTT bridge doesn’t understand how to authenticate to MQTT, so only unauthenticated MQTT is supported. This is mitigated to some degree if you use our Docker Compose config, because MQTT’s port is not actually shared publicly.</li>
|
||
<li><strong>Authentication for MQTT Bridge</strong>: Right now the bridge expects that anyone subscribing is the SmartThings hub. This could use proper authentication.</li>
|
||
</ul>
|
||
|
||
]]></content>
|
||
</entry>
|
||
|
||
<entry>
|
||
<title type="html"><![CDATA[Set up encryption using Let's Encrypt]]></title>
|
||
<link href="https://home-assistant.io/blog/2015/12/13/setup-encryption-using-lets-encrypt/"/>
|
||
<updated>2015-12-13T18:05:00+00:00</updated>
|
||
<id>https://home-assistant.io/blog/2015/12/13/setup-encryption-using-lets-encrypt</id>
|
||
<content type="html"><![CDATA[<p>Exposing your Home Assistant instance outside of your network always has been tricky. You have to set up port forwarding on your router and most likely add a dynamic DNS service to work around your ISP changing your IP. After this you would be able to use Home Assistant from anywhere but there is one big red flag: no encryption.</p>
|
||
|
||
<p>This tutorial will take you through the steps to setup a dynamic DNS for your IP and allow trusted encrypted connection to it - for free using <a href="https://duckdns.org">DuckDNS</a> and <a href="https://letsencrypt.org">Let’s Encrypt</a>.</p>
|
||
|
||
<p class="img">
|
||
<img src="https://home-assistant.io/images/blog/2015-12-lets-encrypt/letsencrypt-secured.png" />
|
||
</p>
|
||
|
||
<!--more-->
|
||
|
||
<h3><a class='title-link' name='requirements' href='#requirements'></a> Requirements </h3>
|
||
|
||
<p>The DuckDNS part of this tutorial has no requirements but there are a few requirements as of now to run the Let’s Encrypt client.</p>
|
||
|
||
<ul>
|
||
<li>Direct connection to the internet or admin access to your router to set up port forwarding</li>
|
||
<li>A machine running a Unix-ish OS that include Python 2.6 or 2.7 (Docker can be used)</li>
|
||
</ul>
|
||
|
||
<p><img src="https://home-assistant.io/images/supported_brands/duckdns.png" style="clear: right; border:none; box-shadow: none; float: right; margin-left: 8px; margin-bottom: 8px;" width="60" /></p>
|
||
|
||
<h3><a class='title-link' name='duckdns' href='#duckdns'></a> DuckDNS </h3>
|
||
|
||
<p>The first step is to set up <a href="https://duckdns.org">DuckDNS</a>. This is a free dynamic DNS service that you can use to get a DuckDNS.org subdomain to point at your house. A dynamic DNS service works by having your home computer tell DuckDNS.org every 5 minutes what its IP is so that DuckDNS can make sure your domain name is set up correctly.</p>
|
||
|
||
<p>For this example we will assume our domain is hass-example.duckdns.org.</p>
|
||
|
||
<p>First step is to acquire and set up our domain name. For this, go to <a href="https://duckdns.org">DuckDNS</a>, log in with any of the supported login providers and add a domain. After this check out their <a href="https://www.duckdns.org/install.jsp">installation instructions</a> to finish your installation of DuckDNS. If you’re on a Raspberry Pi, see ‘Pi’ in the category ‘Operating Systems’.</p>
|
||
|
||
<p><img src="https://home-assistant.io/images/supported_brands/letsencrypt.png" style="clear: right; border:none; box-shadow: none; float: right; margin-left: 8px; margin-bottom: 8px;" width="60" /></p>
|
||
|
||
<h3><a class='title-link' name='lets-encrypt' href='#lets-encrypt'></a> Let’s Encrypt </h3>
|
||
|
||
<p><a href="https://letsencrypt.org">Let’s Encrypt</a> is a free, automated, and open certificate authority (CA). We will use this to acquire a certificate that can be used to encrypted our connection with Home Assistant.</p>
|
||
|
||
<p>Let’s Encrypt will give you a free 90-day certificate if you pass their domain validation challenge. Domains are validated by having certain data be accessible on your domain for Let’s Encrypt (<a href="https://letsencrypt.org/howitworks/technology/">they describe it better themselves</a>).</p>
|
||
|
||
<p>Assuming that your home is behind a router, the first thing to do is to set up port forwarding from your router to your computer that will run Let’s Encrypt. For the Let’s Encrypt set up we need to temporary forward ports <code>80</code> (http connections) and <code>443</code> (https connections). This can be set up by accessing your router admin interface (<a href="http://portforward.com">Site with port forwarding instructions per router</a>).</p>
|
||
|
||
<p>Now you’re ready to run Let’s Encrypt:</p>
|
||
|
||
<div class="highlighter-coderay"><div class="CodeRay">
|
||
<div class="code"><pre>$ git clone https://github.com/letsencrypt/letsencrypt
|
||
[…]
|
||
$ cd letsencrypt
|
||
$ ./letsencrypt-auto certonly --email your@email.address -d hass-example.duckdns.org
|
||
|
||
Updating letsencrypt and virtual environment dependencies.......
|
||
Running with virtualenv: sudo /path/letsencrypt/bin/letsencrypt certonly --email your@e-mail.address -d hass-example.duckdns.org
|
||
|
||
IMPORTANT NOTES:
|
||
- Congratulations! Your certificate and chain have been saved at
|
||
/etc/letsencrypt/live/hass-example.duckdns.org/fullchain.pem. Your cert
|
||
will expire on 2016-03-12. To obtain a new version of the
|
||
certificate in the future, simply run Let's Encrypt again.
|
||
- If like Let's Encrypt, please consider supporting our work by:
|
||
|
||
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
|
||
Donating to EFF: https://eff.org/donate-le
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
|
||
<p>If you’re using Docker, run the following command to generate the required keys:</p>
|
||
|
||
<div class="highlighter-coderay"><div class="CodeRay">
|
||
<div class="code"><pre>sudo mkdir /etc/letsencrypt /var/lib/letsencrypt
|
||
sudo docker run -it --rm -p 443:443 -p 80:80 --name letsencrypt \
|
||
-v "/etc/letsencrypt:/etc/letsencrypt" \
|
||
-v "/var/lib/letsencrypt:/var/lib/letsencrypt" \
|
||
quay.io/letsencrypt/letsencrypt:latest certonly \
|
||
--email your@e-mail.address -d hass-example.duckdns.org
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
|
||
<p>With either method your certificate will be generated and put in the directory <code>/etc/letsencrypt/live/hass-example.duckdns.org</code>. As the lifetime is only 90 days, you will have to repeat this every 90 days.</p>
|
||
|
||
<p><img width="60" src="https://home-assistant.io/images/favicon-192x192.png" style="float: right; border:none; box-shadow: none;" /></p>
|
||
|
||
<h3><a class='title-link' name='home-assistant' href='#home-assistant'></a> Home Assistant </h3>
|
||
|
||
<p>Before updating the Home Assistant configuration, we have to update the port forwarding at your router config. We can drop the port forwarding for port <code>80</code> as we no longer care about unecrypted messages. Update port <code>443</code> to forward to port <code>8123</code> on the computer that will run Home Assistant.</p>
|
||
|
||
<p>The final step is to point Home Assistant at the generated certificates. Before you do this, make sure that the user running Home Assistant has read access to the folder that holds the certificates.</p>
|
||
|
||
<div class="highlighter-coderay"><div class="CodeRay">
|
||
<div class="code"><pre><span class="key">http</span>:
|
||
<span class="key">api_password</span>: <span class="string"><span class="content">YOUR_SECRET_PASSWORD</span></span>
|
||
<span class="key">ssl_certificate</span>: <span class="string"><span class="content">/etc/letsencrypt/live/hass.example.com/fullchain.pem</span></span>
|
||
<span class="key">ssl_key</span>: <span class="string"><span class="content">/etc/letsencrypt/live/hass.example.com/privkey.pem</span></span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
|
||
<p>You can now navigate to https://hass-example.duckdns.org and enjoy encryption!</p>
|
||
|
||
<p><em>Big thanks to Fabian Affolter for his help and feedback on this article.</em></p>
|
||
|
||
]]></content>
|
||
</entry>
|
||
|
||
<entry>
|
||
<title type="html"><![CDATA[Activating Tasker tasks from Home Assistant using command line switches]]></title>
|
||
<link href="https://home-assistant.io/blog/2015/12/10/activating-tasker-tasks-from-home-assistant-using-command-line-switches/"/>
|
||
<updated>2015-12-10T10:39:41+00:00</updated>
|
||
<id>https://home-assistant.io/blog/2015/12/10/activating-tasker-tasks-from-home-assistant-using-command-line-switches</id>
|
||
<content type="html"><![CDATA[<p><img src="https://home-assistant.io/images/blog/2015-12-tasker/tasker-logo.png" style="clear: right; border:none; box-shadow: none; float: right; margin-bottom: 12px;" width="200" /><br />
|
||
In this tutorial I will explain how you can activate Tasker tasks from Home Assistant command line switches. We are going to set up a switch that when toggled will make your Android device say either “On” or “Off”.</p>
|
||
|
||
<p>You could also do this with the automation component instead so whenever you put your house to sleep mode for example your Android device will open up Google Play Books or the Kindle app ready for you to read as well as dimming your lights, but this tutorial is all about the switches.</p>
|
||
|
||
<!--more-->
|
||
|
||
<h3>AutoRemote URL</h3>
|
||
|
||
<p>First things first you should install <a href="https://play.google.com/store/apps/details?id=net.dinglisch.android.taskerm">Tasker</a> and <a href="https://play.google.com/store/apps/details?id=com.joaomgcd.autoremote">AutoRemote</a> onto your Android device and launch AutoRemote. You should see a URL above the QR code, visit it in your browser and it should bring up a page a bit like this.</p>
|
||
|
||
<p class="img">
|
||
<img src="https://home-assistant.io/images/blog/2015-12-tasker/screenshot-1.png" />
|
||
</p>
|
||
|
||
<p>Now type in <code>SayOn</code> in the <code>Message</code> box and you should see a box appear on the right with a URL in it, this is what we will be using in the Python script later on so save that for later. Do the same thing again but this time replace <code>SayOn</code> with <code>SayOff</code>. Now just click the <code>Send message now!</code> button to test that your commands will get sent to your Android device, if they do you will see a toast message at the bottom of your screen like this one.</p>
|
||
|
||
<p class="img">
|
||
<img src="https://home-assistant.io/images/blog/2015-12-tasker/screenshot-2.png" height="450" />
|
||
</p>
|
||
|
||
<h3>Tasker Setup</h3>
|
||
|
||
<p>Open up Tasker and make sure you’re in the <code>PROFILES</code> tab, then select the plus icon to create a new profile. Select <code>Event</code> -> <code>Plugin</code> -> <code>AutoRemote</code> -> <code>AutoRemote</code> and then the pencil icon to configure the AutoRemote event. Select <code>Message Filter</code> and enter in <code>SayOn</code> then go back until it asks you for a task. Select <code>New task</code> then just leave the next field blank and select the tick icon. <br />
|
||
This is where we’ll configure our task, so select the plus icon to select an action. Select <code>Alert</code> -> <code>Say</code> to add a Say action. Enter <code>On</code> in the text field and go back to test your task, make sure your media volume is up then select the play icon, you should hear your device say “On”.</p>
|
||
|
||
<p class="img">
|
||
<img src="https://home-assistant.io/images/blog/2015-12-tasker/screenshot-3.png" height="450" />
|
||
</p>
|
||
|
||
<p>Now you can go back to the main Tasker screen and create another profile but this time replace <code>SayOn</code> with <code>SayOff</code> and <code>On</code> with <code>Off</code>. After you’ve done that go to the main screen again and select the menu button at the top then <code>Exit</code> and <code>Save first</code> to make sure everything is saved properly.</p>
|
||
|
||
<h3>Python Script</h3>
|
||
|
||
<p>Now it’s time to set it up the script, so create a new Python script and name it <code>On.py</code> then enter this code:</p>
|
||
|
||
<div class="highlighter-coderay"><div class="CodeRay">
|
||
<div class="code"><pre><span class="keyword">import</span> <span class="include">requests</span>
|
||
requests.get(<span class="string"><span class="delimiter">'</span><span class="content">[URL]</span><span class="delimiter">'</span></span>)
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
|
||
<p>Enter in your “On” URL then save it. Create another script but this time call it <code>Off.py</code> and enter your “off” URL instead.</p>
|
||
|
||
<h3>Home Assistant Configuration</h3>
|
||
|
||
<p>Add a command line switch to your Home Assistant configuration:</p>
|
||
|
||
<div class="highlighter-coderay"><div class="CodeRay">
|
||
<div class="code"><pre><span class="key">switch</span>:
|
||
<span class="key">platform</span>: <span class="string"><span class="content">command_switch</span></span>
|
||
<span class="key">switches</span>:
|
||
<span class="key">tasker_say</span>:
|
||
<span class="key">oncmd</span>: <span class="string"><span class="content">python "[LocationOfOnScript]"</span></span>
|
||
<span class="key">offcmd</span>: <span class="string"><span class="content">python "[LocationOfOffScript]"</span></span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
|
||
<p>Now load up Home Assistant and whenever you toggle the switch you created your Android device will respond with either “On” or “Off”. :-)</p>
|
||
]]></content>
|
||
</entry>
|
||
|
||
</feed>
|