Somfy Alarm Script not running

All kinds of 'OS' scripts

Moderator: leecollings

MikeyMan
Posts: 237
Joined: Wednesday 17 October 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Somfy Alarm Script not running

Post by MikeyMan »

Hi Guys,

I'm trying to integrate my Somfy Protexiom Alarm into Domoticz. Just walking my first steps on the scripting path.
And getting a bit stuck with the script i found on a french forum. My lack of scripting experience is adding up greatly to my lack of attention i've paid in french class...

I've been changing the user parameters as far as i could, and got the script to run.
However, i'm running into the following errors now:

/home/pi/domoticz/scripts/somfy.sh: 56: /home/pi/domoticz/scripts/somfy.sh: declare: not found
/home/pi/domoticz/scripts/somfy.sh: 58: /home/pi/domoticz/scripts/somfy.sh: Syntax error: "(" unexpected

Can someone help me out here?

The code i found:

Code: Select all

#!/bin/bash
#----------------------------------------------------------------------------------------------------------------------
# Script alarme_Somfy.sh
# Date : 11/2016
# Version : 2.0
# Par : jcjames_13009 <jcjames_13009 at yahoo.fr>
# Description : Script de pilotage de l'alarme Somfy Protexiom 5000 via Domoticz sur Raspberry Pi
# - Adapatation du script de Seb13 du forum easydomoticz.com pour Alarme Somfy Protexion 600 au modèle Protexion 5000
#   * Lecture des états du système et mise à jour dans Domoticz
#   * Mise en marche de l'alarme Zone A
#   * Mise en marche de l'alarme Zone B
#   * Mise en marche de l'alarme Zone C
#   * Mise en marche de l'alarme Zones A B C
#   * Arrêt de l'alarme Zones A B C
#   * Reset defauts piles, liaisons et alarmes
#	* Gestion liste des éléments et mise à jour dans Domoticz
#----------------------------------------------------------------------------------------------------------------------
# Appel du script
# - Mise à jour des états de l'alarme toutes les 15min via le crontab :
#   */15 * * * * sudo /home/pi/domoticz/scripts/shell/alarme_somfy.sh --Status
# - Pilotage de l'alarme à partir de DOMOTICZ :
#   Ex pour la mise en marche Zone A ajouter dans l'onglet "Action On" du capteur virtuel: 
#   script:///home/pi/domoticz/scripts/shell/alarme_somfy.sh --ZoneAOn 
#----------------------------------------------------------------------------------------------------------------------
# Version : 2.1
# Date : 25/11/2016
# - Ajout d'un "sleep 1" pour éviter les pertes de retour d'état de l'alarme entre chaque cde dans la lecture de l'état 
#	du système et de la liste des éléments
#----------------------------------------------------------------------------------------------------------------------
# Version : 2.2
# Date : 27/11/2016
# - Ajout cde reset defauts piles, liaisons et alarmes
#----------------------------------------------------------------------------------------------------------------------
# Version : 2.3
# Date : 10/12/2016
# - Gestion liste des éléments et mise à jour dans Domoticz
#----------------------------------------------------------------------------------------------------------------------
# Version : 2.4
# Date : 04/01/2017
# - Envoie d'une seule commande pour éviter les pertes de retour d'état de l'alarme entre chaque cde dans la lecture de
#	l'état du système et de la liste des éléments
#----------------------------------------------------------------------------------------------------------------------
# Version 2.5
# Date : 21/12/2017
# - Adaptation du script à Domoticz sur NAS Synology
#   Remplacement de iconv qui n'existe pas sur Synology par uconv
#----------------------------------------------------------------------------------------------------------------------

#Debug=True
Debug=False

#----------------------------------------------------------------------------------------------------------------------
# PARAMETRES ALARME
#----------------------------------------------------------------------------------------------------------------------
# Carte d'authentification perso
declare -A CarteAuthentification

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 alarme Somfy 
SrvSomfyIp="http://IP.ALARME/"

# Code Utilisateur1
CodeUtilisateur1=1234

# URLs alarme SOMFY PROTEXION 5000 GSM
UrlLogin=$SrvSomfyIp"fr/login.htm"				# Connexion à l'alarme
UrlLogout=$SrvSomfyIp"logout.htm"				# Déconnexion de l'alarme
UrlEtat=$SrvSomfyIp"status.xml"					# Etat du système
UrlPilotage=$SrvSomfyIp"fr/u_pilotage.htm"		# Pilotage alarme
UrlElements=$SrvSomfyIp"fr/u_listelmt.htm"		# Liste des éléments / Reset défauts

#----------------------------------------------------------------------------------------------------------------------
# PARAMETRES DOMOTICZ
#----------------------------------------------------------------------------------------------------------------------
# Capteurs virtuels Domoticz
AlarmeSomfyPilesIdx=xxx
AlarmeSomfyRadioIdx=xxx
AlarmeSomfyPorteIdx=xxx
AlarmeSomfyAlarmeIdx=xxx
AlarmeSomfyBoitierIdx=xxx

AlarmeSomfyGSMIdx=xxx
AlamreSomfySignalGSMIdx=xxx
AlamreSomfyOperateurGSMIdx=xxx

AlarmeSomfyCameraIdx=xxx

AlamreSomfyZoneAIdx=xxx
AlamreSomfyZoneBIdx=xxx
AlamreSomfyZoneCIdx=xxx

AlamreSomfyDOEntreeIdx=xxx
AlamreSomfyDOAtelierIdx=xxx

# Adresse IP et port du serveur Domoticz
SrvDomoticzIp="IP.DOMOTICZ:PORT"

#----------------------------------------------------------------------------------------------------------------------
# FONCTIONS
#----------------------------------------------------------------------------------------------------------------------
# Fonction menu d'aide
Aide() {
	echo -e "\tScript Domoticz Alarme Somfy Protexion 5000"
	echo -e "\t--help or -h  \t\tMenu d'aide"
	echo -e "\t--Status      \t\tLecture de l'état du système"
	echo -e "\t--Elements    \t\tListe des éléments"
	echo -e "\t--ZoneAOn     \t\tMise en marche de l'alarme Zone A"
	echo -e "\t--ZoneBOn     \t\tMise en marche de l'alarme Zone B"
	echo -e "\t--ZoneCOn     \t\tMise en marche de l'alarme Zone C"
	echo -e "\t--ZonesABCOn  \t\tMise en marche de l'alarme Zones A B C"
	echo -e "\t--AlarmeOff   \t\tArrêt de l'alarme Zones A B C"
	echo -e "\t--RSTPiles    \t\tReset defauts piles"
	echo -e "\t--RSTAlarmes  \t\tReset defauts alarmes"
	echo -e "\t--RSTLiaisons \t\tReset defauts liaisons"
}

# Fonction connexion à l'alarme
login_alarme () {
	# Affichage des URLs
	if [ "$Debug" = "True" ]; then
		echo " ********************************* "
		echo " Liste des URLs"
		echo " ********************************* "
		echo " UrlLogin    = "$UrlLogin
		echo " UrlLogout   = "$UrlLogout
		echo " UrlEtat     = "$UrlEtat
		echo " UrlPilotage = "$UrlPilotage
		echo " UrlElements = "$UrlElements
	fi

	# Récupération du code d'acces
	if [ "$Debug" = "True" ]; then
		echo " Récuperation du code d'accès"
		CodeAcces="$(curl $SrvSomfyIp $UrlLogin | grep -Eoi 'authentification <b>.*</b>')"
		CodeAcces="$(echo "${CodeAcces:20:2}")"
		echo " Code d'accès = "$CodeAcces
	else
		CodeAcces="$(curl -s $SrvSomfyIp $UrlLogin | grep -Eoi 'authentification <b>.*</b>')"
		CodeAcces="$(echo "${CodeAcces:20:2}")"
	fi

	# Récupération du code d'authentification à partir du code d'accès
	CodeAuthentification="${CarteAuthentification["$CodeAcces"]}"
	if [ "$Debug" = "True" ]; then
		echo " Récuperation du code d'authentification"
		echo " Code d'authentification = "$CodeAuthentification
	fi

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

# Fonction déconnexion de l'alarme
logout_alarme () {
	if [ "$Debug" = "True" ]; then
		echo " Déconnexion de l'alarme"
		#curl -L --cookie cjar --cookie-jar cjar $UrlLogout | iconv -f iso8859-1 -t utf-8
		curl -L --cookie cjar --cookie-jar cjar $UrlLogout | uconv -f iso8859-1 -t utf-8
	else
		#curl -s -L --cookie cjar --cookie-jar cjar $UrlLogout | iconv -f iso8859-1 -t utf-8 > /dev/null
		curl -s -L --cookie cjar --cookie-jar cjar $UrlLogout | uconv -f iso8859-1 -t utf-8 > /dev/null
	fi
}

# Fonction mise à jour capteurs Domoticz
# Paramètres: $1 Nom du capteur / $2 On ou Off / $3 Idx du capteur
maj_capteur () {
	if [ "$Debug" = "True" ]; then
		echo " Etat "$1
		if [ "$2" = "On" ]; then
			curl "http://$SrvDomoticzIp/json.htm?type=command&param=switchlight&idx=$3&switchcmd=On"
		else
			curl "http://$SrvDomoticzIp/json.htm?type=command&param=switchlight&idx=$3&switchcmd=Off"
		fi
	else
		if [ "$2" = "On" ]; then
			curl -s "http://$SrvDomoticzIp/json.htm?type=command&param=switchlight&idx=$3&switchcmd=On" > /dev/null
		else
			curl -s "http://$SrvDomoticzIp/json.htm?type=command&param=switchlight&idx=$3&switchcmd=Off" > /dev/null
		fi
	fi
}

#----------------------------------------------------------------------------------------------------------------------
# Menu des options de lancement du script
#----------------------------------------------------------------------------------------------------------------------
while [[ $1 == -* ]]; do
	case "$1" in
		--help|-h) Aide; exit 0;;
		--Status) Status="1"; break;;
		--Elements) Elements="1"; break;;
		--ZoneAOn) ZoneAOn="1"; break;;
		--ZoneBOn) ZoneBOn="1"; break;;
		--ZoneCOn) ZoneCOn="1"; break;;
		--ZonesABCOn) ZonesABCOn="1"; break;;
		--AlarmeOff) AlarmeOff="1"; break;;
		--RSTPiles) RSTPiles="1"; break;;
		--RSTAlarmes) RSTAlarmes="1"; break;;
		--RSTLiaisons) RSTLiaisons="1"; break;;
		--*|-*) shift; break;;
	esac
done

