Version 0.9.1

Datei 'scripts/smart' Zurück zur Übersicht
#!/bin/ksh
#control the smart_home

#variabeln
mode=${1:?'$1 Must be a valid mode'}

#get base dir
BASEDIR=$(dirname "$0")
if [ -L $0 ] ; then
    BASEDIR=$(dirname $(readlink -f "$0"))
fi

#config
if [ -e "$BASEDIR/config.conf" ]; then
	. "$BASEDIR/config.conf"
else
	echo "No config found at: $BASEDIR/config.conf"
fi

function wLog {
	log="${logdir}/smart.log"
	date=$(date "+%Y-%m-%d_%H:%M:%S.%N")
	
	echo "$date $USER $1 $2 $3 $4 $5 $6 $7 $8 $9" >> "$log"
}

case "$mode" in 
 #turn off a device
 "turn_off")
	device=${2:?'$2 Must be a valid device id'}
	wLog "turn_off" "'$2'"
	for f in $device
	do
	  "$shdir/_get/turn_off.sh" "$f"
	done
 ;;
 
 #turn on a device and set it to a default value. If a value has been set before
 "turn_on")
	device=${2:?'$2 Must be a valid device id'}
	wLog "turn_on" "'$2'"
	for f in $device
	do
	  "$shdir/_get/turn_on.sh" "$f"
	done
 ;;
 
 #turn on a device and set it to a default value but only for a limited time
 "on_for")
	device=${2:?'$2 Must be a valid device id'}
	time=${3:?'$3 Must be a valid time'} #default is second
	wLog "on_for" "'$2'" "$3"
	for f in $device
	do
	  #"$shdir/_get/turn_on.sh" "$f"
	  echo "turning on $f for $time sec"
	  "$shdir/_get/turn_on.sh" "$f"
	done
	
	nohup bash -c "sleep $time; $shdir/_get/turn_off.sh '$device'" >/dev/null &2>/dev/null
	echo "turning off '$device'"
 ;;
 
 #set a device value
 "set_device")
	device=${2:?'$2 Must be a valid device id'}
	mode=${3:?'$3 Must be a valid mode'}
	value=${4:?'$4 Must be a valid value'}
	wLog "set_device" "$2" "$3" "$4"
	
	if [[ "$device" = "RXV779" ]]; then 
	  "$shdir/_get/set_rxv779.sh" "$3" "$4"
	else
	  "$shdir/_get/set_device.sh" "$device" "$3"
	fi
 ;;
 
 #set a scene. E.g. "at_home"
 "set_scene")
	scene=${2:?'$2 Must be a valid scene name'}
	wLog "set_scene" "$2"
	"$shdir/_get/set_scene.sh" "$scene"
 ;;
 
 #Control a app on z-wave
 "control_app")
	app=${2:?'$2 Must be a valid app id'}
	wLog "control_app" "$2"
	"$shdir/_get/turn_off.sh" "$app"
 ;;
 
 #Unknown command
 *)
	echo "Unknown command $2 $3 $4 $5 $6 $7 $8 $9 $10"
	wLog "unknown_command" $2 $3 $4 $5 $6 $7 $8 $9 $10
 ;;
esac