Reprenez le contrôle de votre domotique
https://easydomoticz.com/forum/
Code : Tout sélectionner
login=u&password=XXXX&key=XXXX&btn_login=ConnexionDésolé, impossible de passer sans iconv car il me permet d'afficher le code html de la page avec les "é" de la porte fermée par exemple.S1eepy a écrit :Salut seb, merci pour le partage. Ca a l'air très bien, cependant ne marche pas sur mon syno car la commande iconv n'est pas présente.
Oui il est possible de la rajouter en bidouillant (ipkg ou autres...) mais je pense que je vais rester sur PHP pour cette raison.
Balance tes questions, je vais essayer d'y répondre.n1c0l45 a écrit :je viens de voir avec httpfox que le POST data de connexion est:Seb13,par contre, je suis desole, je connais pas encore tous les outils que tu utilises, aurais tu un peu de temps a me consacrer pour m'expliquer?Code : Tout sélectionner
login=u&password=XXXX&key=XXXX&btn_login=Connexion
Merci
Code : Tout sélectionner
Connexion au site Somfy Mobile OK
Etat Porte = Porte ou fenêtre fermée
Etat Piles = Piles OK
Etat Communication Radio = Communication radio OK
Etat Alarme = Pas d'alarme
Etat Boitier = Boîtier OK
Etat Zone A = OFF
Etat Zone B = OFF
Etat Zone C = OFF
Etat Zone ABC = OFF
Deconnexion au site Somfy Mobile OK
Code : Tout sélectionner
./EtatSomfyV3.sh -vCode : Tout sélectionner
./EtatSomfyV3.sh -hCode : Tout sélectionner
./EtatSomfyV3.sh --AlarmeONCode : Tout sélectionner
./EtatSomfyV3.sh --AlarmeOFFCode : Tout sélectionner
crontab -eCode : Tout sélectionner
*/10 * * * * sudo /home/pi/domoticz/scripts/shell/EtatSomfyV3.sh -v
Code : Tout sélectionner
script:///home/pi/domoticz/scripts/shell/EtatSomfyV2.sh --AlarmeONCode : Tout sélectionner
script:///home/pi/domoticz/scripts/shell/EtatSomfyV2.sh --AlarmeOFFCode : Tout sélectionner
#!/bin/bash
#----------------------------------------------------------------------------------------------------------------------------------
# Date : 19/11/2016
# Version : 3
# Description : Script Domoticz pour recuperer les etats des alarmes SOMFY PROTEXIUM 600 et Alarme ON/OFF
# Auteur : Seb13
# Merci au forum easydomoticz
#----------------------------------------------------------------------------------------------------------------------------------
declare -A CarteAuthentification
Debug=False
#----------------------------------------------------------------------------------------------------------------------------------
# ZONE DE MODIFICATION
#----------------------------------------------------------------------------------------------------------------------------------
# Carte d'authentification perso
CarteAuthentification=( ["A1"]="xxxx" ["B1"]="xxx" ["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://xxx.xxx.xxx.xxx/"
SrvDomoticzIp="xxx.xxx.xxx.xxx:8080"
# Code Utilisateur1
CodeUtilisateur1=xxxx
# IDX pour Domoticz
AlarmeSomfyPilesIDX=xxx
AlarmeSomfyBoitierIDX=xxx
AlarmeSomfyRadioIDX=xxx
AlarmeSomfyEtatIDX=xxx
AlarmeSomfyPorteIDX=xxx
AlarmeSomfyZoneABCIDX=xxx
#---------------------------------------------------------------------------------------------------------------------------------
# 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"
}
# Script de connexion au site Somfy version Mobile
Connexion_Somfy() {
# 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
curl -L --cookie cjar --cookie-jar cjar --data "password="$CodeUtilisateur1"&key="$CodeAuthentification"&action=Connexion" $UrlMLogin
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
curl -s -L --cookie cjar --cookie-jar cjar --data "password="$CodeUtilisateur1"&key="$CodeAuthentification"&action=Connexion" $UrlMLogin > /dev/null
fi
echo ""
echo "Connexion au site Somfy Mobile OK"
echo ""
}
# Script de deconnexion au site Somfy version Mobile
Deconnexion_Somfy() {
# Logout du site Somfy
if [ "$Debug" = "True" ]; then
echo ""
#curl -L --cookie cjar --cookie-jar cjar $UrlMLogout | iconv -f iso8859-1 -t utf-8
curl -L --cookie cjar --cookie-jar cjar $UrlMLogout
echo ""
else
echo ""
#curl -s -L --cookie cjar --cookie-jar cjar $UrlMLogout | iconv -f iso8859-1 -t utf-8 > /dev/null
curl -s -L --cookie cjar --cookie-jar cjar $UrlMLogout > /dev/null
echo ""
fi
echo ""
echo "Deconnexion au site Somfy Mobile OK"
echo ""
}
# 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
# Script de connexion au site Somfy version Mobile
Connexion_Somfy
# Lecture de la page MuEtat pour recuperer les etats de l alarme
if [ "$Debug" = "True" ]; then
echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
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>'
curl -L --cookie cjar --cookie-jar cjar $UrlMuEtat | iconv -f iso8859-1 -t utf-8 | grep -Eoi 'Communication.*</td>'
curl -L --cookie cjar --cookie-jar cjar $UrlMuEtat | iconv -f iso8859-1 -t utf-8 | grep -Eoi 'Pas.*</td>'
curl -L --cookie cjar --cookie-jar cjar $UrlMuEtat | iconv -f iso8859-1 -t utf-8 | grep -Eoi 'Boîtier.*</td>'
curl -L --cookie cjar --cookie-jar cjar $UrlMuEtat | iconv -f iso8859-1 -t utf-8 | grep -Eoi 'zonea.*</td>'
curl -L --cookie cjar --cookie-jar cjar $UrlMuEtat | iconv -f iso8859-1 -t utf-8 | grep -Eoi 'zoneb.*</td>'
curl -L --cookie cjar --cookie-jar cjar $UrlMuEtat | iconv -f iso8859-1 -t utf-8 | grep -Eoi 'zonec.*</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}")"
EtatZoneA="$(curl -s -L --cookie cjar --cookie-jar cjar $UrlMuEtat | iconv -f iso8859-1 -t utf-8 | grep -Eoi 'zonea.*</td>')"
EtatZoneA="$(echo "${EtatZoneA:28:3}" | sed s/\<//g)"
EtatZoneB="$(curl -s -L --cookie cjar --cookie-jar cjar $UrlMuEtat | iconv -f iso8859-1 -t utf-8 | grep -Eoi 'zoneb.*</td>')"
EtatZoneB="$(echo "${EtatZoneB:28:3}" | sed s/\<//g)"
EtatZoneC="$(curl -s -L --cookie cjar --cookie-jar cjar $UrlMuEtat | iconv -f iso8859-1 -t utf-8 | grep -Eoi 'zonec.*</td>')"
EtatZoneC="$(echo "${EtatZoneC:28:3}" | sed s/\<//g)"
# Affichage des etats
echo "Etat Porte = "$EtatPorte
echo "Etat Piles = "$EtatPiles
echo "Etat Communication Radio = "$EtatRadio
echo "Etat Alarme = "$EtatAlarme
echo "Etat Boitier = "$EtatBoitier
echo "Etat Zone A = "$EtatZoneA
echo "Etat Zone B = "$EtatZoneB
echo "Etat Zone C = "$EtatZoneC
if [ "$EtatZoneA" = "OFF" ] && [ "$EtatZoneB" = "OFF" ] && [ "$EtatZoneC" = "OFF" ]; then
EtatZoneABC="OFF"
echo "Etat Zone ABC = "$EtatZoneABC
fi
if [ "$EtatZoneA" = "ON" ] && [ "$EtatZoneB" = "ON" ] && [ "$EtatZoneC" = "ON" ]; then
EtatZoneABC="ON"
echo "Etat Zone ABC = "$EtatZoneABC
fi
# Envoi des etats a Domoticz
# Etat des piles
if [ "$Debug" = "True" ]; then
if [ "$EtatPiles" = "Piles OK" ]; then
curl "http://$SrvDomoticzIp/json.htm?type=command¶m=switchlight&idx=$AlarmeSomfyPilesIDX&switchcmd=On"
else
curl "http://$SrvDomoticzIp/json.htm?type=command¶m=switchlight&idx=$AlarmeSomfyPilesIDX&switchcmd=Off"
fi
else
if [ "$EtatPiles" = "Piles OK" ]; then
curl -s "http://$SrvDomoticzIp/json.htm?type=command¶m=switchlight&idx=$AlarmeSomfyPilesIDX&switchcmd=On" > /dev/null
else
curl -s "http://$SrvDomoticzIp/json.htm?type=command¶m=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¶m=switchlight&idx=$AlarmeSomfyBoitierIDX&switchcmd=On"
else
curl "http://$SrvDomoticzIp/json.htm?type=command¶m=switchlight&idx=$AlarmeSomfyBoitierIDX&switchcmd=Off"
fi
else
if [ "$EtatBoitier" = "Boîtier OK" ]; then
curl -s "http://$SrvDomoticzIp/json.htm?type=command¶m=switchlight&idx=$AlarmeSomfyBoitierIDX&switchcmd=On" > /dev/null
else
curl -s "http://$SrvDomoticzIp/json.htm?type=command¶m=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¶m=switchlight&idx=$AlarmeSomfyRadioIDX&switchcmd=On"
else
curl "http://$SrvDomoticzIp/json.htm?type=command¶m=switchlight&idx=$AlarmeSomfyRadioIDX&switchcmd=Off"
fi
else
if [ "$EtatRadio" = "Communication radio OK" ]; then
curl -s "http://$SrvDomoticzIp/json.htm?type=command¶m=switchlight&idx=$AlarmeSomfyRadioIDX&switchcmd=On" > /dev/null
else
curl -s "http://$SrvDomoticzIp/json.htm?type=command¶m=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¶m=switchlight&idx=$AlarmeSomfyEtatIDX&switchcmd=Off"
else
curl "http://$SrvDomoticzIp/json.htm?type=command¶m=switchlight&idx=$AlarmeSomfyEtatIDX&switchcmd=On"
fi
else
if [ "$EtatAlarme" = "Pas d'alarme" ]; then
curl -s "http://$SrvDomoticzIp/json.htm?type=command¶m=switchlight&idx=$AlarmeSomfyEtatIDX&switchcmd=Off" > /dev/null
else
curl -s "http://$SrvDomoticzIp/json.htm?type=command¶m=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¶m=switchlight&idx=$AlarmeSomfyPorteIDX&switchcmd=Off"
else
curl "http://$SrvDomoticzIp/json.htm?type=command¶m=switchlight&idx=$AlarmeSomfyPorteIDX&switchcmd=On"
fi
else
if [ "$EtatPorte" = "Porte ou fenêtre fermée" ]; then
curl -s "http://$SrvDomoticzIp/json.htm?type=command¶m=switchlight&idx=$AlarmeSomfyPorteIDX&switchcmd=Off" > /dev/null
else
curl -s "http://$SrvDomoticzIp/json.htm?type=command¶m=switchlight&idx=$AlarmeSomfyPorteIDX&switchcmd=On" > /dev/null
fi
fi
# Etat Zone ABC
if [ "$Debug" = "True" ]; then
if [ "$EtatZoneABC" = "OFF" ]; then
curl "http://$SrvDomoticzIp/json.htm?type=command¶m=switchlight&idx=$AlarmeSomfyZoneABCIDX&switchcmd=Off"
else
curl "http://$SrvDomoticzIp/json.htm?type=command¶m=switchlight&idx=$AlarmeSomfyZoneABCIDX&switchcmd=On"
fi
else
if [ "$EtatZoneABC" = "OFF" ]; then
curl -s "http://$SrvDomoticzIp/json.htm?type=command¶m=switchlight&idx=$AlarmeSomfyZoneABCIDX&switchcmd=Off" > /dev/null
else
curl -s "http://$SrvDomoticzIp/json.htm?type=command¶m=switchlight&idx=$AlarmeSomfyZoneABCIDX&switchcmd=On" > /dev/null
fi
fi
# Logout du site Somfy
Deconnexion_Somfy
fi
if [ "$AlarmeON" = "1" ]; then
echo "Alarme en fonction - script à faire"
# Script de connexion au site Somfy version Mobile
Connexion_Somfy
# curl -L --cookie cjar --cookie-jar cjar $UrlMuPilotage | iconv -f iso8859-1 -t utf-8
curl -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&zone=Marche%20A%20B%20C" $UrlMuPilotage | iconv -f iso8859-1 -t utf-8
Deconnexion_Somfy
fi
if [ "$AlarmeOFF" = "1" ]; then
echo "Alarme en arrêt - script à faire"
# Script de connexion au site Somfy version Mobile
Connexion_Somfy
# curl -L --cookie cjar --cookie-jar cjar $UrlMuPilotage | iconv -f iso8859-1 -t utf-8
curl -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&zone=Arr%EAt%20A%20B%20C" $UrlMuPilotage | iconv -f iso8859-1 -t utf-8
Deconnexion_Somfy
fi
Code : Tout sélectionner
UrlMLogin=$SrvSomfyIp"fr/login.htm"
UrlMuEtat=$SrvSomfyIp"fr/u_listelmt.htm"
UrlMLogout=$SrvSomfyIp"logout.htm"
UrlMuPilotage=$SrvSomfyIp"fr/u_pilotage.htm"Code : Tout sélectionner
login=u&password=XXXX&key=XXXX&btn_login=ConnexionCode : Tout sélectionner
on se connecte à la page
http://IP_ALARME/fr/u_pilotage.htm
et on a ce "POST data"
hidden=hidden&btn_zone_on_ABC=Marche+A+B+C
Code : Tout sélectionner
on se connecte à la page
http://IP_ALARME/fr/u_pilotage.htm
et on a ce "POST data"
hidden=hidden&btn_zone_off_ABC=Arr%C3%AAt+A+B+C
Salutn1c0l45 a écrit :voila ce que j'ai trouvé pour la 5000
Le POST data de connexion est le suivantCode : Tout sélectionner
UrlMLogin=$SrvSomfyIp"fr/login.htm" UrlMuEtat=$SrvSomfyIp"fr/u_listelmt.htm" UrlMLogout=$SrvSomfyIp"logout.htm" UrlMuPilotage=$SrvSomfyIp"fr/u_pilotage.htm"Code : Tout sélectionner
login=u&password=XXXX&key=XXXX&btn_login=Connexion
mise en marche de toutes les zonesArret de toutes les zonesCode : Tout sélectionner
on se connecte à la page http://IP_ALARME/fr/u_pilotage.htm et on a ce "POST data" hidden=hidden&btn_zone_on_ABC=Marche+A+B+C
Code : Tout sélectionner
on se connecte à la page http://IP_ALARME/fr/u_pilotage.htm et on a ce "POST data" hidden=hidden&btn_zone_off_ABC=Arr%C3%AAt+A+B+C
Code : Tout sélectionner
hidden=hidden&hidden=hidden&btn_zone_on_A=Marche A
hidden=hidden&hidden=hidden&btn_zone_on_B=Marche B
hidden=hidden&hidden=hidden&btn_zone_on_C=Marche CCode : Tout sélectionner
http://IP_ALARME/status.xmlCode : Tout sélectionner
<?xml version="1.0" encoding="iso-8859-15"?>
<response>
<zone0>off</zone0> -> Zone A
<zone1>off</zone1> -> Zone B
<zone2>off</zone2> -> Zone C
<defaut0>ok</defaut0> -> Piles
<defaut1>ok</defaut1> -> Radio
<defaut2>ok</defaut2> -> Porte/Fenetre
<defaut3>ok</defaut3> -> Alarme
<defaut4>ok</defaut4> -> Boitier
<gsm>GSM connecté au réseau</gsm> -> GSM
<recgsm>4</recgsm> -> Signal
<opegsm>"Orange</opegsm> -> Operateur
<camera>disabled</camera> -> Camera
</response>Code : Tout sélectionner
# Declaration des URLs du site Somfy
UrluListeElement=$SrvSomfyIp"u_listelmt.htm"
Connexion_Somfy
# On recup la liste des elements par la recherche elt_name
ListeElement="$(curl -L --cookie cjar --cookie-jar cjar $UrluListeElement | iconv -f iso8859-1 -t utf-8 | grep 'var elt_name')"
# On supprime les 21 premiers caracteres et les 2 derniers
ListeElement="$(echo "${ListeElement:21:-2}")"
# On remplace les " par rien on les supprime
ListeElement="$(echo "$ListeElement" | sed s/\"//g)"
# On remplace ", " par "," on supprime les espaces entre les virgules
ListeElement="$(echo "$ListeElement" | sed s/\,\ /\,/g)"
# On doit avoir la liste des elements sans , et avec des ' a la place des "
echo "Liste des elements = "$ListeElement
# On declare la virgule comme element separateur
IFS=","
# On alimente la variable tableau avec les elements separes par une virgule
TabListeElement=($ListeElement)
# On affiche les elements du tableau
for TabLecture in ${TabListeElement[*]}
do
echo $TabLecture;
done
Deconnexion_Somfy