Difference between revisions of "Install actions"

From xPL
Jump to: navigation, search
(Created page with " ::<html> <a title="By Dsmurat (+) [LGPL (http://www.gnu.org/licenses/lgpl.html)], via Wikimedia Commons" href="http://commons.wikimedia.org/wiki/File%3AUnder_construction_ico...")
 
Line 138: Line 138:
 
On Mac OS, the xPL bash actions device starts-up later than the hub.
 
On Mac OS, the xPL bash actions device starts-up later than the hub.
  
Edit <code>/Library/LaunchDaemons/xpl-central.plist</code>:
+
Edit <code>/Library/LaunchDaemons/xpl-actions.plist</code>:
 
  <?xml version="1.0" encoding="UTF-8"?>
 
  <?xml version="1.0" encoding="UTF-8"?>
 
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
Line 144: Line 144:
 
   <dict>
 
   <dict>
 
     <key>Label</key>
 
     <key>Label</key>
     <string>xPL central message parser</string>
+
     <string>xPL actions launcher</string>
 
     <key>OnDemand</key>
 
     <key>OnDemand</key>
 
     <false/>
 
     <false/>
 
     <key>UserName</key>
 
     <key>UserName</key>
     <string>control</string>
+
     <string>francois</string>
 
     <key>ProgramArguments</key>
 
     <key>ProgramArguments</key>
 
     <array>
 
     <array>
Line 156: Line 156:
 
       <string>-w</string>
 
       <string>-w</string>
 
       <string>25</string>
 
       <string>25</string>
       <string>-a</string>
+
       <string>-d</string>
       <string>/Users/control/Documents/Controls/centralActions.xml</string>
+
       <string>/Users/control/Documents/Controls/Actions</string>
 
     </array>
 
     </array>
 
   </dict>
 
   </dict>

Revision as of 16:22, 8 April 2014

Under construction icon-blue


The xPL home state device stores the current state of different devices such as lights, shutters, etc… This information can be retrieved by clients such as web 2.0 pages in order to display the proper state of the devices to be controlled.

The state update is best controlled with the help of the central xPL device.

Before all,make sure you have installed an xPL hub.

Home state information

The home state information is stored in an XML file. It is categorised in 4 hierarchy levels:

  • the room
  • the kind, such as lights, shutters, etc…
  • the object: an object of the kind given by an identifier, such as table for the lamp above the table
  • the value, such as on or off

The following example shows a possible content of /home/control/Documents/Controls/state.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<state>
  <lounge name="lights" center="off" entry="off" stand="off" table="off" />
  <lounge name="shutters" center="up" east="up" west="up" />
  <lounge name="audio" balance="0" power="on" mute="off" source="CD" surround="stereoSub" volume="50" />
  <lounge name="screen" aspect="43" input="RGB" power="on" />
  <study name="lights" ceiling="off" stand="off" />
  <study name="shutters" window="louvresDown" />
  <study name="audio" balance="0" source="CD" power="off" volume="30" />
</state>

The home state information is both updated and queried with the help of xPL messages.

Install xPL bash actions device

Download the xPL home state script.

Move the script to xPL scripts directory:

SCRIPTS_BASE_DIR=/home/control/Documents/Controls
mv xpl-actions.pl $SCRIPTS_BASE_DIR
chown control:users $SCRIPTS_BASE_DIR/*.pl
chmod 775 $SCRIPTS_BASE_DIR/*.pl

Create the /home/control/Documents/Controls/state.xml state file based on the preceeding example, but adapted to your needs. The file doesn't need to be complete: objects will be added by the xPL update or set messages.

Test xPL bash actions device

Test it on a BeagleBone:

su control
SCRIPTS_BASE_DIR=/home/control/Documents/Controls
$SCRIPTS_BASE_DIR/xpl-actions.pl -h
$SCRIPTS_BASE_DIR/xpl-actions.pl -v -n lounge

Open a 2nd terminal window (on any machine with xPL installed) and monitor the xPL protocol:

SCRIPTS_BASE_DIR=/home/control/Documents/Controls
$SCRIPTS_BASE_DIR/xpl-monitor.pl -vf

The monitor will help by showing the responses of the home state device.

Open another terminal and query a value:

su control
SCRIPTS_BASE_DIR=/home/control/Documents/Controls
cat $SCRIPTS_BASE_DIR/state.xml | grep 'study.*lights'
$SCRIPTS_BASE_DIR/xpl-send.pl -v -c state.basic room=study kind=lights object=ceiling command=ask

Modify a value:

$SCRIPTS_BASE_DIR/xpl-send.pl -v -c state.basic room=study kind=lights object=ceiling value=on command=update
cat $SCRIPTS_BASE_DIR/state.xml | grep 'study.*lights'
$SCRIPTS_BASE_DIR/xpl-send.pl -v -c state.basic room=study kind=lights object=ceiling command=ask

Modify a value and trigger an action:

$SCRIPTS_BASE_DIR/xpl-send.pl -v -c state.basic room=study kind=lights object=ceiling value=off command=set
cat $SCRIPTS_BASE_DIR/state.xml | grep 'study.*lights'
$SCRIPTS_BASE_DIR/xpl-send.pl -v -c state.basic room=study kind=lights object=ceiling command=ask

Additionally to updating the state file, this command will trigger an act message which can be used by the central xPL device to actually turn off the light.

Try to modify a value and don't trigger an action:

$SCRIPTS_BASE_DIR/xpl-send.pl -v -c state.basic room=study kind=lights object=ceiling value=off command=set
cat $SCRIPTS_BASE_DIR/state.xml | grep 'study.*lights'
$SCRIPTS_BASE_DIR/xpl-send.pl -v -c state.basic room=study kind=lights object=ceiling command=ask

As the value of the ceiling lamp was already off, this command will not trigger an act message. This feature will prevent objects to flicker or temporarily mute when an identical command is sent more than once.

Launch the xPL bash actions device at startup

The xPL bash actions is to be launched after the xPL hub.

Ubuntu

On Ubuntu, the xPL bash actions device starts-up once xpl-hub_started has been emitted.

Edit /etc/init/xpl-homeState.conf:

################################################################################
# xPL home state manager
#
description "xPL home state manager"
version     "1.0"
author      "Francois Corthay"

#-------------------------------------------------------------------------------
# Configuration variables
#
env SCRIPTS_DIR='/home/control/Documents/Controls'
env SCRIPT_NAME='xpl-actions.pl'
env PARAMETERS='-n home'

#-------------------------------------------------------------------------------
# Start and stop conditions
#
start on xpl-hub_started
stop on shutdown
respawn
setuid control
setgid users

#-------------------------------------------------------------------------------
# Start daemon
#
exec $SCRIPTS_DIR/$SCRIPT_NAME $PARAMETERS

Start the device and test it:

su root
service xpl-actions start
service xpl-actions status

SCRIPTS_BASE_DIR=/home/control/Documents/Controls
$SCRIPTS_BASE_DIR/xpl-send.pl -v -c state.basic room=study kind=lights object=ceiling command=ask

Mac OS

On Mac OS, the xPL bash actions device starts-up later than the hub.

Edit /Library/LaunchDaemons/xpl-actions.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>xPL actions launcher</string>
    <key>OnDemand</key>
    <false/>
    <key>UserName</key>
    <string>francois</string>
    <key>ProgramArguments</key>
    <array>
      <string>/Users/control/Documents/Controls/xpl-actions.pl</string>
      <string>-n</string>
      <string>lounge</string>
      <string>-w</string>
      <string>25</string>
      <string>-d</string>
      <string>/Users/control/Documents/Controls/Actions</string>
    </array>
  </dict>
</plist>

Start the device and test it:

su root
launchctl load /Library/LaunchDaemons/xpl-actions.plist

SCRIPTS_BASE_DIR=/Users/control/Documents/Controls
$SCRIPTS_BASE_DIR/xpl-send.pl -v -c state.basic room=study kind=lights object=ceiling command=ask