Close

Update#4: XML Configuration and progress overview

A project log for Home Automation

with Raspberry PI, Arduino, ESP8266 and a bunch of Sensors

M@lteM@lte 05/29/2016 at 20:220 Comments

After the last hardware updates, it is now time to talk about the software again.
I the first update, I mentioned room handlers, which were individually programmed to fit each room. To make my system more flexible, I dropped this approach and switched to a more versatile solution.

The new implementation is based on an XML configuration file, in which I can specify actions that are performed based on events (like a detected motion or the press of a button, called "command" in the XML file) and conditions (e.g. brightness or state of the ceiling light). In each request, there can also be a "value" parameter, which can be checked, too.
I also added the option to define macros for larger actions, which are used by different other actions. The "save" tag directs the server to save the event as specified by the given parameters or without changes, if no parameters were given.

The current progress of my project is illustrated by the configuration file

<?xml version="1.0" encoding="UTF-8"?>
<hub>
  <commands>
    <!-- living room -->
    <command roomID="3" type="rgb">
      <action>
        <callHandler class="rgbHandler" />
      </action>
    </command>
    <!-- bedroom -->
    <command roomID="2" type="light">
      <action>
        <conditions>
          <value>1</value>
        </conditions>
        <get url="http://192.168.178.47/?c=A" />
        <save />
      </action>
      <action>
        <conditions>
          <value>0</value>
        </conditions>
        <get url="http://192.168.178.47/?c=a" />
        <save />
      </action>
    </command>
    <command roomID="2" type="curtains">
      <action>
        <conditions>
          <value>O</value>
        </conditions>
        <get url="http://192.168.178.50/?c=O" />
        <save />
      </action>
      <action>
        <conditions>
          <value>C</value>
        </conditions>
        <get url="http://192.168.178.50/?c=C" />
        <save />
      </action>
      <action>
        <conditions>
          <value />
        </conditions>
        <callMacro name="toggleCurtainsBedroom" />
      </action>
    </command>
    <command roomID="2" type="MotionDetected">
      <action>
        <conditions>
          <stateNotEquals roomID="0" type="currentRoom" value="2" />
          <state roomID="0" type="fallbackMode" value="0" />
          <stateLessInt roomID="2" type="brightness" value="500" />
        </conditions>
        <callCommand roomID="2" type="light" value="1" />
        <callCommand roomID="1" type="light" value="0" />
        <save type="currentRoom" roomID="0" value="2"/>
      </action>
      <action>
        <conditions>
          <stateNotEquals roomID="0" type="currentRoom" value="2" />
          <state roomID="0" type="fallbackMode" value="0" />
        </conditions>
        <callCommand roomID="1" type="light" value="0" />
        <save type="currentRoom" roomID="0" value="2"/>
      </action>
    </command>
    <!-- office -->
    <command roomID="1" type="MotionDetected">
      <action>
        <conditions>
          <stateNotEquals roomID="0" type="currentRoom" value="1" />
          <state roomID="0" type="fallbackMode" value="0" />
          <stateLessInt roomID="1" type="brightness" value="500" />
        </conditions>
        <callCommand roomID="1" type="light" value="1" />
        <callCommand roomID="2" type="light" value="0" />
        <save type="currentRoom" roomID="0" value="1"/>
      </action>
      <action>
        <conditions>
          <stateNotEquals roomID="0" type="currentRoom" value="1" />
          <state roomID="0" type="fallbackMode" value="0" />
        </conditions>
        <callCommand roomID="2" type="light" value="0" />
        <save type="currentRoom" roomID="0" value="1"/>
      </action>
    </command>
    <command roomID="1" type="light">
      <action>
        <conditions>
          <value>0</value>
        </conditions>
        <get url="http://192.168.178.32/OFF" />
        <save />
      </action>
      <action>
        <conditions>
          <value>1</value>
        </conditions>
        <get url="http://192.168.178.32/ON" />
        <save />
      </action>
    </command>
    <!-- corridor -->
    <command roomID="0" type="openDoor">
      <action>
        <get url="http://192.168.178.47/?c=O" />
        <save type="doorOpened" />
      </action>
    </command>
    <command roomID="0" type="switch">
      <action>
        <conditions>
          <value>bedroomA</value>
        </conditions>
        <callMacro name="toggleCurtainsBedroom" />
      </action>
    </command> 
    <!-- radio data -->
    <command roomID="0" type="lightA">
      <action>
        <save roomID="2" type="light" />
      </action>
    </command>
  </commands>
  <macros>
    <macro name="toggleCurtainsBedroom">
      <action>
        <conditions>
          <state roomID="2" type="curtains" value="C" />
        </conditions>
        <callCommand roomID="2" type="curtains" value="O" />
      </action>
      <action>
        <conditions>
          <state roomID="2" type="curtains" value="O" />
        </conditions>
        <callCommand roomID="2" type="curtains" value="C" />
      </action>
    </macro>
  </macros>
</hub>

Discussions