#!/bin/bash
   DOMO_IP="localhost"             # Domoticz IP Address
   DOMO_PORT="81"                    # Domoticz Port
   Gauche_IDX=684 # cuisine
   Droit_IDX=701 # téle
   Milieu_IDX=699 # porte
   duree=$2

lockfile-create "/tmp/volet2.lockfile"

echo "Avant $1" >>/tmp/test
curl -s "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$Droit_IDX&switchcmd=$1" &
sleep $duree 
curl -s "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$Droit_IDX&switchcmd=$1" &
sleep 2
curl -s "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$Milieu_IDX&switchcmd=$1" &
sleep $duree 
curl -s "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$Milieu_IDX&switchcmd=$1" &
sleep 2 
curl -s "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$Gauche_IDX&switchcmd=$1" &
sleep $duree
curl -s "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$Gauche_IDX&switchcmd=$1" &
sleep 2 

if [ "$1" = "On" ]
then
	mosquitto_pub -t "jerome.delacotte@gmail.com/chambre/volet" -m "d" 
	sleep 1
	mosquitto_pub -t "jerome.delacotte@gmail.com/theo/volet" -m "d" 
	sleep 1
	mosquitto_pub -t "jerome.delacotte@gmail.com/manon/volet" -m "d" 
	sleep 8
	mosquitto_pub -t "jerome.delacotte@gmail.com/chambre/volet" -m "s" 
	sleep 1
	mosquitto_pub -t "jerome.delacotte@gmail.com/theo/volet" -m "s" 
	sleep 1
	mosquitto_pub -t "jerome.delacotte@gmail.com/manon/volet" -m "s" 
else
	mosquitto_pub -t "jerome.delacotte@gmail.com/chambre/volet" -m "u" 
	sleep 1
	mosquitto_pub -t "jerome.delacotte@gmail.com/theo/volet" -m "u" 
	sleep 1
	mosquitto_pub -t "jerome.delacotte@gmail.com/manon/volet" -m "u" 
fi		

# curl -s "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=822&switchcmd=$1&parsetrigger=false" &
# curl -s "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=823&switchcmd=$1&parsetrigger=false" &
# curl -s "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=824&switchcmd=$1&parsetrigger=false" &



echo "Apres" >>/tmp/test
lockfile-remove "/tmp/volet2.lockfile"
