Page 7 sur 14

Re: RE: Re: Script alarme Somfy Protexiom 600

Publié : 17 nov. 2016, 09:56
par S1eepy
thom@s a écrit :Personnellement je n'utilise pas (ou très peu) les zones.
Pareil.

Re: Script alarme Somfy Protexiom 600

Publié : 17 nov. 2016, 15:28
par n1c0l45
perso, je n'utilise pas du tous les zones, c'est tout ou rien ;)

Re: Script alarme Somfy Protexiom 600

Publié : 17 nov. 2016, 16:49
par n1c0l45
Seb13, peux tu fournir ta nouvelle version du script stp?
Merci pour ton taff!!!

Re: Script alarme Somfy Protexiom 600

Publié : 17 nov. 2016, 17:15
par n1c0l45
Je pense avoir compiler ton taff, c'est bon? ou ai je fais des erreurs?

Code : Tout sélectionner

#----------------------------------------------------------------------------------------------------------------------------------
# Date : XX/11/2016
# Version : 1.X?
# Description : Script Domoticz pour récupérer les états des alarmes SOMFY PROTEXIUM 600 et Alarme ON/OFF
# Auteur : Seb13
#
# il faut créer une interface interrupteur dans Domoticz et dans la configuration il faut mettre pour Action ON ou OFF
# script:///home/pi/domoticz/scripts/xxxxx/xxxxxxx.sh --AlarmeON
# script:///home/pi/domoticz/scripts/xxxx/xxxxxx.sh --AlarmeOFF
#
#  crontab -e
#  */10 * * * * sudo /home/pi/domoticz/scripts/shell/EtatSomfy.sh -v
#----------------------------------------------------------------------------------------------------------------------------------

#----------------------------------------------------------------------------------------------------------------------------------
# ZONE DE MODIFICATION
#----------------------------------------------------------------------------------------------------------------------------------
declare -A CarteAuthentification
#Mettre IDX des boutons virtuels de domoticz
AlarmeSomfyPilesIDX=xxx
AlarmeSomfyBoitierIDX=xxx
AlarmeSomfyRadioIDX=xxx
AlarmeSomfyEtatIDX=xxx
AlarmeSomfyPorteIDX=xxx
Debug=False


# Carte d'authentification perso
CarteAuthentification=( ["A1"]="xxxx" ["B1"]="xxxx" ["C1"]="xxxx" ["D1"]="xxxx" ["E1"]="xxxx" ["F1"]="xxxx" ["A2"]="xxxx" ["B2"]="xxxx" ["C2"]="xxxx" ["D2"]="xxxx" ["E2"]="xxxx" ["F2"]="xxxx" ["A3"]="xxxx" ["B3"]="xxxx" ["C3"]="xxxx" ["D3"]="xxxx" ["E3"]="xxxx" ["F3"]="xxxx" ["A4"]="xxxx" ["B4"]="xxxx" ["C4"]="xxxx" ["D4"]="xxxx" ["E4"]="xxxx" ["F4"]="xxxx" ["A5"]="xxxx" ["B5"]="xxxx" ["C5"]="xxxx" ["D5"]="xxxx" ["E5"]="xxxx" ["F5"]="xxxx" )

# Adresse IP du serveur Somfy
SrvSomfyIp="http://192.168.0.XXX/"
SrvDomoticzIp="192.168.0.XXX:XXXX"

# Code Utilisateur1
CodeUtilisateur1=XXXX

#---------------------------------------------------------------------------------------------------------------------------------

# Menu Aide
Aide() {
echo -e "\tScript Domoticz Somfy Protexion 600"
echo -e "\t--help or -h\t\tMenu Aide"
echo -e "\t--view or -v\t\tVerification des etats"
echo -e "\t--AlarmeON \t\tMise en route de l'alarme sur Zone A B C"
echo -e "\t--AlarmeOFF \t\tArret de l'alarme sur Zone A B C"
}