#----------------------------------------------------------------------------------------------------------------------
# Lecture de l'état du système
#----------------------------------------------------------------------------------------------------------------------
if [ "$Status" = "1" ]; then
	# Connexion à l'alarme
	login_alarme
	
	# Lecture de l'état du système et récupération dans les variables
	# Envoie URL http://IPAlarme/status.xml
	# Retour:
	#	<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/Fenêtre
	#	<defaut3>ok</defaut3>				-> Alarme
	#	<defaut4>ok</defaut4>				-> Boitier
	#
	#	<gsm>GSM connecté au réseau</gsm> 	-> GSM
	#	<recgsm>4</recgsm>					-> Signal GSM
	#	<opegsm>"Orange</opegsm>			-> Opérateur GSM
	#	<camera>disabled</camera>			-> Caméra

	# Lecture de l'état du système et stockage dans fichier temporaire
	if [ "$Debug" = "True" ]; then
		echo " Lecture de l'état du système"
		#curl -L --cookie cjar --cookie-jar cjar $UrlEtat | iconv -f iso8859-1 -t utf-8 > status
		curl -L --cookie cjar --cookie-jar cjar $UrlEtat | uconv -f iso8859-1 -t utf-8 > status
	else
		#curl -s -L --cookie cjar --cookie-jar cjar $UrlEtat | iconv -f iso8859-1 -t utf-8 > status
		curl -s -L --cookie cjar --cookie-jar cjar $UrlEtat | uconv -f iso8859-1 -t utf-8 > status
	fi

	# Déconnexion de l'alarme
	logout_alarme
	
	# Récupération dans les variables
	EtatZoneA="$(grep -Eoi '<zone0>.*' status)"
	EtatZoneA="$(echo "${EtatZoneA:7:-9}")"
	EtatZoneB="$(grep -Eoi '<zone1>.*' status)"
	EtatZoneB="$(echo "${EtatZoneB:7:-9}")"
	EtatZoneC="$(grep -Eoi '<zone2>.*' status)"
	EtatZoneC="$(echo "${EtatZoneC:7:-9}")"

	EtatPiles="$(grep -Eoi '<defaut0>.*' status)"
	EtatPiles="$(echo "${EtatPiles:9:-11}")"
	EtatRadio="$(grep -Eoi '<defaut1>.*' status)"
	EtatRadio="$(echo "${EtatRadio:9:-11}")"
	EtatPorte="$(grep -Eoi '<defaut2>.*' status)"
	EtatPorte="$(echo "${EtatPorte:9:-11}")"
	EtatAlarme="$(grep -Eoi '<defaut3>.*' status)"
	EtatAlarme="$(echo "${EtatAlarme:9:-11}")"
	EtatBoitier="$(grep -Eoi '<defaut4>.*' status)"
	EtatBoitier="$(echo "${EtatBoitier:9:-11}")"

	EtatGSM="$(grep -Eoi '<gsm>.*' status)"
	EtatGSM="$(echo "${EtatGSM:5:-7}")"
	SignalGSM="$(grep -Eoi '<recgsm>.*' status)"
	SignalGSM="$(echo "${SignalGSM:8:-10}")"
	OperateurGSM="$(grep -Eoi '<opegsm>.*' status)"
	OperateurGSM="$(echo "${OperateurGSM:9:-10}")"
		
	EtatCamera="$(grep -Eoi '<camera>.*' status)"
	EtatCamera="$(echo "${EtatCamera:8:-10}")"
	
	if [ "$Debug" = "True" ]; then
		# Affichage des états
		echo " ******************************************* "
		echo "  Etat du système"
		echo " ******************************************* "
		echo " Zone A                   = "$EtatZoneA
		echo " Zone B                   = "$EtatZoneB
		echo " Zone C                   = "$EtatZoneC
		echo ""
		echo " Etat Piles               = "$EtatPiles
		echo " Etat Communication Radio = "$EtatRadio
		echo " Etat Porte/Fenêtre       = "$EtatPorte
		echo " Etat Alarme              = "$EtatAlarme
		echo " Etat Boitier             = "$EtatBoitier
		echo ""
		echo " Etat GSM                 = "$EtatGSM
		echo " Signal GSM               = "$SignalGSM
		echo " Opérateur GSM            = "$OperateurGSM
		echo ""
		echo " Etat caméra              = "$EtatCamera
	fi
	
	# Mise à jour capteurs Domoticz
	if [ "$Debug" = "True" ]; then
		echo " Mise à jour capteurs Domoticz"
	fi

	# Zone A
	if [ "$EtatZoneA" = "off" ]; then
		maj_capteur ZoneA Off $AlamreSomfyZoneAIdx
	else
		maj_capteur ZoneA On $AlamreSomfyZoneAIdx
	fi

	# Zone B
	if [ "$EtatZoneB" = "off" ]; then
		maj_capteur ZoneB Off $AlamreSomfyZoneBIdx
	else
		maj_capteur ZoneB On $AlamreSomfyZoneBIdx
	fi

	# Zone C
	if [ "$EtatZoneC" = "off" ]; then
		maj_capteur ZoneC Off $AlamreSomfyZoneCIdx
	else
		maj_capteur ZoneC On $AlamreSomfyZoneCIdx
	fi

	# Etat Piles
	if [ "$EtatPiles" = "ok" ]; then
		maj_capteur Piles On $AlarmeSomfyPilesIdx
	else
		maj_capteur Piles Off $AlarmeSomfyPilesIdx
	fi

	# Communication Radio
	if [ "$EtatRadio" = "ok" ]; then
		maj_capteur Radio On $AlarmeSomfyRadioIdx
	else
		maj_capteur Radio Off $AlarmeSomfyRadioIdx
	fi

	# Porte/Fenêtre
	if [ "$EtatPorte" = "ok" ]; then
		maj_capteur Porte/Fenetre Off $AlarmeSomfyPorteIdx
	else
		maj_capteur Porte/Fenetre On $AlarmeSomfyPorteIdx
	fi

	# Alarme
	if [ "$EtatAlarme" = "ok" ]; then
		maj_capteur Alarme Off $AlarmeSomfyAlarmeIdx
	else
		maj_capteur Alarme On $AlarmeSomfyAlarmeIdx
	fi

	# Boitier
	if [ "$EtatBoitier" = "ok" ]; then
		maj_capteur Boitier Off $AlarmeSomfyBoitierIdx
	else
		maj_capteur Boitier On $AlarmeSomfyBoitierIdx
	fi

	# GSM
	if [ "$EtatGSM" = "GSM connecté au réseau" ]; then
		maj_capteur GSM On $AlarmeSomfyGSMIdx
	else
		maj_capteur GSM Off $AlarmeSomfyGSMIdx
	fi
	
	# Niveau Signal GSM
	if [ "$Debug" = "True" ]; then
		echo " Niveau Signal GSM"
		curl "http://$SrvDomoticzIp/json.htm?type=command&param=udevice&idx=$AlamreSomfySignalGSMIdx&nvalue=0&svalue=$SignalGSM"
	else
		curl -s "http://$SrvDomoticzIp/json.htm?type=command&param=udevice&idx=$AlamreSomfySignalGSMIdx&nvalue=0&svalue=$SignalGSM" > /dev/null
	fi
		
	# Opérateur GSM
	if [ "$Debug" = "True" ]; then
		echo " Opérateur GSM"
		curl "http://$SrvDomoticzIp/json.htm?type=command&param=udevice&idx=$AlamreSomfyOperateurGSMIdx&nvalue=0&svalue=$OperateurGSM"
	else
		curl -s "http://$SrvDomoticzIp/json.htm?type=command&param=udevice&idx=$AlamreSomfyOperateurGSMIdx&nvalue=0&svalue=$OperateurGSM" > /dev/null
	fi	

	# Caméra
	#if [ "$EtatCamera" = "disabled" ]; then
	#	maj_capteur Camera Off $AlarmeSomfyCameraIdx
	#else
	#	maj_capteur Camera On $AlarmeSomfyCameraIdx
	#fi
	
fi	

#----------------------------------------------------------------------------------------------------------------------
# Mise en marche de l'alarme Zones A B C
#----------------------------------------------------------------------------------------------------------------------
if [ "$ZonesABCOn" = "1" ]; then
	# Connexion à l'alarme
	login_alarme

	# Mise en marche de l'alarme Zones A B C
	if [ "$Debug" = "True" ]; then
		echo "Mise en marche de l'alarme Zones A B C"
		#curl -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_ABC=Marche A B C" $UrlPilotage | iconv -f iso8859-1 -t utf-8
		curl -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_ABC=Marche A B C" $UrlPilotage | uconv -f iso8859-1 -t utf-8
	else
		#curl -s -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_ABC=Marche A B C" $UrlPilotage | iconv -f iso8859-1 -t utf-8 > /dev/null
		curl -s -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_ABC=Marche A B C" $UrlPilotage | uconv -f iso8859-1 -t utf-8 > /dev/null
	fi

	# Déconnexion de l'alarme
	logout_alarme

	# Mise à jour capteurs Domoticz
	if [ "$Debug" = "True" ]; then
		echo " Mise à jour capteurs Domoticz"
	fi
	maj_capteur ZoneA On $AlamreSomfyZoneAIdx
	maj_capteur ZoneB On $AlamreSomfyZoneBIdx
	maj_capteur ZoneC On $AlamreSomfyZoneCIdx
fi

#----------------------------------------------------------------------------------------------------------------------
# Mise en marche de l'alarme Zone A
#----------------------------------------------------------------------------------------------------------------------
if [ "$ZoneAOn" = "1" ]; then
	# Connexion à l'alarme
	login_alarme

	# Mise en marche de l'alarme Zone A
	if [ "$Debug" = "True" ]; then
		echo "Mise en marche de l'alarme Zone A"
		#curl -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_A=Marche A" $UrlPilotage | iconv -f iso8859-1 -t utf-8
		curl -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_A=Marche A" $UrlPilotage | uconv -f iso8859-1 -t utf-8
	else
		#curl -s -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_A=Marche A" $UrlPilotage | iconv -f iso8859-1 -t utf-8 > /dev/null
		curl -s -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_A=Marche A" $UrlPilotage | uconv -f iso8859-1 -t utf-8 > /dev/null
	fi

	# Déconnexion de l'alarme
	logout_alarme

	# Mise à jour capteurs Domoticz
	if [ "$Debug" = "True" ]; then
		echo " Mise à jour capteurs Domoticz"
	fi
	maj_capteur ZoneA On $AlamreSomfyZoneAIdx
fi

#----------------------------------------------------------------------------------------------------------------------
# Mise en marche de l'alarme Zone B
#----------------------------------------------------------------------------------------------------------------------
if [ "$ZoneBOn" = "1" ]; then
	# Connexion à l'alarme
	login_alarme

	# Mise en marche de l'alarme Zone B
	if [ "$Debug" = "True" ]; then
		echo "Mise en marche de l'alarme Zone B"
		#curl -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_B=Marche B" $UrlPilotage | iconv -f iso8859-1 -t utf-8
		curl -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_B=Marche B" $UrlPilotage | uconv -f iso8859-1 -t utf-8
	else
		#curl -s -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_B=Marche B" $UrlPilotage | iconv -f iso8859-1 -t utf-8 > /dev/null
		curl -s -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_B=Marche B" $UrlPilotage | uconv -f iso8859-1 -t utf-8 > /dev/null
	fi

	# Déconnexion de l'alarme
	logout_alarme

	# Mise à jour capteurs Domoticz
	if [ "$Debug" = "True" ]; then
		echo " Mise à jour capteurs Domoticz"
	fi
	maj_capteur ZoneB On $AlamreSomfyZoneBIdx
fi

#----------------------------------------------------------------------------------------------------------------------
# Mise en marche de l'alarme Zone C
#----------------------------------------------------------------------------------------------------------------------
if [ "$ZoneCOn" = "1" ]; then
	# Connexion à l'alarme
	login_alarme

	# Mise en marche de l'alarme Zone C
	if [ "$Debug" = "True" ]; then
		echo "Mise en marche de l'alarme Zone C"
		#curl -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_C=Marche C" $UrlPilotage | iconv -f iso8859-1 -t utf-8
		curl -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_C=Marche C" $UrlPilotage | uconv -f iso8859-1 -t utf-8
	else
		#curl -s -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_C=Marche C" $UrlPilotage | iconv -f iso8859-1 -t utf-8 > /dev/null
		curl -s -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_C=Marche C" $UrlPilotage | uconv -f iso8859-1 -t utf-8 > /dev/null
	fi

	# Déconnexion de l'alarme
	logout_alarme

	# Mise à jour capteurs Domoticz
	if [ "$Debug" = "True" ]; then
		echo " Mise à jour capteurs Domoticz"
	fi
	maj_capteur ZoneC On $AlamreSomfyZoneCIdx
fi

#----------------------------------------------------------------------------------------------------------------------
# Arrêt de l'alarme Zones A B C
#----------------------------------------------------------------------------------------------------------------------
if [ "$AlarmeOff" = "1" ]; then
	# Connexion à l'alarme
	login_alarme

	# Arrêt de l'alarme Zones A B C
	if [ "$Debug" = "True" ]; then
		echo "Arret de l'alarme Zones A B C"
		#curl -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&btn_zone_off_ABC=Arrêt A B C" $UrlPilotage | iconv -f iso8859-1 -t utf-8
		curl -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&btn_zone_off_ABC=Arrêt A B C" $UrlPilotage | uconv -f iso8859-1 -t utf-8
	else
		#curl -s -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&btn_zone_off_ABC=Arrêt A B C" $UrlPilotage | iconv -f iso8859-1 -t utf-8 > /dev/null
		curl -s -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&btn_zone_off_ABC=Arrêt A B C" $UrlPilotage | uconv -f iso8859-1 -t utf-8 > /dev/null
	fi

	# Déconnexion de l'alarme
	logout_alarme
	
	# Mise à jour capteurs Domoticz
	if [ "$Debug" = "True" ]; then
		echo " Mise à jour capteurs Domoticz"
	fi
	maj_capteur ZoneA Off $AlamreSomfyZoneAIdx
	maj_capteur ZoneB Off $AlamreSomfyZoneBIdx
	maj_capteur ZoneC Off $AlamreSomfyZoneCIdx
