Une solution simple pour activer ou désactiver certaines caméras via un dummy dans domoticz, pratique en complément d’un script de détection de présence !
MISE A JOUR : Version 2 disponible
Les scripts sont issus du forum synology, modifiés par mes soins car pas fonctionnels en surveillance station 7.1 (en tout cas, les scripts d’origine ne fonctionnaient pas chez moi)
Configuration côté DSM
Il faut tout d’abord créer et configurer le compte qui nous servira à contrôler les caméras. Rien de bien compliqué, juste refuser les accès à tout sauf à Surveillance Station
Puis, dans Surveillance Station, lui donner le privilège de Gestionnaire (directeur)
C’est tout pour le côté DSM 🙂
Configuration côté Domoticz
Un peu plus d’étapes et de complexité ici
Script pour l’activation
#!/bin/bash #The MIT License (MIT) # #Copyright (c) 2015 oliver.retzl #Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: #The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. # #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ########################################################################################################################################## #Scriptname: syno-enable-camera.sh #Purpose: enables cameras on surveillance station #Author: Oliver Retzl #License: https://opensource.org/licenses/MIT #Prerequisites: 1. add user directly with manager profile in surveillance station (no DSM account required) # 2. change User, Passwd, URL and cameraIds in the section below # 3. script requires GNU wget 1.16+ (run opkg update; opkg upgrade wget on your router) # 4. script requires GNU bash 4.3+ #Usage: /bin/bash <path>/syno-disable-camera.sh #References: # -Offical Synology-API: https://global.download.synology.com/download/Document/DeveloperGuide/Surveillance_Station_Web_API_v2.0.pdf # -Forumthread: http://forum.synology.com/enu/viewtopic.php?f=82&t=47074&start=15 # -Thanks to pat31 for his example-script: http://www.weblink.fr/camera-cmd ######## Configuration SYNO_SS_USER="dscamUser" SYNO_SS_PASS="VOTRE MDP" SYNO_URL="IPDISKSTATION:5000" SYNO_CAMERAIDS="1" ######### Internal variables ############ COOKIESFILE="$0-cookies-$ID" ID="$RANDOM" ###### Functions #Check HTTP Response function _cleanupCookies () { rm $COOKIESFILE } function _checkSynoResponse () { if [ $1 != '{"success":true}' ] then echo "$2 failed: "$RESPONSE _cleanupCookies exit -1 fi } ####### 1.step login VER=1 METHOD="Login" RESPONSE=`wget -q --keep-session-cookies --save-cookies $COOKIESFILE -O- "http://${SYNO_URL}/webapi/auth.cgi?api=SYNO.API.Auth&method=$METHOD&version=${VER}&account=${SYNO_SS_USER}&passwd=${SYNO_SS_PASS}&session=SurveillanceStation"` _checkSynoResponse $RESPONSE $METHOD; ######## 2.step enable camera VER=8 METHOD="Enable" #RESPONSE=`wget -q --load-cookies $COOKIESFILE -O- "http://${SYNO_URL}/webapi/SurveillanceStation/camera.cgi?api=SYNO.SurveillanceStation.Camera&method=$METHOD&version=$VER&cameraIds=$SYNO_CAMERAIDS"` # /webapi/SurveillanceStation/camera.cgi?api=SYNO.SurveillanceStation.Camera&method=Enable&version=3&cameraIds=2,10 RESPONSE=`wget -q --load-cookies $COOKIESFILE -O- "http://${SYNO_URL}/webapi/entry.cgi?api="SYNO.SurveillanceStation.Camera"&method="$METHOD"&version=$VER&cameraIds=$SYNO_CAMERAIDS"` #_checkSynoResponse $RESPONSE $METHOD; ######## 3.step logout VER=1 METHOD="Logout" RESPONSE=`wget -q --load-cookies $COOKIESFILE -O- "http://${SYNO_URL}/webapi/auth.cgi?api=SYNO.API.Auth&method=$METHOD&version=${VER}"` _checkSynoResponse $RESPONSE $METHOD; ###### Cleanup _cleanupCookies exit
Script pour la désactivation
#!/bin/bash #The MIT License (MIT) # #Copyright (c) 2015 oliver.retzl #Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: #The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. # #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ########################################################################################################################################## #Scriptname: syno-disable-cameras.sh #Purpose: disables cameras on surveillance station #Author: Oliver Retzl #License: https://opensource.org/licenses/MIT #Prerequisites: 1. add user directly with manager profile in surveillance station (no DSM account required) # 2. change User, Passwd, URL and cameraIds in the section below # 3. script requires GNU wget 1.16+ (run opkg update; opkg upgrade wget on your router) # 4. script requires GNU bash 4.3+ #Usage: /bin/bash <path>/syno-disable-camera.sh #References: # -Offical Synology-API: https://global.download.synology.com/download/Document/DeveloperGuide/Surveillance_Station_Web_API_v2.0.pdf # -Forumthread: http://forum.synology.com/enu/viewtopic.php?f=82&t=47074&start=15 # -Thanks to pat31 for his example-script: http://www.weblink.fr/camera-cmd ######## Configuration SYNO_SS_USER="dscamUser" SYNO_SS_PASS="VOTRE MDP" SYNO_URL="IPDISKSTATION:5000" SYNO_CAMERAIDS="1" ######### Internal variables ############ COOKIESFILE="$0-cookies-$ID" ID="$RANDOM" ###### Functions #Check HTTP Response function _cleanupCookies () { rm $COOKIESFILE } function _checkSynoResponse () { if [ $1 != '{"success":true}' ] then echo "$2 failed: "$RESPONSE _cleanupCookies exit -1 fi } ####### 1.step login VER=1 METHOD="Login" RESPONSE=`wget -q --keep-session-cookies --save-cookies $COOKIESFILE -O- "http://${SYNO_URL}/webapi/auth.cgi?api=SYNO.API.Auth&method=$METHOD&version=${VER}&account=${SYNO_SS_USER}&passwd=${SYNO_SS_PASS}&session=SurveillanceStation"` _checkSynoResponse $RESPONSE $METHOD; ######## 2.step disable camera VER=8 METHOD="Disable" #RESPONSE=`wget -q --load-cookies $COOKIESFILE -O- "http://${SYNO_URL}/webapi/SurveillanceStation/camera.cgi?api=SYNO.SurveillanceStation.Camera&method=$METHOD&version=$VER&cameraIds=$SYNO_CAMERAIDS"` RESPONSE=`wget -q --load-cookies $COOKIESFILE -O- "http://${SYNO_URL}/webapi/entry.cgi?api="SYNO.SurveillanceStation.Camera"&method="$METHOD"&version=$VER&cameraIds=$SYNO_CAMERAIDS"` #_checkSynoResponse $RESPONSE $METHOD; ######## 3.step logout VER=1 METHOD="Logout" RESPONSE=`wget -q --load-cookies $COOKIESFILE -O- "http://${SYNO_URL}/webapi/auth.cgi?api=SYNO.API.Auth&method=$METHOD&version=${VER}"` _checkSynoResponse $RESPONSE $METHOD; ###### Cleanup _cleanupCookies exit
Les deux scripts contiennent quelques lignes de configuration à modifier
######## Configuration SYNO_SS_USER="dscamUser" SYNO_SS_PASS="VOTRE MDP" SYNO_URL="IPDISKSTATION:5000" SYNO_CAMERAIDS="1"
Il est possible d’indiquer plusieurs caméras en séparant les IDs par une virgule : SYNO_CAMERAIDS=”1,3″ par exemple.
Ces deux fichiers sont à copier sous /home/pi/domoticz/scripts puis il faut les rendre exécutables, commande chmod +x syno-enable-cameras.sh syno-disable-cameras.sh
Vous pouvez déjà tester si cela fonctionne en lancant le script depuis le shell /home/pi/domoticz/scripts/syno-enable-cameras.sh ou /home/pi/domoticz/scripts/syno-disable-cameras.sh
Gestion dummy domoticz
Une fois ces deux scripts fonctionnels, il suffit alors de créer un dernier script (lua cette fois-ci) qui sera appelé lors du changement d’état de notre dummy.
commandArray = {} if (devicechanged['DUMMYSWITCH'] == 'On') then os.execute('bash /home/pi/domoticz/scripts/syno-enable-cameras.sh') elseif (devicechanged['DUMMYSWITCH'] == 'Off') then os.execute('bash /home/pi/domoticz/scripts/syno-disable-cameras.sh') end return commandArray
Dear Stephane, your script works but if I put cameraids”4,5″ as per my setup it doesn’t work for 5 but only for the 4…
Hello,
Wich version of surveillance station are you using ?
I have the same problem. I think the API from Synology is broken
Nouvelle version / new version : https://www.stephanerochat.ch/wordpress/2017/01/v2-gestion-cameras-synology-surveillance-station-via-un-dummy-dans-domoticz/