# Menu des options du script
while [[ $1 == -* ]]; do
case "$1" in
--help|-h) Aide; exit 0;;
--view|-v) VerifEtat="1"; break;;
--AlarmeON) AlarmeON="1"; break;;
--AlarmeOFF) AlarmeOFF="1"; break;;
--*|-*) shift; break;;
esac
done

# Exection si option -v activee
if [ "$VerifEtat" = "1" ]; then

        # Declaration des URLs du site Somfy Mobile
        UrlMLogin=$SrvSomfyIp"m_login.htm"
        UrlMuEtat=$SrvSomfyIp"mu_etat.htm"
        UrlMLogout=$SrvSomfyIp"m_logout.htm"
        UrlMuPilotage=$SrvSomfyIp"mu_pilotage.htm"

        # Affichage des URLs
        if [ "$Debug" = "True" ]; then
                echo ""
                echo " ********************************* "
                echo " Liste des URLs"
                echo " ********************************* "
                echo " UrlMLogin = "$UrlMLogin
                echo " UrlMuEtat = "$UrlMuEtat
                echo " UrlMLogout = "$UrlMLogout
                echo " UrlMuPilotage = "$UrlMuPilotage
                echo ""
        fi


        # Recuperation du code d'acces apres lecture sur la page MLogin
        if [ "$Debug" = "True" ]; then
                echo ""
                CodeAcces="$(curl $SrvSomfyIp $UrlMLogin | grep -Eoi 'authentification <b>.*</b>')"
                CodeAcces="$(echo "${CodeAcces:20:2}")"
                echo "Code Acces = "$CodeAcces
                echo ""
        else
                        CodeAcces="$(curl -s $SrvSomfyIp $UrlMLogin | grep -Eoi 'authentification <b>.*</b>')"
                        CodeAcces="$(echo "${CodeAcces:20:2}")"
        fi


        # Recuperation du code d'authentification avec le code d'acces
        CodeAuthentification="${CarteAuthentification["$CodeAcces"]}"

        if [ "$Debug" = "True" ]; then
                        echo ""
                echo "Code Authentification = "$CodeAuthentification
                echo ""
        fi

        # Envoi du code utilisateur1 et du code d'authentification dans l'url MLogin pour connexion
        if [ "$Debug" = "True" ]; then
                echo ""
                curl -L --cookie cjar --cookie-jar cjar --data "password="$CodeUtilisateur1"&key="$CodeAuthentification"&action=Connexion" $UrlMLogin | iconv -f iso8859-1 -t utf-8
                echo ""
        else
                curl -s -L --cookie cjar --cookie-jar cjar --data "password="$CodeUtilisateur1"&key="$CodeAuthentification"&action=Connexion" $UrlMLogin | iconv -f iso8859-1 -t utf-8 > /dev/null
        fi


        # Lecture de la page MuEtat pour recuperer les etats de l alarme
        if [ "$Debug" = "True" ]; then
                        echo ""
                curl -L --cookie cjar --cookie-jar cjar $UrlMuEtat | iconv -f iso8859-1 -t utf-8
                curl -L --cookie cjar --cookie-jar cjar $UrlMuEtat | iconv -f iso8859-1 -t utf-8 | grep -Eoi 'Porte.*fermée'
                curl -L --cookie cjar --cookie-jar cjar $UrlMuEtat | iconv -f iso8859-1 -t utf-8 | grep -Eoi 'Porte.*ouverte'
                curl -L --cookie cjar --cookie-jar cjar $UrlMuEtat | iconv -f iso8859-1 -t utf-8 | grep -Eoi 'Pile.*OK'
                curl -L --cookie cjar --cookie-jar cjar $UrlMuEtat | iconv -f iso8859-1 -t utf-8 | grep -Eoi 'Pile.*</td>'
                echo ""
        fi

        # Recuperation des etats dans les variables
        EtatPorte="$(curl -s -L --cookie cjar --cookie-jar cjar $UrlMuEtat | iconv -f iso8859-1 -t utf-8 | grep -Eoi 'Porte.*</td>')"
        EtatPorte="$(echo "${EtatPorte:0:24}" | sed s/\<//g)"
        EtatPiles="$(curl -s -L --cookie cjar --cookie-jar cjar $UrlMuEtat | iconv -f iso8859-1 -t utf-8 | grep -Eoi 'Pile.*</td>')"
        EtatPiles="$(echo "${EtatPiles:0:8}")"
        EtatRadio="$(curl -s -L --cookie cjar --cookie-jar cjar $UrlMuEtat | iconv -f iso8859-1 -t utf-8 | grep -Eoi 'Communication.*</td>')"
        EtatRadio="$(echo "${EtatRadio:0:22}")"
        EtatAlarme="$(curl -s -L --cookie cjar --cookie-jar cjar $UrlMuEtat | iconv -f iso8859-1 -t utf-8 | grep -Eoi 'Pas.*</td>')"
        EtatAlarme="$(echo "${EtatAlarme:0:12}")"
        EtatBoitier="$(curl -s -L --cookie cjar --cookie-jar cjar $UrlMuEtat | iconv -f iso8859-1 -t utf-8 | grep -Eoi 'Boîtier.*</td>')"
        EtatBoitier="$(echo "${EtatBoitier:0:10}")"

        # Affichage des etats
        echo "Etat Porte = "$EtatPorte
        echo "Etat Piles = "$EtatPiles
        echo "Etat Communication Radio = "$EtatRadio
        echo "Etat Alarme = "$EtatAlarme
        echo "Etat Boitier = "$EtatBoitier

		# Envoi des etats a Domoticz
        # Etat des piles
        if [ "$Debug" = "True" ]; then
                if [ "$EtatPiles" = "Piles OK" ]; then
                        curl "http://$SrvDomoticzIp/json.htm?type=command&param=switchlight&idx=$AlarmeSomfyPilesIDX&switchcmd=On"
                else
                        curl "http://$SrvDomoticzIp/json.htm?type=command&param=switchlight&idx=$AlarmeSomfyPilesIDX&switchcmd=Off"
                fi
        else
                if [ "$EtatPiles" = "Piles OK" ]; then
                        curl -s "http://$SrvDomoticzIp/json.htm?type=command&param=switchlight&idx=$AlarmeSomfyPilesIDX&switchcmd=On" > /dev/null
                else
                        curl -s "http://$SrvDomoticzIp/json.htm?type=command&param=switchlight&idx=$AlarmeSomfyPilesIDX&switchcmd=Off" > /dev/null
                fi
        fi

        # Etat Boitier
        if [ "$Debug" = "True" ]; then
                if [ "$EtatBoitier" = "Boîtier OK" ]; then
                        curl "http://$SrvDomoticzIp/json.htm?type=command&param=switchlight&idx=$AlarmeSomfyBoitierIDX&switchcmd=On"
                else
                        curl "http://$SrvDomoticzIp/json.htm?type=command&param=switchlight&idx=$AlarmeSomfyBoitierIDX&switchcmd=Off"
                fi
        else
                if [ "$EtatBoitier" = "Boîtier OK" ]; then
                        curl -s "http://$SrvDomoticzIp/json.htm?type=command&param=switchlight&idx=$AlarmeSomfyBoitierIDX&switchcmd=On" > /dev/null
                else
                        curl -s "http://$SrvDomoticzIp/json.htm?type=command&param=switchlight&idx=$AlarmeSomfyBoitierIDX&switchcmd=Off" > /dev/null
                fi
        fi

        # Etat Communication Radio
        if [ "$Debug" = "True" ]; then
                if [ "$EtatRadio" = "Communication radio OK" ]; then
                        curl "http://$SrvDomoticzIp/json.htm?type=command&param=switchlight&idx=$AlarmeSomfyRadioIDX&switchcmd=On"
                else
                        curl "http://$SrvDomoticzIp/json.htm?type=command&param=switchlight&idx=$AlarmeSomfyRadioIDX&switchcmd=Off"
                fi
        else
                if [ "$EtatRadio" = "Communication radio OK" ]; then
                        curl -s "http://$SrvDomoticzIp/json.htm?type=command&param=switchlight&idx=$AlarmeSomfyRadioIDX&switchcmd=On" > /dev/null
                else
                        curl -s "http://$SrvDomoticzIp/json.htm?type=command&param=switchlight&idx=$AlarmeSomfyRadioIDX&switchcmd=Off" > /dev/null
                fi
        fi

        # Etat Alarme Somfy
        if [ "$Debug" = "True" ]; then
                if [ "$EtatAlarme" = "Pas d'alarme" ]; then
                        curl "http://$SrvDomoticzIp/json.htm?type=command&param=switchlight&idx=$AlarmeSomfyEtatIDX&switchcmd=Off"
                else
                        curl "http://$SrvDomoticzIp/json.htm?type=command&param=switchlight&idx=$AlarmeSomfyEtatIDX&switchcmd=On"
                fi
        else
                if [ "$EtatAlarme" = "Pas d'alarme" ]; then
                        curl -s "http://$SrvDomoticzIp/json.htm?type=command&param=switchlight&idx=$AlarmeSomfyEtatIDX&switchcmd=Off" > /dev/null
                else
                        curl -s "http://$SrvDomoticzIp/json.htm?type=command&param=switchlight&idx=$AlarmeSomfyEtatIDX&switchcmd=On" > /dev/null
                fi
        fi

        # Etat Porte
        if [ "$Debug" = "True" ]; then
                if [ "$EtatPorte" = "Porte ou fenêtre fermée" ]; then
                        curl "http://$SrvDomoticzIp/json.htm?type=command&param=switchlight&idx=$AlarmeSomfyPorteIDX&switchcmd=Off"
                else
                        curl "http://$SrvDomoticzIp/json.htm?type=command&param=switchlight&idx=$AlarmeSomfyPorteIDX&switchcmd=On"
                fi
        else
                if [ "$EtatPorte" = "Porte ou fenêtre fermée" ]; then
                        curl -s "http://$SrvDomoticzIp/json.htm?type=command&param=switchlight&idx=$AlarmeSomfyPorteIDX&switchcmd=Off" > /dev/null
                else
                        curl -s "http://$SrvDomoticzIp/json.htm?type=command&param=switchlight&idx=$AlarmeSomfyPorteIDX&switchcmd=On" > /dev/null
                fi
        fi

	
        # Logout du site Somfy
        if [ "$Debug" = "True" ]; then
                        echo ""
                curl -L --cookie cjar --cookie-jar cjar $UrlMLogout | iconv -f iso8859-1 -t utf-8
                echo ""
        else
                echo ""
                curl -s -L --cookie cjar --cookie-jar cjar $UrlMLogout | iconv -f iso8859-1 -t utf-8 > /dev/null
                echo ""
        fi