fi

#----------------------------------------------------------------------------------------------------------------------
# Reset defauts piles
#----------------------------------------------------------------------------------------------------------------------
if [ "$RSTPiles" = "1" ]; then
	# Connexion à l'alarme
	login_alarme

	# Reset defauts piles
	if [ "$Debug" = "True" ]; then
		echo "Reset defauts piles"
		#curl -L --cookie cjar --cookie-jar cjar --data "btn_del_pil=Piles" $UrlElements | iconv -f iso8859-1 -t utf-8
		curl -L --cookie cjar --cookie-jar cjar --data "btn_del_pil=Piles" $UrlElements | uconv -f iso8859-1 -t utf-8
	else
		#curl -s -L --cookie cjar --cookie-jar cjar --data "btn_del_pil=Piles" $UrlElements | iconv -f iso8859-1 -t utf-8 > /dev/null
		curl -s -L --cookie cjar --cookie-jar cjar --data "btn_del_pil=Piles" $UrlElements | uconv -f iso8859-1 -t utf-8 > /dev/null
	fi

	# Déconnexion de l'alarme
	logout_alarme
fi

#----------------------------------------------------------------------------------------------------------------------
# Reset defauts alarmes
#----------------------------------------------------------------------------------------------------------------------
if [ "$RSTAlarmes" = "1" ]; then
	# Connexion à l'alarme
	login_alarme

	# Reset defauts alarmes
	if [ "$Debug" = "True" ]; then
		echo "Reset defauts alarmes"
		#curl -L --cookie cjar --cookie-jar cjar --data "btn_del_alm=Alarmes" $UrlElements | iconv -f iso8859-1 -t utf-8
		curl -L --cookie cjar --cookie-jar cjar --data "btn_del_alm=Alarmes" $UrlElements | uconv -f iso8859-1 -t utf-8
	else
		#curl -s -L --cookie cjar --cookie-jar cjar --data "btn_del_alm=Alarmes" $UrlElements | iconv -f iso8859-1 -t utf-8 > /dev/null
		curl -s -L --cookie cjar --cookie-jar cjar --data "btn_del_alm=Alarmes" $UrlElements | uconv -f iso8859-1 -t utf-8 > /dev/null
	fi

	# Déconnexion de l'alarme
	logout_alarme
fi

#----------------------------------------------------------------------------------------------------------------------
# Reset defauts liaisons
#----------------------------------------------------------------------------------------------------------------------
if [ "$RSTLiaisons" = "1" ]; then
	# Connexion à l'alarme
	login_alarme

	# Reset defauts liaisons
	if [ "$Debug" = "True" ]; then
		echo "Reset defauts liaisons"
		#curl -L --cookie cjar --cookie-jar cjar --data "btn_del_lia=Liaisons" $UrlElements | iconv -f iso8859-1 -t utf-8
		curl -L --cookie cjar --cookie-jar cjar --data "btn_del_lia=Liaisons" $UrlElements | uconv -f iso8859-1 -t utf-8
	else
		#curl -s -L --cookie cjar --cookie-jar cjar --data "btn_del_lia=Liaisons" $UrlElements | iconv -f iso8859-1 -t utf-8 > /dev/null
		curl -s -L --cookie cjar --cookie-jar cjar --data "btn_del_lia=Liaisons" $UrlElements | uconv -f iso8859-1 -t utf-8 > /dev/null
	fi

	# Déconnexion de l'alarme
	logout_alarme
fi

