Difference between revisions of "Install actions"
(→Install xPL actions device) |
(→Home state information) |
||
Line 17: | Line 17: | ||
Before all, make sure you have installed an [[install xpl hub|xPL hub]]. | Before all, make sure you have installed an [[install xpl hub|xPL hub]]. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
= Install xPL actions device = | = Install xPL actions device = |
Revision as of 17:57, 8 April 2014
The xPL actions device allows to launch scripts or executables with parameters from any xPL device.
This allows to build complex home control sequences, even with condition checks.
In this point of view, the actions device allows more elaborate control than the central xPL device.
As an example, pushing an EIB button can result not only in opening the entrance door, but also in turning-on selected lights if the button has been pushed after sunset.
The actions device is often controlled by xPL messages originating from the central xPL device. Additionally to sending xPL messages to controlled devices such as lights and shutters, it can perform local actions on a computer, such as displaying an alert message, sending an e-mail or backing-up files.
Before all, make sure you have installed an xPL hub.
Contents
[hide]Install xPL actions device
Download the xPL actions 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/Actions
directory.
Create the /home/control/Documents/Controls/Actions/Play.bash
file:
#!/bin/bash #------------------------------------------------------------------------------- # Constants # DEFAULT_SOUND_FILE='/home/control/Documents/Controls/Sounds/pop.wav' PLAY_COMMAND='aplay' #------------------------------------------------------------------------------- # Command line arguments # sound_file= while [ "$1" != '' ] ; do case $1 in -f | --file ) shift ; sound_file=$1 ;; esac shift done #=============================================================================== # Play sound # if [ -e "$sound_file" ] ; then echo "Playing file: $sound_file" $PLAY_COMMAND $sound_file > /dev/null 2>&1 else sound_file=$DEFAULT_SOUND_FILE $PLAY_COMMAND $sound_file > /dev/null 2>&1 echo "File \"$sound_file\" not found" fi
Test it:
SCRIPTS_BASE_DIR=/home/control/Documents/Controls $SCRIPTS_BASE_DIR/Actions/play.bash -f /home/control/Documents/Controls/Sounds/ring.wav
Test xPL 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 actions device at startup
The xPL actions is to be launched after the xPL hub.
Ubuntu
On Ubuntu, the xPL 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 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