fi

if [ "$AlarmeON" = "1" ]; then
        echo "Alarme en fonction"
		curl -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&zone=Marche%20A%20B%20C" $UrlMuPilotage | iconv -f iso8859-1 -t utf-8
fi
if [ "$AlarmeOFF" = "1" ]; then
        echo "Alarme en arrêt"
		curl -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&zone=Arr%EAt%20A%20B%20C" $UrlMuPilotage | iconv -f iso8859-1 -t utf-8
fi

Re: Script alarme Somfy Protexiom 600

Publié : 17 nov. 2016, 21:49
par n1c0l45
j'ai ce message d'erreur mais je trouve pas l'erreur! mon tableau est bon, je l'ai verifié 4 fois...

Code : Tout sélectionner

pi@Domoticz:~/scripts$ ./EtatSomfy.sh -v
./EtatSomfy.sh: ligne 98: CarteAuthentification: mauvais indice de tableau
Etat Porte =
Etat Piles =
Etat Communication Radio =
Etat Alarme =
Etat Boitier =

Re: Script alarme Somfy Protexiom 600

Publié : 17 nov. 2016, 22:26
par jcjames_13009
Salut n1c0l45

J'ai vu que tu avais une PROTEXIOM 5000 comme moi et les URL à envoyer à l'alarme sont différents de ceux de la PROTEXIOM 600