#----------------------------------------------------------------------------------------------------------------------
# Gestion de la liste des éléments
#----------------------------------------------------------------------------------------------------------------------
if [ "$Elements" = "1" ]; then
	# Connexion à l'alarme
	login_alarme

	# Lecture de la liste des éléments et stockage dans fichier temporaire
	if [ "$Debug" = "True" ]; then
		echo "Gestion liste des éléments"
		#curl -L --cookie cjar --cookie-jar cjar $UrlElements | iconv -f iso8859-1 -t utf-8 > elements
		curl -L --cookie cjar --cookie-jar cjar $UrlElements | uconv -f iso8859-1 -t utf-8 > elements
	else
		#curl -s -L --cookie cjar --cookie-jar cjar $UrlElements | iconv -f iso8859-1 -t utf-8 > elements
		curl -s -L --cookie cjar --cookie-jar cjar $UrlElements | uconv -f iso8859-1 -t utf-8 > elements
	fi

	# Déconnexion de l'alarme
	logout_alarme
	
	# Récupération dans les variables
	TypeElements="$(grep -Eoi 'var item_label.*' elements)"
	NomElements="$(grep -Eoi 'var elt_name.*' elements)"
	EtatElements="$(grep -Eoi 'var item_pause.*' elements)"
	EtatPiles="$(grep -Eoi 'var elt_pile.*' elements)"
	EtatLiaison="$(grep -Eoi 'var elt_onde.*' elements)"
	EtatPortes="$(grep -Eoi 'var elt_porte.*' elements)"
	EtatBoitiers="$(grep -Eoi 'var elt_as.*' elements)"
	EtatAlarme="$(grep -Eoi 'var elt_maison.*' elements)"

	# Affichage des éléments
	if [ "$Debug" = "True" ]; then
		echo " Type des éléments"
		echo $TypeElements
		echo " Nom des éléments"
		echo $NomElements
		echo " Etat des éléments"
		echo $EtatElements
		echo " Etat des piles"
		echo $EtatPiles
		echo " Etat liaison radio"
		echo $EtatLiaison
		echo " Etat détecteurs ouverture"
		echo $EtatPortes
		echo " Etat ouverture boitiers"
		echo $EtatBoitiers
		echo " Etat alarme"
		echo $EtatAlarme
	fi
		
	# Formatage du type des éléments	
	# Suppression des 21 1er caractères et 2 derniers
	TypeElements="$(echo "${TypeElements:21:-2}")"
	# Suppression des "
	TypeElements="$(echo "$TypeElements" | sed s/\"//g)"
	# Suppression des espaces entre les ,
	TypeElements="$(echo "$TypeElements" | sed s/\,\ /\,/g)"
	# Déclaration , comme séparateur
	IFS=","
	# Stockage dans le tableau
	TabTypeElements=($TypeElements)

	# Formatage des noms des éléments
	# Suppression des 21 1er caractères et 2 derniers
	NomElements="$(echo "${NomElements:21:-2}")"
	# Suppression des "
	NomElements="$(echo "$NomElements" | sed s/\"//g)"
	# Suppression des espaces entre les ,
	NomElements="$(echo "$NomElements" | sed s/\,\ /\,/g)"
	# Déclaration , comme séparateur
	IFS=","
	# Stockage dans le tableau
	TabNomElements=($NomElements)
		
	# Formatage état des éléments
	# Suppression des 21 1er caractères et 2 derniers
	EtatElements="$(echo "${EtatElements:21:-2}")"
	# Suppression des "
	EtatElements="$(echo "$EtatElements" | sed s/\"//g)"
	# Suppression des espaces entre les ,
	EtatElements="$(echo "$EtatElements" | sed s/\,\ /\,/g)"
	# Déclaration , comme séparateur
	IFS=","
	# Stockage dans le tableau
	TabEtatElements=($EtatElements)
	# Modification valeurs tableau
	TailleTab=${#TabEtatElements[@]}
	for (( i=0; i<$TailleTab; i++ ))
	do
		if [ ${TabEtatElements["$i"]} = "running" ]; then TabEtatElements["$i"]="Activé"
		else
			TabEtatElements["$i"]="Désactivé"
		fi
	done

	# Formatage état des piles
	# Suppression des 21 1er caractères et 2 derniers
	EtatPiles="$(echo "${EtatPiles:21:-2}")"
	# Suppression des "
	EtatPiles="$(echo "$EtatPiles" | sed s/\"//g)"
	# Suppression des espaces entre les ,
	EtatPiles="$(echo "$EtatPiles" | sed s/\,\ /\,/g)"
	# Déclaration , comme séparateur
	IFS=","
	# Stockage dans le tableau
	TabEtatPiles=($EtatPiles)
	# Modification des valeurs du tableau
	TailleTab=${#TabEtatPiles[@]}
	for (( i=0; i<$TailleTab; i++ ))
	do
		if [ ${TabEtatPiles["$i"]} = "itemhidden" ]; then TabEtatPiles["$i"]="NA"
		else
			if [ ${TabEtatPiles["$i"]} = "itembattok" ]; then TabEtatPiles["$i"]="OK"
			else
				TabEtatPiles["$i"]="NOK"
			fi
		fi
	done

	# Formatage état liaison radio
	# Suppression des 21 1er caractères et 2 derniers
	EtatLiaison="$(echo "${EtatLiaison:21:-2}")"
	# Suppression des "
	EtatLiaison="$(echo "$EtatLiaison" | sed s/\"//g)"
	# Suppression des espaces entre les ,
	EtatLiaison="$(echo "$EtatLiaison" | sed s/\,\ /\,/g)"
	# Déclaration , comme séparateur
	IFS=","
	# Stockage dans le tableau
	TabEtatLiaison=($EtatLiaison)
	# Modification des valeurs du tableau
	TailleTab=${#TabEtatLiaison[@]}
	for (( i=0; i<$TailleTab; i++ ))
	do
		if [ ${TabEtatLiaison["$i"]} = "itemhidden" ]; then TabEtatLiaison["$i"]="NA"
		else
			if [ ${TabEtatLiaison["$i"]} = "itemcomok" ]; then TabEtatLiaison["$i"]="OK"
			else
				TabEtatLiaison["$i"]="NOK"
			fi
		fi
	done
		
	# Récup état détecteurs ouverture
	# Suppression des 21 1er caractères et 2 derniers
	EtatPortes="$(echo "${EtatPortes:21:-2}")"
	# Suppression des "
	EtatPortes="$(echo "$EtatPortes" | sed s/\"//g)"
	# Suppression des espaces entre les ,
	EtatPortes="$(echo "$EtatPortes" | sed s/\,\ /\,/g)"
	# Déclaration , comme séparateur
	IFS=","
	# Stockage dans le tableau
	TabEtatPortes=($EtatPortes)
	# Modification des valeurs du tableau
	TailleTab=${#TabEtatPortes[@]}
	for (( i=0; i<$TailleTab; i++ ))
	do
		if [ ${TabEtatPortes["$i"]} = "itemhidden" ]; then TabEtatPortes["$i"]="NA"
		else
			if [ ${TabEtatPortes["$i"]} = "itemdoorok" ]; then TabEtatPortes["$i"]="Fermée"
			else
				TabEtatPortes["$i"]="Ouverte"
			fi
		fi
	done
		
	# Récup état ouverture boitiers
	# Suppression des 21 1er caractères et 2 derniers
	EtatBoitiers="$(echo "${EtatBoitiers:21:-2}")"
	# Suppression des "
	EtatBoitiers="$(echo "$EtatBoitiers" | sed s/\"//g)"
	# Suppression des espaces entre les ,
	EtatBoitiers="$(echo "$EtatBoitiers" | sed s/\,\ /\,/g)"
	# Déclaration , comme séparateur
	IFS=","
	# Stockage dans le tableau
	TabEtatBoitiers=($EtatBoitiers)
	# Modification des valeurs du tableau
	TailleTab=${#TabEtatBoitiers[@]}
	for (( i=0; i<$TailleTab; i++ ))
	do
		if [ ${TabEtatBoitiers["$i"]} = "itemhidden" ]; then TabEtatBoitiers["$i"]="NA"
		else
			if [ ${TabEtatBoitiers["$i"]} = "itemboxok" ]; then TabEtatBoitiers["$i"]="Fermé"
			else
				TabEtatBoitiers["$i"]="Ouvert"
			fi
		fi
	done
		
	# Récup état alarme
	# Suppression des 21 1er caractères et 2 derniers
	EtatAlarme="$(echo "${EtatAlarme:21:-2}")"
	# Suppression des "
	EtatAlarme="$(echo "$EtatAlarme" | sed s/\"//g)"
	# Suppression des espaces entre les ,
	EtatAlarme="$(echo "$EtatAlarme" | sed s/\,\ /\,/g)"
	# Déclaration , comme séparateur
	IFS=","
	# Stockage dans le tableau
	TabEtatAlarme=($EtatAlarme)
	# Modification des valeurs du tableau
	TailleTab=${#TabEtatAlarme[@]}
	for (( i=0; i<$TailleTab; i++ ))
	do
		if [ ${TabEtatAlarme["$i"]} = "itemhouseok" ]; then TabEtatAlarme["$i"]="Pas d'alarme"
		else
			TabEtatAlarme["$i"]="Alarme"
		fi
	done
		
	# Affichage de la liste des éléments
	if [ "$Debug" = "True" ]; then
		echo " Liste des éléments"
		TailleTab=${#TabNomElements[@]}
		for (( i=0; i<$TailleTab; i++ ))
		do
			echo " Type : "${TabTypeElements["$i"]} "/ Nom : "${TabNomElements["$i"]} "/ Etat : "${TabEtatElements["$i"]} "/ Etat piles : "${TabEtatPiles["$i"]} "/ Etat liaison : "${TabEtatLiaison["$i"]} "/ Etat portes : "${TabEtatPortes["$i"]} "/ Etat boitiers : "${TabEtatBoitiers["$i"]} "/ Etat alarme : "${TabEtatAlarme["$i"]}
		done	
	fi
	
	# Mise à jour capteurs Domoticz
	if [ "$Debug" = "True" ]; then
		echo " Mise à jour capteurs Domoticz"
	fi

	# DO Entré
	TailleTab=${#TabNomElements[@]}
	for (( i=0; i<$TailleTab; i++ ))
	do
		if [ ${TabNomElements["$i"]} = "DO Entree" ]; then PosElement=$i
		fi
	done
	if [ ${TabEtatPortes["$PosElement"]} = "Fermée" ]; then
		maj_capteur DOEntrée Off $AlamreSomfyDOEntreeIdx
	else
		maj_capteur DOEntrée On $AlamreSomfyDOEntreeIdx
	fi
	
	# DO Couloir
	for (( i=0; i<$TailleTab; i++ ))
	do
		if [ ${TabNomElements["$i"]} = "DO Couloir" ]; then PosElement=$i
		fi
	done
	if [ ${TabEtatPortes["$PosElement"]} = "Fermée" ]; then
		maj_capteur DOAtelier Off $AlamreSomfyDOAtelierIdx
	else
		maj_capteur DOAtelier On $AlamreSomfyDOAtelierIdx
	fi
	
fi

exit 0
Last edited by MikeyMan on Friday 07 February 2020 8:57, edited 1 time in total.
MikeyMan
Posts: 237
Joined: Wednesday 17 October 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Somfy Alarm Script

Post by MikeyMan »

If anyone is able to help out, would be much appreciated :)
clumpton
Posts: 31
Joined: Saturday 18 January 2020 13:17
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: France
Contact:

Re: Somfy Alarm Script

Post by clumpton »

What are you running this on? Your profile says RaspberryPi.
"declare" is a built-in linux/bash command and should not cause an error - works fine in Raspbian, as does line 58.
MikeyMan
Posts: 237
Joined: Wednesday 17 October 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Somfy Alarm Script

Post by MikeyMan »

I am indeed running this on a Raspberry Pi

This is quite literally the first thing i ever tried scripting, so i have to go a long way i'm afraid :)
clumpton
Posts: 31
Joined: Saturday 18 January 2020 13:17
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: France
Contact:

Re: Somfy Alarm Script

Post by clumpton »

Can you try this on the RaspberryPi command line?

Code: Select all

 declare -A TestArray
 TestArray=(["A1"]="xxxx" ["B1"]="yyyy" ["C1"]="zzzz")
 echo ${TestArray["A1"]}
 echo ${TestArray["B1"]}
 echo ${TestArray["C1"]}
You should get no error messages and each 'echo' should return xxxx, yyyy etc.

Doing a

Code: Select all

bash --version
might help see if something is wrong with bash itself.
MikeyMan
Posts: 237
Joined: Wednesday 17 October 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Somfy Alarm Script

Post by MikeyMan »

Thanks for the help, much appreciated! :)

test script gives me no errors, and indeed xxxx, yyyy, zzzz

bash --version gives me:

GNU bash, version 5.0.3(1)-release (arm-unknown-linux-gnueabihf)

but still the same issue when i run sh Somfy.sh
could this be a translation issue, since this was originally a French script?
MikeyMan
Posts: 237
Joined: Wednesday 17 October 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Somfy Alarm Script

Post by MikeyMan »

Wait a minute... it see declare is not supported by sh...

Bash Somfy.sh doesnt give me an error, but nothing seems to happen though.
clumpton
Posts: 31
Joined: Saturday 18 January 2020 13:17
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: France
Contact:

Re: Somfy Alarm Script

Post by clumpton »

MikeyMan wrote: Wednesday 05 February 2020 14:40 Wait a minute... it see declare is not supported by sh...

Bash Somfy.sh doesnt give me an error, but nothing seems to happen though.
The #!/bin/bash at the beginning of the script is known as shebang , it tells the interpreter that the following lines are written for bash, so execute this file as bash script.

Have you made Somfy.sh executable (I suspect that you must have)?
If not make sure that you do a:

Code: Select all

sudo chmod 755 /home/pi/domoticz/scripts/somfy.sh
Also remember that Somfy.sh and somfy.sh are two different files!
MikeyMan
Posts: 237
Joined: Wednesday 17 October 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Somfy Alarm Script

Post by MikeyMan »

Did the do to make it executable. Did that in the past, but been fiddling with a migration to Buster.
Ran that again, to no avail. Even though debug=on and i see a lot of 'echo' which should be printed to screen...

Code: Select all

pi@raspberrypi:~/domoticz/scripts $ sudo bash somfy.sh                          
pi@raspberrypi:~/domoticz/scripts $ 
literally nothing happens :(
clumpton
Posts: 31
Joined: Saturday 18 January 2020 13:17
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: France
Contact:

Re: Somfy Alarm Script

Post by clumpton »

Are you sure that the first line of your script is
#!/bin/bash
?

Try running it like this

Code: Select all

./somfy.sh
clumpton
Posts: 31
Joined: Saturday 18 January 2020 13:17
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: France
Contact:

Re: Somfy Alarm Script

Post by clumpton »

Try this:
Make a new test script called test.sh (sic)

Code: Select all

sudo nano test.sh
Paste the following into it

Code: Select all

#!/bin/bash
#-----------------------------------------------------------------------------------------------------------$
# Script test.sh
# Date :02/20
# Version : 1.0
# By : Clumpton
declare -A TestArray
TestArray=(["A1"]="xxxx" ["B1"]="yyyy" ["C1"]="zzzz")
echo ${TestArray["A1"]}
echo ${TestArray["B1"]}
echo ${TestArray["C1"]}
Press Ctrl-O, then ENTER to write the file. Ctrl-X to quit nano
Make the file executable

Code: Select all

sudo chmod 755 test.sh
Try running the script

Code: Select all

./test.sh
MikeyMan
Posts: 237
Joined: Wednesday 17 October 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Somfy Alarm Script

Post by MikeyMan »

That test script is working fine... ./somfy.sh does nothing as well...

First line is indeed #!/bin/bash.
Got the script from: https://easydomoticz.com/forum/viewtopic.php?t=2831

To be sure (i have been fiddling around with the comments), this is the most recent version:

Code: Select all

#!/bin/bash
#----------------------------------------------------------------------------------------------------------------------
# Script alarme_Somfy.sh
# Date : 11/2016
# Version : 2.0
# Par : jcjames_13009 <jcjames_13009 at yahoo.fr>
# Description : Script de pilotage de l'alarme Somfy Protexiom 5000 via Domoticz sur Raspberry Pi
# - Adapatation du script de Seb13 du forum easydomoticz.com pour Alarme Somfy Protexion 600 au modèle Protexion 5000
#   * Lecture des états du système et mise à jour dans Domoticz
#   * Mise en marche de l'alarme Zone A
#   * Mise en marche de l'alarme Zone B
#   * Mise en marche de l'alarme Zone C
#   * Mise en marche de l'alarme Zones A B C
#   * Arret de l'alarme Zones A B C
#   * Reset defauts piles, liaisons et alarmes
#	* Gestion liste des Elements et mise à jour dans Domoticz
#----------------------------------------------------------------------------------------------------------------------
# Appel du script
# - Mise à jour des états de l'alarme toutes les 15min via le crontab :
#   */15 * * * * sudo /home/pi/domoticz/scripts/somfy.sh --Status
# - Pilotage de l'alarme à partir de DOMOTICZ :
#   Ex pour la mise en marche Zone A ajouter dans l'onglet "Action On" du capteur virtuel: 
#   script:///home/pi/domoticz/scripts/somfy.sh --ZoneAOn 
#----------------------------------------------------------------------------------------------------------------------
# Version : 2.1
# Date : 25/11/2016
# - Ajout d'un "sleep 1" pour éviter les pertes de retour d'état de l'alarme entre chaque cde dans la lecture de l'état 
#	du système et de la liste des Elements
#----------------------------------------------------------------------------------------------------------------------
# Version : 2.2
# Date : 27/11/2016
# - Ajout cde reset defauts piles, liaisons et alarmes
#----------------------------------------------------------------------------------------------------------------------
# Version : 2.3
# Date : 10/12/2016
# - Gestion liste des Elements et mise à jour dans Domoticz
#----------------------------------------------------------------------------------------------------------------------
# Version : 2.4
# Date : 04/01/2017
# - Envoie d'une seule commande pour éviter les pertes de retour d'état de l'alarme entre chaque cde dans la lecture de
#	l'état du système et de la liste des Elements
#----------------------------------------------------------------------------------------------------------------------
# Version 2.5
# Date : 21/12/2017
# - Adaptation du script à Domoticz sur NAS Synology
#   Remplacement de iconv qui n'existe pas sur Synology par uconv
#----------------------------------------------------------------------------------------------------------------------

Debug=True
#Debug=False

#----------------------------------------------------------------------------------------------------------------------
# PARAMETRES ALARME
#----------------------------------------------------------------------------------------------------------------------
# Carte d'authentification perso
declare -A CarteAuthentification

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 alarme Somfy 
SrvSomfyIp="http://10.0.0.0/"

# Code Utilisateur1
CodeUtilisateur1=1111

# URLs alarme SOMFY PROTEXION 5000 GSM
UrlLogin=$SrvSomfyIp"gb/login.htm"				# Connect
UrlLogout=$SrvSomfyIp"logout.htm"				# Log out
UrlEtat=$SrvSomfyIp"status.xml"					# Status
UrlPilotage=$SrvSomfyIp"gb/u_pilotage.htm"		# Control of alarm and automatic devices
UrlElements=$SrvSomfyIp"gb/u_listelmt.htm"		# List of system devices

#----------------------------------------------------------------------------------------------------------------------
# PARAMETRES DOMOTICZ
#----------------------------------------------------------------------------------------------------------------------
# ID's Domoticz
AlarmeSomfyPilesIdx=18
AlarmeSomfyRadioIdx=19
AlarmeSomfyPorteIdx=20
AlarmeSomfyAlarmeIdx=21
AlarmeSomfyBoitierIdx=22

AlarmeSomfyGSMIdx=26
AlarmeSomfySignalGSMIdx=24
AlarmeSomfyOperateurGSMIdx=25

#AlarmeSomfyCameraIdx=xxx

AlarmeSomfyZoneAIdx=15
AlarmeSomfyZoneBIdx=16
AlarmeSomfyZoneCIdx=17

#AlarmeSomfyDOEntreeIdx=xxx
#AlarmeSomfyDOAtelierIdx=xxx

# Adresse IP et port du serveur Domoticz
SrvDomoticzIp="10.0.0.30:8080"

#----------------------------------------------------------------------------------------------------------------------
# FONCTIONS
#----------------------------------------------------------------------------------------------------------------------
# Fonction menu d'aide
Aide() {
	echo -e "\tScript Domoticz Alarme Somfy Protexion 5000"
	echo -e "\t--help or -h  \t\tMenu d'aide"
	echo -e "\t--Status      \t\tLecture de l'état du système"
	echo -e "\t--Elements    \t\tListe des Elements"
	echo -e "\t--ZoneAOn     \t\tMise en marche de l'alarme Zone A"
	echo -e "\t--ZoneBOn     \t\tMise en marche de l'alarme Zone B"
	echo -e "\t--ZoneCOn     \t\tMise en marche de l'alarme Zone C"
	echo -e "\t--ZonesABCOn  \t\tMise en marche de l'alarme Zones A B C"
	echo -e "\t--AlarmeOff   \t\tArret de l'alarme Zones A B C"
	echo -e "\t--RSTPiles    \t\tReset defauts piles"
	echo -e "\t--RSTAlarmes  \t\tReset defauts alarmes"
	echo -e "\t--RSTLiaisons \t\tReset defauts liaisons"
}

# Functie connectie met alarm
login_alarme () {
	# Affichage des URLs
	if [ "$Debug" = "True" ]; then
		echo " ********************************* "
		echo " Liste des URLs"
		echo " ********************************* "
		echo " UrlLogin    = "$UrlLogin
		echo " UrlLogout   = "$UrlLogout
		echo " UrlEtat     = "$UrlEtat
		echo " UrlPilotage = "$UrlPilotage
		echo " UrlElements = "$UrlElements
	fi

	# Ophalen toegangscode
	if [ "$Debug" = "True" ]; then
		echo " Toegangscode ophalen"
		CodeAcces="$(curl $SrvSomfyIp $UrlLogin | grep -Eoi 'authentification <b>.*</b>')"
		CodeAcces="$(echo "${CodeAcces:20:2}")"
		echo " Code d'accès = "$CodeAcces
	else
		CodeAcces="$(curl -s $SrvSomfyIp $UrlLogin | grep -Eoi 'authentification <b>.*</b>')"
		CodeAcces="$(echo "${CodeAcces:20:2}")"
	fi

	# De verificatiecode ophalen uit de toegangscode
	CodeAuthentification="${CarteAuthentification["$CodeAcces"]}"
	if [ "$Debug" = "True" ]; then
		echo " Ophalen Authentificatiecode"
		echo " Authenticatiecode = "$CodeAuthentification
	fi

	# De user1-code en de authenticatiecode verzenden in de aanmeldings-URL voor Inloggen
	if [ "$Debug" = "True" ]; then
		echo " Gebruiker1-code en verificatiecode verzenden"
		curl -L --cookie cjar --cookie-jar cjar --data "password="$CodeUtilisateur1"&key="$CodeAuthentification"&btn_login=Connexion" $UrlLogin | iconv -f iso8859-1 -t utf-8
		#curl -L --cookie cjar --cookie-jar cjar --data "password="$CodeUtilisateur1"&key="$CodeAuthentification"&btn_login=Connexion" $UrlLogin | uconv -f iso8859-1 -t utf-8
	else
		curl -s -L --cookie cjar --cookie-jar cjar --data "password="$CodeUtilisateur1"&key="$CodeAuthentification"&btn_login=Connexion" $UrlLogin  | iconv -f iso8859-1 -t utf-8 > /dev/null
		#curl -s -L --cookie cjar --cookie-jar cjar --data "password="$CodeUtilisateur1"&key="$CodeAuthentification"&btn_login=Connexion" $UrlLogin  | uconv -f iso8859-1 -t utf-8 > /dev/null
	fi
}

# Functie verbinden met Alarm
logout_alarme () {
	if [ "$Debug" = "True" ]; then
		echo " Verbinden met alarm"
		curl -L --cookie cjar --cookie-jar cjar $UrlLogout | iconv -f iso8859-1 -t utf-8
		#curl -L --cookie cjar --cookie-jar cjar $UrlLogout | uconv -f iso8859-1 -t utf-8
	else
		curl -s -L --cookie cjar --cookie-jar cjar $UrlLogout | iconv -f iso8859-1 -t utf-8 > /dev/null
		#curl -s -L --cookie cjar --cookie-jar cjar $UrlLogout | uconv -f iso8859-1 -t utf-8 > /dev/null
	fi
}

# Functie update Domoticz sensoren
# Parameters: $1 Sensornaam / $2 On / Off / $3 Idx sensor
maj_capteur () {
	if [ "$Debug" = "True" ]; then
		echo " Staat "$1
		if [ "$2" = "On" ]; then
			curl "http://$SrvDomoticzIp/json.htm?type=command&param=switchlight&idx=$3&switchcmd=On"
		else
			curl "http://$SrvDomoticzIp/json.htm?type=command&param=switchlight&idx=$3&switchcmd=Off"
		fi
	else
		if [ "$2" = "On" ]; then
			curl -s "http://$SrvDomoticzIp/json.htm?type=command&param=switchlight&idx=$3&switchcmd=On" > /dev/null
		else
			curl -s "http://$SrvDomoticzIp/json.htm?type=command&param=switchlight&idx=$3&switchcmd=Off" > /dev/null
		fi
	fi
}

#----------------------------------------------------------------------------------------------------------------------
# Menu des options de lancement du script
#----------------------------------------------------------------------------------------------------------------------
while [[ $1 == -* ]]; do
	case "$1" in
		--help|-h) Aide; exit 0;;
		--Status) Status="1"; break;;
		--Elements) Elements="1"; break;;
		--ZoneAOn) ZoneAOn="1"; break;;
		--ZoneBOn) ZoneBOn="1"; break;;
		--ZoneCOn) ZoneCOn="1"; break;;
		--ZonesABCOn) ZonesABCOn="1"; break;;
		--AlarmeOff) AlarmeOff="1"; break;;
		--RSTPiles) RSTPiles="1"; break;;
		--RSTAlarmes) RSTAlarmes="1"; break;;
		--RSTLiaisons) RSTLiaisons="1"; break;;
		--*|-*) shift; break;;
	esac
