pidor/scripts/lightcommander

112 lines
4.4 KiB
Bash
Executable File

#!/bin/bash
if [ "$1" = "" ]
then
echo "usage: $0 {main|chill|status|labsocket|alarm|screen} {on|off}"
echo "usage: $0 projector {on|hdmi1|hdmi2|dvi|vga1|off|vol-|query}"
echo "usage: $0 receiver {on|off|hdmi|jack1|jack2|optical|tuner|cd|vol-|vol+}"
echo "usage: $0 bluray {down|up|left|right|ok|audio|subtitle|menu}"
# echo "usage: $0 {maindoor} {open}"
exit 1
fi
LockDir="/run/lock/$(basename "$0").run"
P() {
while ! mkdir "$LockDir" 2>/dev/null
do
LockDirStamp=$(stat -c %Y "$LockDir" 2>/dev/null)
if [ "$LockDirStamp" != "" ] && [ "$LockDirStamp" -lt $(date --date "300 seconds ago" +%s) ]
then
rmdir "$LockDir"
logger -t $(basename $0) "$$ deleting stale semaphore dir $LockDir"
fi
sleep 1
done
}
V() {
rmdir "$LockDir" 2>/dev/null
if [ $? -ne 0 ]
then
logger -t $(basename $0) "$$ semaphore dir $LockDir disappeared while running"
fi
}
function IRcmd() {
P
sudo /root/pidor/rcswitch-pi/send "$1" "$2" "$3" "$4"
V
}
# v---- group A=1, B=2, G=7
# v---- number
# /root/pidor/rcswitch-pi/send 2 7 3 1 <-- 0=off 1=on
function dolight() {
if [ "$2" = "on" ]
then
setvalue=1
mqtt_command=ON
else
setvalue=0
mqtt_command=OFF
fi
case "$1" in
all) dolight "main" $2
dolight "status" $2
dolight "labsocket" $2
dolight "3dprinter" $2
dolight "alarm" $2
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "$mqtt_command" "http://10.2.113.102:8080/rest/items/engineering_table_lamps"
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "$mqtt_command" "http://10.2.113.102:8080/rest/items/engineering_ceiling_lamps"
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "$mqtt_command" "http://10.2.113.102:8080/rest/items/engineering_status_lamp"
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "$mqtt_command" "http://10.2.113.102:8080/rest/items/chill_zone_lamps"
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "$mqtt_command" "http://10.2.113.102:8080/rest/items/entrance_ceiling_lamps"
;;
main) IRcmd 2 1A 1 "$setvalue"
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "$mqtt_command" "http://10.2.113.102:8080/rest/items/entrance_ceiling_lamps"
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "$mqtt_command" "http://10.2.113.102:8080/rest/items/chill_zone_lamps"
if [ "$setvalue" = "0" ] # switch off alarm light when switching off all lights
then
IRcmd2 15A 1 "$setvalue"
fi
;;
chill) IRcmd 2 1A 2 "$setvalue"
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "$mqtt_command" "http://10.2.113.102:8080/rest/items/chill_zone_lamps"
;;
status) IRcmd 2 2A 1 "$setvalue"
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "$mqtt_command" "http://10.2.113.102:8080/rest/items/engineering_status_lamp"
;;
labsocket) IRcmd 2 15A 6 "$setvalue"
;;
alarm) ( IRcmd 2 15A 1 "$setvalue"
sleep 1
IRcmd 2 15A 1 "$setvalue" ) &
;;
3dprinter) IRcmd 2 7 3 "$setvalue"
;;
screen) sudo /root/pidor/scripts/beamercontrol.sh screen "$2"
;;
projector) sudo /root/pidor/scripts/beamercontrol.sh beamer "$2"
;;
receiver) sudo /root/pidor/scripts/beamercontrol.sh receiver "$2"
;;
bluray) sudo /root/pidor/scripts/beamercontrol.sh bluray "$2"
;;
stealth) sudo /root/pidor/scripts/stealth.sh
;;
# maindoor) sudo /root/pidor/scripts/opendoor.sh 2>&1 | logger
# ;;
esac
# type (2=10bit)
# | house 1-16 (the dial thingie)
# | |group A-P (the dial thingie)
# | || unit (1-16) (the button, usually 1-4)
# | || | on/off
# | || | |
#/usr/local/bin/433send 2 1A 1 1 #on
#/usr/local/bin/433send 2 1A 1 0 #off
}
logger -t $(basename $0) "do $$ $1 $2"
dolight "$1" "$2"