Il te faut remplacer l'URL de login par "fr/login.htm"
Même chose pour le logout, il faut utiliser "logout.htm"
l'URL pour le pilotage serait "u_pilotage.htm" (Pas encore testé)
Je n'ai pas encore trouvé l'URL à utiliser pour l'état système 'mu_etat.htm' ne semble pas fonctionner

Code : Tout sélectionner

		# Alarme SOMFY PROTEXION 5000 GSM
		UrlMLogin=$SrvSomfyIp"fr/login.htm"
		UrlMuEtat=$SrvSomfyIp"??????.htm"
		UrlMLogout=$SrvSomfyIp"logout.htm"
		UrlMuPilotage=$SrvSomfyIp"fr/u_pilotage.htm"
Pour te connecter il faut remplacer "action" par "btn_login" dans la commande de connexion. Il faut utiliser ça :

Code : Tout sélectionner

curl -L --cookie cjar --cookie-jar cjar --data "password="$CodeUtilisateur1"&key="$CodeAuthentification"&btn_login=Connexion" $UrlMLogin | iconv -f iso8859-1 -t utf-8
Dernier point, je ne suis pas sur que tu puisses mettre en marche l'alarme et l'arrêter sans te connecter à l'alarme avant (envoie code utilisateur et d'authentification) comme pour récupérer les états du système.

