<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
     xmlns:atom="http://www.w3.org/2005/Atom"
     xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:wfw="http://wellformedweb.org/CommentAPI/"
     >
  <channel>
    <title>Temporal Anomaly</title>
    <link>http://www.temporalanomaly.com/blog</link>
    <description>Automating our house and other random stuff</description>
    <pubDate>Sun, 08 Jan 2012 15:58:29 GMT</pubDate>
    <generator>Blogofile</generator>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Home Automation Setup: May 2011</title>
      <link>http://www.temporalanomaly.com/blog/2011/05/08/home-automation-setup:-may-2011</link>
      <pubDate>Sun, 08 May 2011 20:20:07 BST</pubDate>
      <category><![CDATA[home automation]]></category>
      <category><![CDATA[backend]]></category>
      <category><![CDATA[xpl]]></category>
      <guid isPermaLink="true">http://www.temporalanomaly.com/blog/2011/05/08/home-automation-setup:-may-2011</guid>
      <description>Home Automation Setup: May 2011</description>
      <content:encoded><![CDATA[<p>I was planning to answer a question in a comment on previous post and
wanted to talk about the number of <a href="http://xplproject.org.uk/wiki/index.php?title=XPL_Specification_Document">xPL</a> clients that I have
running.  Rather than just quoting the number, I thought I'd make a
post to put my response in context.</p>
<p>Most of my xPL components support the <a href="http://xplproject.org.uk/wiki/index.php?title=Schema_-_HBEAT"><code>hbeat</code></a> schema.  So I
can identify them by sending a <code>hbeat.request</code> message.  My perl
<code>xpl-sender</code> command can do this:</p>
<pre><code>bash$ xpl-sender --schema hbeat.request --wait 10
</code></pre>
<p>By default, the sender just sends the specified message and exits.
But, with the <code>--wait</code> parameter, it prepares to receive replies,
sends the message and waits the specified number of seconds for any
replies.  The output from the above command is a summary of each
received <code>hbeat.app</code> reply:</p>
<pre><code>xpl-stat/hbeat.app: bnz-apcups.apc -&gt; * 5/53556/192.168.32.1
xpl-stat/hbeat.app: bnz-blue.slave -&gt; * 5/51540/192.168.32.1
xpl-stat/hbeat.app: bnz-ccost.slave -&gt; * 5/58435/192.168.32.1
xpl-stat/hbeat.app: bnz-dmx.slave -&gt; * 5/44072/192.168.32.1
xpl-stat/hbeat.app: bnz-gpower.slave -&gt; * 5/59772/192.168.32.1
xpl-stat/hbeat.app: bnz-heyu.slave -&gt; * 5/56009/192.168.32.1
xpl-stat/hbeat.app: bnz-lcdproc.slave -&gt; * 5/41722/192.168.32.1
xpl-stat/hbeat.app: bnz-linux.slave -&gt; * 5/46917/192.168.32.1
xpl-stat/hbeat.app: bnz-lirc.slave -&gt; * 5/33992/192.168.32.1
xpl-stat/hbeat.app: bnz-mpd.slave -&gt; * 5/32798/192.168.32.1
xpl-stat/hbeat.app: bnz-ownet.slave -&gt; * 5/46631/192.168.32.1
xpl-stat/hbeat.app: bnz-rfxcomrx.slave -&gt; * 5/40448/192.168.32.1
xpl-stat/hbeat.app: bnz-rfxcomtx.slave -&gt; * 5/48635/192.168.32.1
xpl-stat/hbeat.app: bnz-sendsms.slave -&gt; * 5/47592/192.168.32.1
xpl-stat/hbeat.app: bnz-smart.slave -&gt; * 5/43472/192.168.32.1
xpl-stat/hbeat.app: bnz-udin.slave1 -&gt; * 5/50553/192.168.32.1
xpl-stat/hbeat.app: bnz-udin.slave2 -&gt; * 5/52187/192.168.32.1
xpl-stat/hbeat.app: bnz-wol.slave -&gt; * 5/33981/192.168.32.1
xpl-stat/hbeat.app: bnz-zenah.slave -&gt; * 5/39324/192.168.32.1
xpl-stat/hbeat.app: bnz-mythtv.vz -&gt; * 5/34473/192.168.32.6
xpl-stat/hbeat.app: bnz-smart.vz -&gt; * 5/34298/192.168.32.6
xpl-stat/hbeat.app: bnz-xosd.vz -&gt; * 5/34487/192.168.32.6
xpl-stat/hbeat.app: bnz-xvkbd.vz -&gt; * 5/49051/192.168.32.6
</code></pre>
<p>Each summary is of the form:</p>
<pre><code>message_type/schema: source-identifier -&gt; target interval/port/ip
</code></pre>
<p>and each source-identifier is of the form:</p>
<pre><code>vendorid-deviceid.instanceid
</code></pre>
<p>My vendor id (developer id) is <code>bnz</code>, the device id is typically the
type of the device being managed, and the instance id is typically the
hostname of the machine running the client.</p>
<p>There are two machines in the list <code>vz</code> (which is my main <a href="http://www.mythtv.org/">mythtv</a>
box) and <a href="http://en.wikipedia.org/wiki/Scorpio_(Blake&apos;s_7)"><code>slave</code></a> (which is the main home automation server).
(The observant may notice that there is also <code>apc</code> but that is
actually running on <code>slave</code> monitoring an <a href="http://www.amazon.co.uk/gp/product/B002EB1FNO?tag=temporalanoma-21">APC UPS</a> via USB but the
instance id is changed as a convinience in order to distinguish
between <code>slave</code> and the UPS as they both report power/battery
information.)  The clients on the <a href="http://www.mythtv.org/">mythtv</a> box are:</p>
<ul>
<li>
<p><code>xpl-mythtv</code> which reports the percentage utilisation of the video
  inputs/tuners,</p>
</li>
<li>
<p><code>xpl-smart</code> which reports disk temperatures so I can turn on fans to
  extract warm air from the server room,</p>
</li>
<li>
<p><code>xpl-xosd</code> which responds to <a href="http://xplproject.org.uk/wiki/index.php?title=Schema_-_OSD.BASIC"><code>osd.basic</code> schema</a> messages
  showing on-screen display text using <a href="http://libxosd.sf.net">xosd</a>, and</p>
</li>
<li>
<p><code>xpl-xvkbd</code> which sends fake key presses to the active window
  (probably a security risk even though the keys always go to
  mythfrontend).</p>
</li>
</ul>
<p>The clients on <code>slave</code> are:</p>
<ul>
<li>
<p><code>xpl-apcups</code> which reports status of my APC UPS and sends events if
  when the UPS switches between mains and battery and vice versa,</p>
</li>
<li>
<p><code>xpl-blue</code> which monitors for the presence of various bluetooth
  devices so that my house "knows" when different people are home,</p>
</li>
<li>
<p><code>xpl-ccost</code> which monitors my mains power usage (or at least it did
  until it got confusing when I started exporting power) and the solar
  power generated by the PV panels on my roof,</p>
</li>
<li>
<p><code>xpl-dmx</code> which sends commands to a
  <a href="http://www.amazon.co.uk/gp/product/9792347860?tag=temporalanoma-21">Milford Instruments DMX Transmitter</a> to control a
  <a href="http://www.pulsarlight.com/Products/LEDLighting/ChromaZone/tabid/57/Default.aspx">Pulsar ChromaZone 12 Controller</a> which in turn drives a
  number of <a href="http://www.pulsarlight.com/Products/LEDLighting/tabid/56/Default.aspx">ChromaRange</a> lamps,</p>
</li>
<li>
<p><code>xpl-gpower</code> which reports my power usage information into the
  <a href="http://code.google.com/apis/powermeter/">Google PowerMeter API</a>,</p>
</li>
<li>
<p><code>xpl-heyu</code> which uses the <a href="http://www.heyu.org/">heyu</a> X10 software control my mains
  appliances and lights,</p>
</li>
<li>
<p><code>xpl-jabber</code> which enables interaction via <a href="http://xmpp.org/">XMPP</a> instant messages
  (such as Google Talk),</p>
</li>
<li>
<p><code>xpl-lcdproc</code> which responds to <a href="http://xplproject.org.uk/wiki/index.php?title=Schema_-_OSD.BASIC"><code>osd.basic</code> schema</a>
  messages showing text on a <a href="http://www.mini-box.com/picoLCD-4x20-sideshow">picoLCD-4x20-slideshow</a> device
  using the [lcdproc][] protocol,</p>
</li>
<li>
<p><code>xpl-linux</code> which reports Linux battery status and events, system
  temperature, etc.,</p>
</li>
<li>
<p><code>xpl-lirc</code> which reports <a href="http://www.lirc.org/">LIRC</a> IR remote button presses (so that
  I can switch the kettle on or send wake-on-lan packets using a basic
  TV remote control),</p>
</li>
<li>
<p><code>xpl-mpd</code> which controls a <a href="http://musicpd.sf.net/">Music Player Daemon</a> to play music
  in several zones around the house,</p>
</li>
<li>
<p><code>xpl-ownet</code> which is an interface to an <a href="http://www.owfs.org/">OWFS Daemon</a> that
  reads from temperature/humidity sensors and writes to relay
  controllers on the one-wire network in my house,</p>
</li>
<li>
<p><code>xpl-rfxcomrx</code> which is an interface to an <a href="http://rfxcom.com/receivers.htm">RFXCOM RF Receiver</a>
  that reports RF messages received from various sensors, switches,
  etc.,</p>
</li>
<li>
<p><code>xpl-rfxcomtx</code> which sends RF messages via an
  <a href="http://www.rfxcom.com/transmitters.htm">RFXCOM RF Transmitter</a> to control X10, HomeEasy, etc. devices,</p>
</li>
<li>
<p><code>xpl-sendsms</code> which sends SMS messages via any service supported by
   the <a href="http://search.cpan.org/search?query=sms::send">SMS::Send Perl API</a> (I use the service from
   <a href="http://www.csoft.co.uk/">Connection Software</a>),</p>
</li>
<li>
<p><code>xpl-smart</code> which reports disk temperatures,</p>
</li>
<li>
<p>two instances of <code>xpl-udin</code> to control two
  <a href="http://www.audon.co.uk/udin.html">UDIN USB Relay Controllers</a> to momentarily pulse the open/close
  inputs of several blind and curtains,</p>
</li>
<li>
<p><code>xpl-wol</code> which sends wake-on-lan packets (using the <code>etherwake</code>
  command) to wake up devices that are shutdown in order to save power
  (such as my <a href="http://www.mythtv.org/">mythtv</a> box), and</p>
</li>
<li>
<p><code>zenah</code> which is the brains of my house - triggering actions based
  on timers and incoming xPL messages.</p>
</li>
</ul>
<p>I am also running several other clients that run in <code>stealth mode</code> -
that is only sending messages and not listening for or responding to
<code>hbeat.request</code> messages.  These "inputs" include:</p>
<ul>
<li>
<p>a web frontend,</p>
</li>
<li>
<p>an experimental daemon supporting the <a href="http://melloware.com/products/lightswitch/">lightswitch</a> API so that I
  can use existing Android (or iPhone) applications to control my
  house, and</p>
</li>
<li>
<p>some security-related inputs (that I wont be writing much about).</p>
</li>
</ul>
<p>I'm currently trying to refactor the code to separate out the
device-related code from the xPL code and to reduce the coupling
between the web interface and the <code>zenah</code> "brains".  This will
probably involve a couple re-write of the <code>zenah</code> component and the
web interface.</p>]]></content:encoded>
    </item>
    <item>
      <title>Home Automation Protocols: xPL</title>
      <link>http://www.temporalanomaly.com/blog/2011/04/11/home-automation-protocols:-xpl</link>
      <pubDate>Mon, 11 Apr 2011 22:42:04 BST</pubDate>
      <category><![CDATA[home automation]]></category>
      <category><![CDATA[protocols]]></category>
      <category><![CDATA[xpl]]></category>
      <guid isPermaLink="true">http://www.temporalanomaly.com/blog/2011/04/11/home-automation-protocols:-xpl</guid>
      <description>Home Automation Protocols: xPL</description>
      <content:encoded><![CDATA[<p>I've been using the <a href="http://xplproject.org.uk/wiki/index.php?title=XPL_Specification_Document">xPL Protocol</a> since 2005, prior to that I
was using Jabber (or <a href="http://xmpp.org/">XMPP</a> as it is known now).  As I'm thinking
about changing protocol, I thought I'd write a bit about <a href="http://xplproject.org.uk/wiki/index.php?title=XPL_Specification_Document">xPL</a> and,
in later posts, something about the candidates to replace it.</p>
<p>The <a href="http://xplproject.org.uk/wiki/index.php?title=XPL_Specification_Document">xPL Protocol</a> has three types of messages: commands
(<code>xpl-cmnd</code>), triggers (<code>xpl-trig</code>) and status (<code>xpl-stat</code>).  They
have the same simple format consisting of the message type, <em>common</em>
"header" fields, the schema type and schema-specific "body" fields.
For example:</p>
<pre><code>xpl-cmnd
{
hop=1
source=vendor-device.host
target=*
}
x10.basic
{
command=on
device=c3
}
</code></pre>
<p>xPL doesn't use a server as its "message bus" is simply UDP port 3865
on the local network broadcast address.  In order to avoid multiple
devices having to listen on the same port on the same broadcast
address, each host runs a hub that distributes messages to all local
xPL clients.  I think this is a poor solution to this problem.  It
introduces an unnecessary single point of failure (albeit one with
very simple-to-test behaviour).  To avoid this single point of
failure, my <a href="https://github.com/beanz/xpl-perl/">xPL clients</a> also support a hubless mode where
they simply set the <code>SO_REUSEADDR</code> socket option on the listen socket
so that all clients can coexist on the same port on the same broadcast
address.  However, if you need to interoperate with clients from other
developers then you'll need to use the standard hub model.</p>
<p>Using UDP broadcasts to avoid any (unnecessary) single points of
failure is a good idea.  However, I have more than 20 xPL clients on
my network and all clients process all messages they receive,
discarding most of them and responding to relatively few.  This means
that all of the clients have to wake up and consume CPU resource for
every single message.  (This is one of the issues that is prompting me
to re-evaluate my choice of protocol.)</p>
<p>I thought about avoiding this problem by combining several clients in
to one more complex client but this seems like a bad idea as it will
inevitably lead to more complexity and thus more complicated failure
cases.  (My <a href="https://github.com/beanz/xpl-perl/">xPL clients</a> are structured in such a way that
this is very easy to do and some users with lower-powered servers do
this.)</p>
<p>For me, the <a href="http://xplproject.org.uk/wiki/index.php?title=XPL_Message_Schema">xPL Message Schema</a> are what make the protocol work so
well.  Essentially, the schema define the fields to expect in the body
of an xPL message.  This means I can write a client for a
<a href="http://www.audon.co.uk/udin.html">UDIN USB Relay Controller</a> or a <a href="http://www.phaedrusltd.com/pages/html/viom.html">Phaedrus VIOM</a> that supports the
<a href="http://xplproject.org.uk/wiki/index.php?title=Schema_-_CONTROL.BASIC">control.basic schema</a> and someone else can write a client that uses
the same schema to control relays and it will happily interoperate
with my clients.  (In fact, I realised this advantage when I migrated
from using a VIOM to several more compact UDIN controllers.  I only
needed to change the names of the relays for open/close on my
blinds/curtains after each set of wires were migrated to the new
hardware.)</p>
<p>The schema, as described in the protocol documentation, support a type
of inheritance.  A message schema that inherits from another must
include all of the mandatory fields of the other, in the same order,
so clients can support the basic function even if they don't
understand the additional sub-schema fields.  However, since
optional vendor-specific fields are also allowed without inheritance
(giving a simple duck typing approach), the inheritance mechanism
doesn't really give much benefit.</p>
<p>Take <code>hbeat</code> messages, there are two types, <code>basic</code>:</p>
<pre><code>xpl-stat
{
hop=1
source=vendor-device.host
target=*
}
hbeat.basic
{
interval=5
}
</code></pre>
<p>and, inherited from <code>basic</code>, <code>app</code>:</p>
<pre><code>xpl-stat
{
hop=1
source=vendor-device.host
target=*
}
hbeat.app
{
interval=5
port=43438
remote-ip=198.51.100.2
}
</code></pre>
<p>Why do the messages need the <code>.basic</code> or <code>.app</code>?  So that a client
knows to expect the port and remote-ip fields?  Why does a client need
to know to expect them?  A client can just parse the message and if
the fields are present - i.e. no <code>}</code> following the <code>interval=5</code> line -
then it can treat the message like an <code>.app</code> message and like a
<code>.basic</code> message if not.  It is simply redundant.</p>
<p>The only obviously valid use of the <code>.suffix</code> is <code>.confirm</code> suffix but
this would probably be better implemented as a fourth message type
such as <code>xpl-ack</code> or <code>xpl-conf</code>.</p>
<p>The wildcard <code>target=*</code> line is also redundant since a lack of
explicit <code>target=vendor-device.host</code> could just as easily be used to
distinguish the wildcard case.</p>
<p>These superfluous elements mean that the "Lite on the wire, by design"
subtitle on the <a href="http://xplproject.org.uk/wiki/index.php?title=XPL_Specification_Document">xPL Protocol</a> specification isn't really as
"lite" as it could be (and IMHO should be).</p>
<p>Another confusing aspect of the <a href="http://xplproject.org.uk/wiki/index.php?title=XPL_Specification_Document">xPL Protocol</a> is the notion of a
device.  In the protocol spec, for instance in the
<a href="http://xplproject.org.uk/wiki/index.php?title=XPL_Specification_Document#Device_Groups">Device Groups</a> section, it is clear that the <code>target</code> field is
addressing an individual device - a controller for a single
curtain/drape.  This is fine in theory, but in practice, individual
devices are general addressed using fields in the <em>body</em>.  For
instance, <code>control.basic</code>, <code>remote.basic</code>, <code>sensor.basic</code>,
<code>x10.basic</code>, and <code>x10.security</code> use <code>device</code>, <code>homeasy.basic</code> uses the
combination of <code>address</code> and <code>unit</code>, <code>zwave.basic</code> uses <code>node</code>, etc.
This is because xPL clients are typically controllers/gateways for
several devices.  For instance, I have a 1-wire sensor/relay network
with dozens of devices attached to it but one xPL client opens the
1-wire USB interface and manages all of these devices based on the
<code>device</code> field in <code>control.basic</code> and <code>sensor.basic</code> messages.</p>
<p>The protocol would be simpler to use if addressing of devices was more
consistent.  In fact, devices (rather than clients) should be
first-class citizens on the "network".  That is, they should be
discoverable (like clients are today with <code>hbeat</code> requests) and
probably should be aliasable (so that they can be given memorable
names).</p>
<p>I like the <a href="http://xplproject.org.uk/wiki/index.php?title=XPL_Specification_Document">xPL Protocol</a>; it has been my protocol of choice for
more than 5 years and most of these issues are not a big deal.  The
broadcast message bus is simple (if you ignore hubs) and reliable but
the inefficiency of waking all clients on every message is starting to
become an issue for me.  So, in the next few posts, I'll write about
some of the alternatives I am considering.</p>]]></content:encoded>
    </item>
  </channel>
</rss>