done

#----------------------------------------------------------------------------------------------------------------------
# Lecture de l'état du système
#----------------------------------------------------------------------------------------------------------------------
if [ "$Status" = "1" ]; then
	# Connexion à l'alarme
	login_alarme
	
	# Lecture de l'état du système et récupération dans les variables
	# Envoie URL http://IPAlarme/status.xml
	# Retour:
	#	<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/Fenêtre
	#	<defaut3>ok</defaut3>				-> Alarme
	#	<defaut4>ok</defaut4>				-> Boitier
	#
	#	<gsm>GSM connecté au réseau</gsm> 	-> GSM
	#	<recgsm>4</recgsm>					-> Signal GSM
	#	<opegsm>"Orange</opegsm>			-> Opérateur GSM
	#	<camera>disabled</camera>			-> Caméra

	# Lecture de l'état du système et stockage dans fichier temporaire
	if [ "$Debug" = "True" ]; then
		echo " Lecture de l'état du système"
		curl -L --cookie cjar --cookie-jar cjar $UrlEtat | iconv -f iso8859-1 -t utf-8 > status
		#curl -L --cookie cjar --cookie-jar cjar $UrlEtat | uconv -f iso8859-1 -t utf-8 > status
	else
		curl -s -L --cookie cjar --cookie-jar cjar $UrlEtat | iconv -f iso8859-1 -t utf-8 > status
		#curl -s -L --cookie cjar --cookie-jar cjar $UrlEtat | uconv -f iso8859-1 -t utf-8 > status
	fi

	# Deconnexion de l'alarme
	logout_alarme
	
	# Récupération dans les variables
	EtatZoneA="$(grep -Eoi '<zone0>.*' status)"
	EtatZoneA="$(echo "${EtatZoneA:7:-9}")"
	EtatZoneB="$(grep -Eoi '<zone1>.*' status)"
	EtatZoneB="$(echo "${EtatZoneB:7:-9}")"
	EtatZoneC="$(grep -Eoi '<zone2>.*' status)"
	EtatZoneC="$(echo "${EtatZoneC:7:-9}")"

	EtatPiles="$(grep -Eoi '<defaut0>.*' status)"
	EtatPiles="$(echo "${EtatPiles:9:-11}")"
	EtatRadio="$(grep -Eoi '<defaut1>.*' status)"
	EtatRadio="$(echo "${EtatRadio:9:-11}")"
	EtatPorte="$(grep -Eoi '<defaut2>.*' status)"
	EtatPorte="$(echo "${EtatPorte:9:-11}")"
	EtatAlarme="$(grep -Eoi '<defaut3>.*' status)"
	EtatAlarme="$(echo "${EtatAlarme:9:-11}")"
	EtatBoitier="$(grep -Eoi '<defaut4>.*' status)"
	EtatBoitier="$(echo "${EtatBoitier:9:-11}")"

	EtatGSM="$(grep -Eoi '<gsm>.*' status)"
	EtatGSM="$(echo "${EtatGSM:5:-7}")"
	SignalGSM="$(grep -Eoi '<recgsm>.*' status)"
	SignalGSM="$(echo "${SignalGSM:8:-10}")"
	OperateurGSM="$(grep -Eoi '<opegsm>.*' status)"
	OperateurGSM="$(echo "${OperateurGSM:9:-10}")"
		
	EtatCamera="$(grep -Eoi '<camera>.*' status)"
	EtatCamera="$(echo "${EtatCamera:8:-10}")"
	
	if [ "$Debug" = "True" ]; then
		# Statusoverzicht
		echo " ******************************************* "
		echo "  Status van het systeem"
		echo " ******************************************* "
		echo " Zone A                   = "$EtatZoneA
		echo " Zone B                   = "$EtatZoneB
		echo " Zone C                   = "$EtatZoneC
		echo ""
		echo " Status Batterijen	= "$EtatPiles
		echo " Status communicatie 	= "$EtatRadio
		echo " Status Ramen/Deuren	= "$EtatPorte
		echo " Status Alarm		= "$EtatAlarme
		echo " Status Behuizing		= "$EtatBoitier
		echo ""
		echo " Status GSM      	        = "$EtatGSM
		echo " Signal GSM               = "$SignalGSM
		echo " GSM Provider		= "$OperateurGSM
		echo ""
		echo " Status Camera		= "$EtatCamera
	fi
	
	# Mise à jour capteurs Domoticz
	if [ "$Debug" = "True" ]; then
		echo " Mise à jour capteurs Domoticz"
	fi

	# Zone A
	if [ "$EtatZoneA" = "off" ]; then
		maj_capteur ZoneA Off $AlarmeSomfyZoneAIdx
	else
		maj_capteur ZoneA On $AlarmeSomfyZoneAIdx
	fi

	# Zone B
	if [ "$EtatZoneB" = "off" ]; then
		maj_capteur ZoneB Off $AlarmeSomfyZoneBIdx
	else
		maj_capteur ZoneB On $AlarmeSomfyZoneBIdx
	fi

	# Zone C
	if [ "$EtatZoneC" = "off" ]; then
		maj_capteur ZoneC Off $AlarmeSomfyZoneCIdx
	else
		maj_capteur ZoneC On $AlarmeSomfyZoneCIdx
	fi

	# Status Batterijen
	if [ "$EtatPiles" = "ok" ]; then
		maj_capteur Piles On $AlarmeSomfyPilesIdx
	else
		maj_capteur Piles Off $AlarmeSomfyPilesIdx
	fi

	# Status Communicatie
	if [ "$EtatRadio" = "ok" ]; then
		maj_capteur Radio On $AlarmeSomfyRadioIdx
	else
		maj_capteur Radio Off $AlarmeSomfyRadioIdx
	fi

	# Status Ramen/Deuren
	if [ "$EtatPorte" = "ok" ]; then
		maj_capteur Porte/Fenetre Off $AlarmeSomfyPorteIdx
	else
		maj_capteur Porte/Fenetre On $AlarmeSomfyPorteIdx
	fi

	# Status Alarm
	if [ "$EtatAlarme" = "ok" ]; then
		maj_capteur Alarme Off $AlarmeSomfyAlarmeIdx
	else
		maj_capteur Alarme On $AlarmeSomfyAlarmeIdx
	fi

	# Status Behuizing
	if [ "$EtatBoitier" = "ok" ]; then
		maj_capteur Boitier Off $AlarmeSomfyBoitierIdx
	else
		maj_capteur Boitier On $AlarmeSomfyBoitierIdx
	fi

	# Status GSM
	if [ "$EtatGSM" = "GSM connecté au réseau" ]; then
		maj_capteur GSM On $AlarmeSomfyGSMIdx
	else
		maj_capteur GSM Off $AlarmeSomfyGSMIdx
	fi
	
	# GSM Signaal
	if [ "$Debug" = "True" ]; then
		echo " Niveau Signal GSM"
		curl "http://$SrvDomoticzIp/json.htm?type=command&param=udevice&idx=$AlarmeSomfySignalGSMIdx&nvalue=0&svalue=$SignalGSM"
	else
		curl -s "http://$SrvDomoticzIp/json.htm?type=command&param=udevice&idx=$AlarmeSomfySignalGSMIdx&nvalue=0&svalue=$SignalGSM" > /dev/null
	fi
		
	# GSM Provider
	if [ "$Debug" = "True" ]; then
		echo " Opérateur GSM"
		curl "http://$SrvDomoticzIp/json.htm?type=command&param=udevice&idx=$AlarmeSomfyOperateurGSMIdx&nvalue=0&svalue=$OperateurGSM"
	else
		curl -s "http://$SrvDomoticzIp/json.htm?type=command&param=udevice&idx=$AlarmeSomfyOperateurGSMIdx&nvalue=0&svalue=$OperateurGSM" > /dev/null
	fi	

	# Camera
	#if [ "$EtatCamera" = "disabled" ]; then
	#	maj_capteur Camera Off $AlarmeSomfyCameraIdx
	#else
	#	maj_capteur Camera On $AlarmeSomfyCameraIdx
	#fi
	