Je cherche pour le reste...

@+

JC

Re: Script alarme Somfy Protexiom 600

Publié : 19 nov. 2016, 09:59
par n1c0l45
Salut et merci

je vais regarder cela!
Comment trouvez vous les commandes? J'imagine que vous utilisez une extension de votre navigateur pour voir les requetes envoyées?
Merci

Re: Script alarme Somfy Protexiom 600

Publié : 19 nov. 2016, 10:06
par Seb13
Hello à tous,

Désolé, je n''ai pas reçu de notification sur ma messagerie... j'ai regardé sur le site ce matin... je ne sais pas pourquoi :shock:

Je vais essayer de modifier un peu le script ce matin et je balance après.

Pour répondre à la question, comment on fait pour trouver les URLs et bien on le fait à la main dans notre navigateur.
Pour savoir ce qu'il faut envoyer comme valeur, je fais un curl de la page, je vois le code HTML et ensuite via un grep + sed je recup les valeurs.

Oui, il faut être connecter pour avoir l'état, c'est comme en vrai ;)

Re: Script alarme Somfy Protexiom 600

Publié : 19 nov. 2016, 10:10
par Seb13
J'ai vu que Etat Alarme dans mon script remonte si on a eu une alerte ou pas... mais cela ne donne pas l'état de l'alarme si Active ou non :x

Donc, j'ai modifié pour avoir le retour des Zones ABC.

Re: Script alarme Somfy Protexiom 600

Publié : 19 nov. 2016, 10:12
par Seb13
Un autre point, dans le début de mon script il y a une variable Debug.
Si elle est à False, vous allez voir juste les états mais si vous passez à True, cela active le debug du script et donc, vous voyez tout à l'écran... très pratique quand on cherche un bug ou à comprendre ce qu'il se passe.

Surtout, cela me permet de modifier une variable et pas mettre des # partout dans le script quand c'est terminé.