home-assistant.github.io/blog/2016/02/09/smarter-smart-things-with-mqtt-and-home-assistant/index.html
2016-03-21 19:41:32 +00:00

516 lines
No EOL
25 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Smarter SmartThings with MQTT and Home Assistant - Home Assistant</title>
<meta name="author" content="Paulus Schoutsen">
<meta name="description" content="Jer and St. John describe how they connected SmartThings with Home Assistant.">
<meta name="viewport" content="width=device-width">
<link rel="canonical" href="https://home-assistant.io/blog/2016/02/09/smarter-smart-things-with-mqtt-and-home-assistant/">
<meta property="fb:app_id" content="338291289691179">
<meta property="og:title" content="Smarter SmartThings with MQTT and Home Assistant">
<meta property="og:site_name" content="Home Assistant">
<meta property="og:url" content="https://home-assistant.io/blog/2016/02/09/smarter-smart-things-with-mqtt-and-home-assistant/">
<meta property="og:type" content="article">
<meta property="og:description" content="Jer and St. John describe how they connected SmartThings with Home Assistant.">
<meta property="og:image" content="https://home-assistant.io/images/blog/2016-02-smartthings/social.png">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@home_assistant">
<meta name="twitter:title" content="Smarter SmartThings with MQTT and Home Assistant">
<meta name="twitter:description" content="Jer and St. John describe how they connected SmartThings with Home Assistant.">
<meta name="twitter:image" content="https://home-assistant.io/images/blog/2016-02-smartthings/social.png">
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet">
<link href="/atom.xml" rel="alternate" title="Home Assistant" type="application/atom+xml">
<link rel='shortcut icon' href='/images/favicon.ico' />
<link rel='icon' type='image/png' href='/images/favicon-192x192.png' sizes='192x192' />
</head>
<body >
<header>
<div class="grid-wrapper">
<div class="grid">
<div class="grid__item three-tenths lap-two-sixths palm-one-whole ha-title">
<a href="/" class="site-title">
<img width='40' src='/demo/favicon-192x192.png'>
<span>Home Assistant</span>
</a>
</div>
<div class="grid__item seven-tenths lap-four-sixths palm-one-whole">
<nav>
<input type="checkbox" id="toggle">
<label for="toggle" class="toggle" data-open="Main Menu" data-close="Close Menu"></label>
<ul class="menu pull-right">
<li>
<a>Getting started <i class="icon icon-caret-down"></i></a>
<ul>
<li><a href='/getting-started/'>Installing Home Assistant</a></li>
<li><a href='/getting-started/configuration/'>Configuration Basics</a></li>
<li><a href='/getting-started/devices/'>Adding devices</a></li>
<li><a href='/getting-started/presence-detection/'>Presence Detection</a></li>
<li><a href='/getting-started/automation/'>Automation</a></li>
<li><a href='/topics/'>Advanced Topics</a></li>
</ul>
</li>
<li><a href='/components/'>Components</a></li>
<li><a href='/cookbook'>Examples</a></li>
<li>
<a>Developers <i class="icon icon-caret-down"></i></a>
<ul>
<li><a href="/developers/">Setup Development</a></li>
<li><a href="/developers/architecture/">Architecture</a></li>
<li><a href="/developers/frontend/">Frontend Development</a></li>
<li><a href="/developers/creating_components/">
Creating Components
</a></li>
<li><a href="/developers/add_new_platform/">
Adding Platform Support
</a></li>
<li><a href="/developers/api/">API</a></li>
<li><a href="/developers/credits/">Credits</a></li>
</ul>
</li>
<li><a href="/blog/">Blog</a></li>
<li><a href="/help/">Need help?</a></li>
</ul>
</nav>
</div>
</div>
</div>
</header>
<div class="grid-wrapper">
<div class="grid grid-center">
<div class="grid__item two-thirds lap-one-whole palm-one-whole">
<article class="post">
<header>
<h1 class="title indent">Smarter SmartThings with MQTT and Home Assistant</h1>
<div class="meta clearfix">
<time datetime="2016-02-09T07:44:00+00:00" pubdate data-updated="true"><i class="icon-calendar"></i> February 09, 2016</time>
<span class="byline author vcard"><i class='icon-user'></i> Jeremiah Wuenschel and St. John Johnson</span>
<span><i class='icon-time'></i> eight minutes reading time</span>
<span>
<i class="icon-tags"></i>
<ul class="tags unstyled">
<li><a class='category' href='/blog/categories/how-to/'>How-To</a></li>
<li><a class='category' href='/blog/categories/mqtt/'>MQTT</a></li>
</ul>
</span>
<a class='comments'
href="#disqus_thread"
>Comments</a>
</div>
</header>
<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>Thats 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="/images/blog/2016-02-smartthings/splash.png" />
</p>
<a name="read-more"></a>
<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=&quot;mqtt&quot; \
-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 dont 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=&quot;mqtt-bridge&quot; \
-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">&lt;IP of the host&gt;</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 devices Preferences. Click <code>edit</code> and fill in the 3 pieces of information it asks for.</p>
<ul>
<li>MQTT Bridge IP Address: &lt;IP address of the MQTT Bridge from the previous step&gt;</li>
<li>MQTT Bridge Port: &lt;8080 if you have changed nothing in the previous commands&gt;</li>
<li>MQTT Bridge MAC Address: &lt;Mac address of machine running the Bridge code&gt;</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/&lt;Device Name&gt;/&lt;Atribute&gt;</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">&quot;</span><span class="content">Fireplace Lights</span><span class="delimiter">&quot;</span></span>
<span class="key">state_topic</span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">smartthings/Fireplace Lights/switch</span><span class="delimiter">&quot;</span></span>
<span class="key">command_topic</span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">smartthings/Fireplace Lights/switch</span><span class="delimiter">&quot;</span></span>
<span class="key">brightness_state_topic</span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">smartthings/Fireplace Lights/level</span><span class="delimiter">&quot;</span></span>
<span class="key">brightness_command_topic</span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">smartthings/Fireplace Lights/level</span><span class="delimiter">&quot;</span></span>
<span class="key">payload_on</span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">on</span><span class="delimiter">&quot;</span></span>
<span class="key">payload_off</span>: <span class="string"><span class="delimiter">&quot;</span><span class="content">off</span><span class="delimiter">&quot;</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">balloob/home-assistant</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 cant 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 |&lt;---&gt; Bridge App &lt;---&gt; Bridge Device Type &lt;---&gt; &lt;Local network&gt;
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="/images/blog/2016-02-smartthings/SmartThings-HomeAssistant.png">
<img src="/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 doesnt 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 MQTTs 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>
</article>
<section id="disqus">
<h3 class="indent title">Comments</h3>
<div id="disqus_thread" aria-live="polite"><noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript></div>
</section>
</div>
<aside id="sidebar" class="grid__item one-third lap-one-whole palm-one-whole">
<div class="grid">
<section class="aside-module grid__item one-whole lap-one-half">
<h1 class="title delta">About Home Assistant</h1>
<ul class="divided">
<li>
Home Assistant is an open-source home automation platform running on Python 3. Track and control all devices at home and automate control.
</li>
<li><a href='/getting-started/'>Get started with Home Assistant</a></li>
<li><a href='/demo/'>Try the online demo</a></li>
<li><a class="twitter-follow-button" href="https://twitter.com/Home_Assistant">Follow Home Assistant on Twitter</a></li>
</ul>
</section>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.async=true;js.src='//platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
<section class="sharing aside-module grid__item one-whole lap-one-half">
<h1 class="title delta">Share this post</h1>
<a href="//twitter.com/share"
class="twitter-share-button"
data-via="home_assistant"
data-related="home_assistant"
data-url="https://home-assistant.io/blog/2016/02/09/smarter-smart-things-with-mqtt-and-home-assistant/"
data-counturl="https://home-assistant.io/blog/2016/02/09/smarter-smart-things-with-mqtt-and-home-assistant/" >Tweet</a>
<div class="fb-share-button" style='top: -6px;'
data-href="https://home-assistant.io/blog/2016/02/09/smarter-smart-things-with-mqtt-and-home-assistant/"
data-layout="button_count">
</div>
<div class="g-plusone" data-size="standard"></div>
</section>
<script src="https://apis.google.com/js/platform.js" async defer></script>
<script>
window.fbAsyncInit = function() {
FB.init({appId: '338291289691179', xfbml: true, version: 'v2.2'});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<section id="recent-posts" class="aside-module grid__item one-whole lap-one-half">
<h1 class="title delta">Recent Posts</h1>
<ul class="divided">
<li class="post">
<a href="/blog/2016/03/12/z-wave-pep257-templated-service-calls/">0.15: Unforked Open Z-Wave, templated service calls, extended scene support and PEP257 compliance.</a>
</li>
<li class="post">
<a href="/blog/2016/02/27/steam-d-link-smart-plugs-and-neurio-energy-sensors/">0.14: Steam, D-Link smart plugs and Neurio Energy Sensors</a>
</li>
<li class="post">
<a href="/blog/2016/02/20/community-highlights/">Community Highlights</a>
</li>
<li class="post">
<a href="/blog/2016/02/18/multi-room-audio-with-snapcast/">Multi-room audio with Snapcast, Mopidy, and Home Assistant</a>
</li>
<li class="post">
<a href="/blog/2016/02/13/speedtest-bloomsky-splunk-and-garage-doors/">0.13: Speedtest.net, Bloomsky, Splunk and Garage Doors</a>
</li>
</ul>
</section>
</div>
</aside>
</div>
</div>
<footer>
<div class="grid-wrapper">
<div class="grid">
<div class="grid__item">
<div class="copyright">
<a rel="me" href='https://twitter.com/home_assistant'><i class="icon-twitter"></i></a>
<a rel="me" href='https://github.com/balloob/home-assistant'><i class="icon-github"></i></a>
<div class="credit">
Website powered by <a href='http://jekyllrb.com/'>Jekyll</a> and the <a href='https://github.com/coogie/oscailte'>Oscalite theme</a>.<br />
Hosted by <a href='https://pages.github.com/'>GitHub</a> and served by <a href='https://cloudflare.com'>CloudFlare</a>.
</div>
</div>
</div>
</div>
</div>
</footer>
<!--[if lt IE 7]>
<p class="chromeframe">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a> to improve your experience.</p>
<![endif]-->
<script>
var _gaq=[['_setAccount','UA-57927901-1'],['_trackPageview']];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
</script>
<script>
var disqus_shortname = 'home-assistant';
// var disqus_developer = 1;
var disqus_identifier = 'https://home-assistant.io/blog/2016/02/09/smarter-smart-things-with-mqtt-and-home-assistant/';
var disqus_url = 'https://home-assistant.io/blog/2016/02/09/smarter-smart-things-with-mqtt-and-home-assistant/';
var disqus_script = 'embed.js';
(function () {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/' + disqus_script;
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
}());
</script>
</body>
</html>