fi	

#----------------------------------------------------------------------------------------------------------------------
# Mise en marche de l'alarme Zones A B C
#----------------------------------------------------------------------------------------------------------------------
if [ "$ZonesABCOn" = "1" ]; then
	# Connexion à l'alarme
	login_alarme

	# Mise en marche de l'alarme Zones A B C
	if [ "$Debug" = "True" ]; then
		echo "Mise en marche de l'alarme Zones A B C"
		curl -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_ABC=Marche A B C" $UrlPilotage | iconv -f iso8859-1 -t utf-8
		#curl -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_ABC=Marche A B C" $UrlPilotage | uconv -f iso8859-1 -t utf-8
	else
		curl -s -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_ABC=Marche A B C" $UrlPilotage | iconv -f iso8859-1 -t utf-8 > /dev/null
		#curl -s -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_ABC=Marche A B C" $UrlPilotage | uconv -f iso8859-1 -t utf-8 > /dev/null
	fi

	# Deconnexion de l'alarme
	logout_alarme

	# Mise à jour capteurs Domoticz
	if [ "$Debug" = "True" ]; then
		echo " Mise à jour capteurs Domoticz"
	fi
	maj_capteur ZoneA On $AlarmeSomfyZoneAIdx
	maj_capteur ZoneB On $AlarmeSomfyZoneBIdx
	maj_capteur ZoneC On $AlarmeSomfyZoneCIdx
fi

#----------------------------------------------------------------------------------------------------------------------
# Mise en marche de l'alarme Zone A
#----------------------------------------------------------------------------------------------------------------------
if [ "$ZoneAOn" = "1" ]; then
	# Connexion à l'alarme
	login_alarme

	# Mise en marche de l'alarme Zone A
	if [ "$Debug" = "True" ]; then
		echo "Mise en marche de l'alarme Zone A"
		curl -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_A=Marche A" $UrlPilotage | iconv -f iso8859-1 -t utf-8
		#curl -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_A=Marche A" $UrlPilotage | uconv -f iso8859-1 -t utf-8
	else
		curl -s -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_A=Marche A" $UrlPilotage | iconv -f iso8859-1 -t utf-8 > /dev/null
		#curl -s -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_A=Marche A" $UrlPilotage | uconv -f iso8859-1 -t utf-8 > /dev/null
	fi

	# Deconnexion de l'alarme
	logout_alarme

	# Mise à jour capteurs Domoticz
	if [ "$Debug" = "True" ]; then
		echo " Mise à jour capteurs Domoticz"
	fi
	maj_capteur ZoneA On $AlarmeSomfyZoneAIdx
fi

#----------------------------------------------------------------------------------------------------------------------
# Mise en marche de l'alarme Zone B
#----------------------------------------------------------------------------------------------------------------------
if [ "$ZoneBOn" = "1" ]; then
	# Connexion à l'alarme
	login_alarme

	# Mise en marche de l'alarme Zone B
	if [ "$Debug" = "True" ]; then
		echo "Mise en marche de l'alarme Zone B"
		curl -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_B=Marche B" $UrlPilotage | iconv -f iso8859-1 -t utf-8
		#curl -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_B=Marche B" $UrlPilotage | uconv -f iso8859-1 -t utf-8
	else
		curl -s -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_B=Marche B" $UrlPilotage | iconv -f iso8859-1 -t utf-8 > /dev/null
		#curl -s -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_B=Marche B" $UrlPilotage | uconv -f iso8859-1 -t utf-8 > /dev/null
	fi

	# Deconnexion de l'alarme
	logout_alarme

	# Mise à jour capteurs Domoticz
	if [ "$Debug" = "True" ]; then
		echo " Mise à jour capteurs Domoticz"
	fi
	maj_capteur ZoneB On $AlarmeSomfyZoneBIdx
fi

#----------------------------------------------------------------------------------------------------------------------
# Mise en marche de l'alarme Zone C
#----------------------------------------------------------------------------------------------------------------------
if [ "$ZoneCOn" = "1" ]; then
	# Connexion à l'alarme
	login_alarme

	# Mise en marche de l'alarme Zone C
	if [ "$Debug" = "True" ]; then
		echo "Mise en marche de l'alarme Zone C"
		curl -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_C=Marche C" $UrlPilotage | iconv -f iso8859-1 -t utf-8
		#curl -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_C=Marche C" $UrlPilotage | uconv -f iso8859-1 -t utf-8
	else
		curl -s -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_C=Marche C" $UrlPilotage | iconv -f iso8859-1 -t utf-8 > /dev/null
		#curl -s -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&hidden=hidden&btn_zone_on_C=Marche C" $UrlPilotage | uconv -f iso8859-1 -t utf-8 > /dev/null
	fi

	# Deconnexion de l'alarme
	logout_alarme

	# Mise à jour capteurs Domoticz
	if [ "$Debug" = "True" ]; then
		echo " Mise à jour capteurs Domoticz"
	fi
	maj_capteur ZoneC On $AlarmeSomfyZoneCIdx
fi

#----------------------------------------------------------------------------------------------------------------------
# Arret de l'alarme Zones A B C
#----------------------------------------------------------------------------------------------------------------------
if [ "$AlarmeOff" = "1" ]; then
	# Connexion à l'alarme
	login_alarme

	# Arret de l'alarme Zones A B C
	if [ "$Debug" = "True" ]; then
		echo "Arret de l'alarme Zones A B C"
		curl -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&btn_zone_off_ABC=Arret A B C" $UrlPilotage | iconv -f iso8859-1 -t utf-8
		#curl -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&btn_zone_off_ABC=Arret A B C" $UrlPilotage | uconv -f iso8859-1 -t utf-8
	else
		curl -s -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&btn_zone_off_ABC=Arret A B C" $UrlPilotage | iconv -f iso8859-1 -t utf-8 > /dev/null
		#curl -s -L --cookie cjar --cookie-jar cjar --data "hidden=hidden&btn_zone_off_ABC=Arret A B C" $UrlPilotage | uconv -f iso8859-1 -t utf-8 > /dev/null
	fi

	# Deconnexion de l'alarme
	logout_alarme
	
	# Mise à jour capteurs Domoticz
	if [ "$Debug" = "True" ]; then
		echo " Mise à jour capteurs Domoticz"
	fi
	maj_capteur ZoneA Off $AlarmeSomfyZoneAIdx
	maj_capteur ZoneB Off $AlarmeSomfyZoneBIdx
	maj_capteur ZoneC Off $AlarmeSomfyZoneCIdx
fi

#----------------------------------------------------------------------------------------------------------------------
# Reset defauts piles
#----------------------------------------------------------------------------------------------------------------------
if [ "$RSTPiles" = "1" ]; then
	# Connexion à l'alarme
	login_alarme

	# Reset defauts piles
	if [ "$Debug" = "True" ]; then
		echo "Reset defauts piles"
		curl -L --cookie cjar --cookie-jar cjar --data "btn_del_pil=Piles" $UrlElements | iconv -f iso8859-1 -t utf-8
		#curl -L --cookie cjar --cookie-jar cjar --data "btn_del_pil=Piles" $UrlElements | uconv -f iso8859-1 -t utf-8
	else
		curl -s -L --cookie cjar --cookie-jar cjar --data "btn_del_pil=Piles" $UrlElements | iconv -f iso8859-1 -t utf-8 > /dev/null
		#curl -s -L --cookie cjar --cookie-jar cjar --data "btn_del_pil=Piles" $UrlElements | uconv -f iso8859-1 -t utf-8 > /dev/null
	fi

	# Deconnexion de l'alarme
	logout_alarme
fi

#----------------------------------------------------------------------------------------------------------------------
# Reset defauts alarmes
#----------------------------------------------------------------------------------------------------------------------
if [ "$RSTAlarmes" = "1" ]; then
	# Connexion à l'alarme
	login_alarme

	# Reset defauts alarmes
	if [ "$Debug" = "True" ]; then
		echo "Reset defauts alarmes"
		curl -L --cookie cjar --cookie-jar cjar --data "btn_del_alm=Alarmes" $UrlElements | iconv -f iso8859-1 -t utf-8
		#curl -L --cookie cjar --cookie-jar cjar --data "btn_del_alm=Alarmes" $UrlElements | uconv -f iso8859-1 -t utf-8
	else
		curl -s -L --cookie cjar --cookie-jar cjar --data "btn_del_alm=Alarmes" $UrlElements | iconv -f iso8859-1 -t utf-8 > /dev/null
		#curl -s -L --cookie cjar --cookie-jar cjar --data "btn_del_alm=Alarmes" $UrlElements | uconv -f iso8859-1 -t utf-8 > /dev/null
	fi

	# Deconnexion de l'alarme
	logout_alarme
fi

#----------------------------------------------------------------------------------------------------------------------
# Reset defauts liaisons
#----------------------------------------------------------------------------------------------------------------------
if [ "$RSTLiaisons" = "1" ]; then
	# Connexion à l'alarme
	login_alarme

	# Reset defauts liaisons
	if [ "$Debug" = "True" ]; then
		echo "Reset defauts liaisons"
		curl -L --cookie cjar --cookie-jar cjar --data "btn_del_lia=Liaisons" $UrlElements | iconv -f iso8859-1 -t utf-8
		#curl -L --cookie cjar --cookie-jar cjar --data "btn_del_lia=Liaisons" $UrlElements | uconv -f iso8859-1 -t utf-8
	else
		curl -s -L --cookie cjar --cookie-jar cjar --data "btn_del_lia=Liaisons" $UrlElements | iconv -f iso8859-1 -t utf-8 > /dev/null
		#curl -s -L --cookie cjar --cookie-jar cjar --data "btn_del_lia=Liaisons" $UrlElements | uconv -f iso8859-1 -t utf-8 > /dev/null
	fi

	# Deconnexion de l'alarme
	logout_alarme
fi

#----------------------------------------------------------------------------------------------------------------------
# Gestion de la liste des Elements
#----------------------------------------------------------------------------------------------------------------------
if [ "$Elements" = "1" ]; then
	# Connexion à l'alarme
	login_alarme

	# Lecture de la liste des Elements et stockage dans fichier temporaire
	if [ "$Debug" = "True" ]; then
		echo "Gestion liste des Elements"
		curl -L --cookie cjar --cookie-jar cjar $UrlElements | iconv -f iso8859-1 -t utf-8 > elements
		#curl -L --cookie cjar --cookie-jar cjar $UrlElements | uconv -f iso8859-1 -t utf-8 > elements
	else
		curl -s -L --cookie cjar --cookie-jar cjar $UrlElements | iconv -f iso8859-1 -t utf-8 > elements
		#curl -s -L --cookie cjar --cookie-jar cjar $UrlElements | uconv -f iso8859-1 -t utf-8 > elements
	fi

	# Deconnexion de l'alarme
	logout_alarme
	
	# Récupération dans les variables
	TypeElements="$(grep -Eoi 'var item_label.*' elements)"
	NomElements="$(grep -Eoi 'var elt_name.*' elements)"
	EtatElements="$(grep -Eoi 'var item_pause.*' elements)"
	EtatPiles="$(grep -Eoi 'var elt_pile.*' elements)"
	EtatLiaison="$(grep -Eoi 'var elt_onde.*' elements)"
	EtatPortes="$(grep -Eoi 'var elt_porte.*' elements)"
	EtatBoitiers="$(grep -Eoi 'var elt_as.*' elements)"
	EtatAlarme="$(grep -Eoi 'var elt_maison.*' elements)"

	# Affichage des Elements
	if [ "$Debug" = "True" ]; then
		echo " Type des Elements"
		echo $TypeElements
		echo " Nom des Elements"
		echo $NomElements
		echo " Etat des Elements"
		echo $EtatElements
		echo " Etat des piles"
		echo $EtatPiles
		echo " Etat liaison radio"
		echo $EtatLiaison
		echo " Etat détecteurs ouverture"
		echo $EtatPortes
		echo " Etat ouverture boitiers"
		echo $EtatBoitiers
		echo " Etat alarme"
		echo $EtatAlarme
	fi
		
	# Formatage du type des Elements	
	# Suppression des 21 1er caractères et 2 derniers
	TypeElements="$(echo "${TypeElements:21:-2}")"
	# Suppression des "
	TypeElements="$(echo "$TypeElements" | sed s/\"//g)"
	# Suppression des espaces entre les ,
	TypeElements="$(echo "$TypeElements" | sed s/\,\ /\,/g)"
	# Déclaration , comme séparateur
	IFS=","
	# Stockage dans le tableau
	TabTypeElements=($TypeElements)

	# Formatage des noms des Elements
	# Suppression des 21 1er caractères et 2 derniers
	NomElements="$(echo "${NomElements:21:-2}")"
	# Suppression des "
	NomElements="$(echo "$NomElements" | sed s/\"//g)"
	# Suppression des espaces entre les ,
	NomElements="$(echo "$NomElements" | sed s/\,\ /\,/g)"
	# Déclaration , comme séparateur
	IFS=","
	# Stockage dans le tableau
	TabNomElements=($NomElements)
		
	# Formatage état des Elements
	# Suppression des 21 1er caractères et 2 derniers
	EtatElements="$(echo "${EtatElements:21:-2}")"
	# Suppression des "
	EtatElements="$(echo "$EtatElements" | sed s/\"//g)"
	# Suppression des espaces entre les ,
	EtatElements="$(echo "$EtatElements" | sed s/\,\ /\,/g)"
	# Déclaration , comme séparateur
	IFS=","
	# Stockage dans le tableau
	TabEtatElements=($EtatElements)
	# Modification valeurs tableau
	TailleTab=${#TabEtatElements[@]}
	for (( i=0; i<$TailleTab; i++ ))
	do
		if [ ${TabEtatElements["$i"]} = "running" ]; then TabEtatElements["$i"]="Activé"
		else
			TabEtatElements["$i"]="Désactivé"
		fi
	done

	# Formatage état des piles
	# Suppression des 21 1er caractères et 2 derniers
	EtatPiles="$(echo "${EtatPiles:21:-2}")"
	# Suppression des "
	EtatPiles="$(echo "$EtatPiles" | sed s/\"//g)"
	# Suppression des espaces entre les ,
	EtatPiles="$(echo "$EtatPiles" | sed s/\,\ /\,/g)"
	# Déclaration , comme séparateur
	IFS=","
	# Stockage dans le tableau
	TabEtatPiles=($EtatPiles)
	# Modification des valeurs du tableau
	TailleTab=${#TabEtatPiles[@]}
	for (( i=0; i<$TailleTab; i++ ))
	do
		if [ ${TabEtatPiles["$i"]} = "itemhidden" ]; then TabEtatPiles["$i"]="NA"
		else
			if [ ${TabEtatPiles["$i"]} = "itembattok" ]; then TabEtatPiles["$i"]="OK"
			else
				TabEtatPiles["$i"]="NOK"
			fi
		fi
	done

	# Formatage état liaison radio
	# Suppression des 21 1er caractères et 2 derniers
	EtatLiaison="$(echo "${EtatLiaison:21:-2}")"
	# Suppression des "
	EtatLiaison="$(echo "$EtatLiaison" | sed s/\"//g)"
	# Suppression des espaces entre les ,
	EtatLiaison="$(echo "$EtatLiaison" | sed s/\,\ /\,/g)"
	# Déclaration , comme séparateur
	IFS=","
	# Stockage dans le tableau
	TabEtatLiaison=($EtatLiaison)
	# Modification des valeurs du tableau
	TailleTab=${#TabEtatLiaison[@]}
	for (( i=0; i<$TailleTab; i++ ))
	do
		if [ ${TabEtatLiaison["$i"]} = "itemhidden" ]; then TabEtatLiaison["$i"]="NA"
		else
			if [ ${TabEtatLiaison["$i"]} = "itemcomok" ]; then TabEtatLiaison["$i"]="OK"
			else
				TabEtatLiaison["$i"]="NOK"
			fi
		fi
	done
		
	# Récup état détecteurs ouverture
	# Suppression des 21 1er caractères et 2 derniers
	EtatPortes="$(echo "${EtatPortes:21:-2}")"
	# Suppression des "
	EtatPortes="$(echo "$EtatPortes" | sed s/\"//g)"
	# Suppression des espaces entre les ,
	EtatPortes="$(echo "$EtatPortes" | sed s/\,\ /\,/g)"
	# Déclaration , comme séparateur
	IFS=","
	# Stockage dans le tableau
	TabEtatPortes=($EtatPortes)
	# Modification des valeurs du tableau
	TailleTab=${#TabEtatPortes[@]}
	for (( i=0; i<$TailleTab; i++ ))
	do
		if [ ${TabEtatPortes["$i"]} = "itemhidden" ]; then TabEtatPortes["$i"]="NA"
		else
			if [ ${TabEtatPortes["$i"]} = "itemdoorok" ]; then TabEtatPortes["$i"]="Fermée"
			else
				TabEtatPortes["$i"]="Ouverte"
			fi
		fi
	done
		
	# Récup état ouverture boitiers
	# Suppression des 21 1er caractères et 2 derniers
	EtatBoitiers="$(echo "${EtatBoitiers:21:-2}")"
	# Suppression des "
	EtatBoitiers="$(echo "$EtatBoitiers" | sed s/\"//g)"
	# Suppression des espaces entre les ,
	EtatBoitiers="$(echo "$EtatBoitiers" | sed s/\,\ /\,/g)"
	# Déclaration , comme séparateur
	IFS=","
	# Stockage dans le tableau
	TabEtatBoitiers=($EtatBoitiers)
	# Modification des valeurs du tableau
	TailleTab=${#TabEtatBoitiers[@]}
	for (( i=0; i<$TailleTab; i++ ))
	do
		if [ ${TabEtatBoitiers["$i"]} = "itemhidden" ]; then TabEtatBoitiers["$i"]="NA"
		else
			if [ ${TabEtatBoitiers["$i"]} = "itemboxok" ]; then TabEtatBoitiers["$i"]="Fermé"
			else
				TabEtatBoitiers["$i"]="Ouvert"
			fi
		fi
	done
		
	# Récup état alarme
	# Suppression des 21 1er caractères et 2 derniers
	EtatAlarme="$(echo "${EtatAlarme:21:-2}")"
	# Suppression des "
	EtatAlarme="$(echo "$EtatAlarme" | sed s/\"//g)"
	# Suppression des espaces entre les ,
	EtatAlarme="$(echo "$EtatAlarme" | sed s/\,\ /\,/g)"
	# Déclaration , comme séparateur
	IFS=","
	# Stockage dans le tableau
	TabEtatAlarme=($EtatAlarme)
	# Modification des valeurs du tableau
	TailleTab=${#TabEtatAlarme[@]}
	for (( i=0; i<$TailleTab; i++ ))
	do
		if [ ${TabEtatAlarme["$i"]} = "itemhouseok" ]; then TabEtatAlarme["$i"]="Pas d'alarme"
		else
			TabEtatAlarme["$i"]="Alarme"
		fi
	done
		
	# Affichage de la liste des Elements
	if [ "$Debug" = "True" ]; then
		echo " Liste des Elements"
		TailleTab=${#TabNomElements[@]}
		for (( i=0; i<$TailleTab; i++ ))
		do
			echo " Type : "${TabTypeElements["$i"]} "/ Nom : "${TabNomElements["$i"]} "/ Etat : "${TabEtatElements["$i"]} "/ Etat piles : "${TabEtatPiles["$i"]} "/ Etat liaison : "${TabEtatLiaison["$i"]} "/ Etat portes : "${TabEtatPortes["$i"]} "/ Etat boitiers : "${TabEtatBoitiers["$i"]} "/ Etat alarme : "${TabEtatAlarme["$i"]}
		done	
	fi
	
	# Mise à jour capteurs Domoticz
	if [ "$Debug" = "True" ]; then
		echo " Mise à jour capteurs Domoticz"
	fi

	# DO Entré
	TailleTab=${#TabNomElements[@]}
	for (( i=0; i<$TailleTab; i++ ))
	do
		if [ ${TabNomElements["$i"]} = "DO Entree" ]; then PosElement=$i
		fi
	done
	if [ ${TabEtatPortes["$PosElement"]} = "Fermée" ]; then
		maj_capteur DOEntrée Off $AlarmeSomfyDOEntreeIdx
	else
		maj_capteur DOEntrée On $AlarmeSomfyDOEntreeIdx
	fi
	
	# DO Couloir
	for (( i=0; i<$TailleTab; i++ ))
	do
		if [ ${TabNomElements["$i"]} = "DO Couloir" ]; then PosElement=$i
		fi
	done
	if [ ${TabEtatPortes["$PosElement"]} = "Fermée" ]; then
		maj_capteur DOAtelier Off $AlarmeSomfyDOAtelierIdx
	else
		maj_capteur DOAtelier On $AlarmeSomfyDOAtelierIdx
	fi
	
fi

exit 0
To be sure; tried the un-altered Original from the forum; same reaction.
clumpton
Posts: 31
Joined: Saturday 18 January 2020 13:17
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: France
Contact:

Re: Somfy Alarm Script

Post by clumpton »

Just to be sure that you are editing and executing the same script file just add

Code: Select all

echo "Starting script in file: "$0
as the second line in your file.

It should then print out Starting script in file: your_filename. If it doesn't then you may well be editing (or running) the wrong file.
MikeyMan
Posts: 237
Joined: Wednesday 17 October 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Somfy Alarm Script

Post by MikeyMan »

I'm fairly sure i have the right document:

Code: Select all

pi@raspberrypi:~/domoticz/scripts $ dir
backup.sh                   logrotate             somfy.sh
buienradar_rain_example.pl  lua                   templates
domoticz.conf               lua_parsers           test.sh
_domoticz_main              meterstand_water.txt  update_domoticz
_domoticz_main.bat          python                watermeter.py
download_update.sh          readme.txt
dzVents                     restart_domoticz
but for the fun of it:

Code: Select all

pi@raspberrypi:~/domoticz/scripts $ ./somfy.sh
Starting script in file: ./somfy.sh
Its literally the only thing that happens
clumpton
Posts: 31
Joined: Saturday 18 January 2020 13:17
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: France
Contact:

Re: Somfy Alarm Script

Post by clumpton »

OK so it looks like it is actually running correctly from the command line, try

Code: Select all

./somfy.sh --help
You should get the list of commands (in French)

Note that your Somfy server address of 10.0.0.0 looks incorrect, generally IPs do not end in 0.

Coming back to the original error message, I assume that it is from the Domoticz log? It would appear to indicate that Domoticz is running the script in a manner that negates the bash shebang and runs it under sh.
... After a bit of googling ...
It would appear that 'modern' Raspbian uses dash for sh, so if Domoticz runs your script using 'sh your_script_file' it will run under the dash interpreter. Running it like this overrides the shebang in the file. The dash shell does not support the 'declare' function that is causing your problem.
The easy way out (which hopefully shouldn't break anything) is to replace dash with bash as the actual sh interpreter.
You can do this (for all users) by:

Code: Select all

sudo dpkg-reconfigure dash
This will show you a message asking if you want to use dash as the default system shell, answer NO.
You should then see:

Code: Select all

Removing 'diversion of /bin/sh to /bin/sh.distrib by dash'
Adding 'diversion of /bin/sh to /bin/sh.distrib by bash'
Removing 'diversion of /usr/share/man/man1/sh.1.gz to /usr/share/man/man1/sh.distrib.1.gz by dash'
Adding 'diversion of /usr/share/man/man1/sh.1.gz to /usr/share/man/man1/sh.distrib.1.gz by bash'
If it now works I can help you with translating the French.
MikeyMan
Posts: 237
Joined: Wednesday 17 October 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Somfy Alarm Script

Post by MikeyMan »

I'll get on it this evening. Thank you very much for your help.
Just wondering, is code in french actually different?

About the ip address: i changed it before posting here. It's actually 10.0.0.112.
But i would expect an error for that if that was the case?

The error message came from the command line. Haven't been able to have Domoticz do anything yet.
clumpton
Posts: 31
Joined: Saturday 18 January 2020 13:17
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: France
Contact:

Re: Somfy Alarm Script

Post by clumpton »

MikeyMan wrote: Thursday 06 February 2020 10:49 I'll get on it this evening. Thank you very much for your help.
Just wondering, is code in french actually different?
Nope, just the names of some variables might be hard to understand for non--French. :roll:
About the ip address: i changed it before posting here. It's actually 10.0.0.112.
But i would expect an error for that if that was the case?
Yes most probably, however I think the error checking in the script is not overly complex and relies more on operations timing out.
The error message came from the command line. Haven't been able to have Domoticz do anything yet.
Just FYI here's the --help translated.

Code: Select all

Script Domoticz Alarme Somfy Protexion 5000
        --help or -h            Help menu
        --Status                Reports on system state
        --Elements              Lists elements (units?)
        --ZoneAOn               Turn on alarm Zone A
        --ZoneBOn               Turn on alarm Zone B
        --ZoneCOn               Turn on alarm Zone C
        --ZonesABCOn            Turn on alarm Zones A B C
        --AlarmeOff             Turn off alarm Zones A B C
        --RSTPiles              Reset battery fail
        --RSTAlarmes            Reset alarm fails
        --RSTLiaisons           Reset link fails
MikeyMan
Posts: 237
Joined: Wednesday 17 October 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Somfy Alarm Script

Post by MikeyMan »

./somfy.sh --help actually gives back the help file nicely.
Added your translations to be sure :)

Running the --Status script, does give me the line we added earlier:

Code: Select all

Starting script in file: ./somfy.sh
 *********************************
 Liste des URLs
 *********************************
 UrlLogin    = http://10.0.0.112/gb/login.htm
 UrlLogout   = http://10.0.0.112/logout.htm
 UrlEtat     = http://10.0.0.112/status.xml
 UrlPilotage = http://10.0.0.112/gb/u_pilotage.htm
 UrlElements = http://10.0.0.112/gb/u_listelmt.htm
 Toegangscode ophalen
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    34    0    34    0     0   3777      0 --:--:-- --:--:-- --:--:--  4250
100  2539    0  2539    0     0   9879      0 --:--:-- --:--:-- --:--:--  9879
 Code d'accès =
./somfy.sh: line 144: CarteAuthentification: bad array subscript
 Ophalen Authentificatiecode
 Authenticatiecode =
 Gebruiker1-code en verificatiecode verzenden
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    38    0     0  100    38      0   1583 --:--:-- --:--:-- --:--:--  1583
100  1592    0  1592    0     0   5271      0 --:--:-- --:--:-- --:--:-- 15762
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/x                                                 html1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <meta http-equiv="content-style-type" content="text/css" />
    <title>Central unit</title>
    <link rel="shortcut icon" href="/domis.ico" type="image/x-icon"/>
    <meta name="language" content="en" />
    <meta http-equiv="expires" content="0">
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache, must-revalidate">
<link href="/domis_welcome.css" rel="stylesheet" type="text/css" />  </head>
  <body>
    <div id="page">
      <div id="fond">
        <div id="menu">
          <div class="logohmb">&nbsp;</div>
        </div>
<div id="navbar"><div id="mode"></div></div><div id="titlebar"><div class="widet                                                 itlevoid">Error</div><div class="titlecorner"></div></div><div id="content" clas                                                 s="contentall"><br /><br /><div id="infobox">Incorrect code
 <b>(0x0B00)</b><br /><br /><form method="post" action="error.htm"><input type="                                                 submit" name="btn_ok" value="OK" class="arrowdark_short" /></form></div><div id=                                                 "content_footer">&nbsp;</div></div>         <!--content -->
        <div id="spacer">
          <!-- -->
          <!--[if IE]>&nbsp;
          <![endif]-->
        </div>
        <div id="menu_footer">
          <br />
          Copyright &copy;2013 Somfy
        </div>
      </div>
      <!-- fond -->
    </div>
    <!-- page -->
  </body>
  </html>
  Lecture de l'état du système
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   110    0   110    0     0    478      0 --:--:-- --:--:-- --:--:--   478
 Verbinden met alarm
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  2539    0  2539    0     0   9133      0 --:--:-- --:--:-- --:--:--  9133
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/x                                                 html1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <meta http-equiv="content-style-type" content="text/css" />
    <title>Central unit</title>
    <link rel="shortcut icon" href="/domis.ico" type="image/x-icon"/>
    <meta name="language" content="en" />
    <meta http-equiv="expires" content="0">
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache, must-revalidate">
<link href="/domis_welcome.css" rel="stylesheet" type="text/css" /><style type="                                                 text/css">img{border:none;};#menu a{border-bottom:none;}</style></head><body><di                                                 v id="page"><div id="fond"><div id="menu"><div class="logohmb">&nbsp;</div><div                                                  id="filler"></div></div><div id="titlebar"><div class="widetitlevoid">Welcome</d                                                 iv><div class="titlecorner"></div></div><div id="content"><div class="loginhouse                                                 ">My Somfy alarm system</div><form id="form_id" method="post" action="login.htm"                                                 ><table><col width="165px"><tr><td>Account</td><td><select name="login" class="s                                                 kinnedselectinput"> <option value="u">User1 </option><option value="i">Installer                                                  </option><option value="t">Remote mon. </option></select></td></tr><tr><td>Acce                                                 ss code</td><td><input type="password" name="password" value="" class="skinnedte                                                 xtinput" maxlength="12" size="16"/></td></tr><tr><td>Authentication code <b>F2</                                                 b></td><td><input type="password" name="key" value="" class="skinnedtextinput" m                                                 axlength="6" size="16"/></td></tr></table><div id="content_footer"><input type="                                                 submit" name="btn_login" value="Login" class="arrowdark"/></div></form></div>                                                         <!--content -->
        <div id="spacer">
          <!-- -->
          <!--[if IE]>&nbsp;
          <![endif]-->
        </div>
        <div id="menu_footerflag">
Select language:<br><br>
<a href="/gb/login.htm"><img src="/img/gb.gif" alt="gb"/></a>&nbsp;&nbsp;&nbsp;
<a href="/fr/login.htm"><img src="/img/fr.gif" alt="fr"/></a>&nbsp;&nbsp;&nbsp;
<a href="/nl/login.htm"><img src="/img/nl.gif" alt="nl"/></a><br>
<a href="/it/login.htm"><img src="/img/it.gif" alt="it"/></a>&nbsp;&nbsp;&nbsp;
<a href="/de/login.htm"><img src="/img/de.gif" alt="de"/></a>&nbsp;&nbsp;&nbsp;
<a href="/sp/login.htm"><img src="/img/sp.gif" alt="sp"/></a><br>
          Copyright &copy;2013 Somfy
        </div>
      </div>
      <!-- fond -->
    </div>
    <!-- page -->
  </body>
  </html>
  *******************************************
  Status van het systeem
 *******************************************
 Zone A                   =
 Zone B                   =
 Zone C                   =

 Status Batterijen      =
 Status communicatie    =
 Status Ramen/Deuren    =
 Status Alarm           =
 Status Behuizing               =

 Status GSM                     =
 Signal GSM               =
 GSM Provider           =

 Status Camera          =
 Mise à jour capteurs Domoticz
 Staat ZoneA
{
        "status" : "OK",
        "title" : "SwitchLight"
}
 Staat ZoneB
{
        "status" : "OK",
        "title" : "SwitchLight"
}
 Staat ZoneC
{
        "status" : "OK",
        "title" : "SwitchLight"
}
 Staat Piles
{
        "status" : "OK",
        "title" : "SwitchLight"
}
 Staat Radio
{
        "status" : "OK",
        "title" : "SwitchLight"
}
 Staat Porte/Fenetre
{
        "status" : "OK",
        "title" : "SwitchLight"
}
 Staat Alarme
{
        "status" : "OK",
        "title" : "SwitchLight"
}
 Staat Boitier
{
        "status" : "OK",
        "title" : "SwitchLight"
}
 Staat GSM
{
        "status" : "OK",
        "title" : "SwitchLight"
}
 Niveau Signal GSM
{
        "status" : "OK",
        "title" : "Update Device"
}
 Opérateur GSM
{
        "status" : "OK",
        "title" : "Update Device"
}
but then; Domoticz does see that the devices did something; last update is at 2020-02-06 14:24:44 for the Somfy devices...
One time thing though, next time running it; again nothing :(
MikeyMan
Posts: 237
Joined: Wednesday 17 October 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Somfy Alarm Script

Post by MikeyMan »

Hmm… i do see an issue in the code above: Bad array subscript.
And i see that the last update time is keeping up with time now…

Somehow my log in domoticz is now filled with:
2020-02-06 14:57:27.308 Status: User: Admin initiated a switch command (15/Zone A/Off)
2020-02-06 14:57:27.356 Status: User: Admin initiated a switch command (16/Zone B/Off)
2020-02-06 14:57:27.401 Status: User: Admin initiated a switch command (17/Zone C/Off)
2020-02-06 14:57:27.474 Status: Executing script: /home/pi/domoticz/scripts/somfy.sh

Fixed that by disabling the button. Gets in some kind of loop after pressing...
clumpton
Posts: 31
Joined: Saturday 18 January 2020 13:17
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: France
Contact:

Re: Somfy Alarm Script

Post by clumpton »

Glad that something's happening now!
Since I don't have a Somfy alarm (only their roller shutters) I'm going to have to step back a bit. If you need any help with the French thread dealing with this, let me know.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest