Voici le tuto complet :
Attention : ce script fonctionne pour Freebox V6. Si vous avez une Freebox V5, voir à la fin de ce tuto pour l'adaptation.
1) se connecter au Raspberry ou votre serveur domoticz, créer un répertoire dédié pour les scripts pour la freebox :
Code : Tout sélectionner
pi@raspberrypi ~ $ pwd
/home/pi
pi@raspberrypi ~ $ mkdir freebox
pi@raspberrypi ~ $ cd freebox
2) Télécharger le script api freebox (remerciements pour l'info à Deennoo !) :
Code : Tout sélectionner
curl -L http://github.com/JrCs/freeboxos-bash-api/raw/master/freeboxos_bash_api.sh > freeboxos_bash_api.sh
chmod +x freeboxos_bash_api.sh
3) Obtenir un token d'autorisation auprès de votre freebox. C'est ce qui vous permettra de l'interroger par la suite :
Code : Tout sélectionner
$ source ./freeboxos_bash_api.sh
$ authorize_application 'Domoticz.app' 'Domoticz App' '1.0.0' 'Raspberry PI'
Please grant/deny access to the app on the Freebox LCD...
[IL FAUT ALORS APPUYER SUR LE BOUTON FLECHE DROITE SUR LA FREEBOX !!!]
Authorization granted
Modifier alors les valeurs suivantes dans le script avec celles fournies par VOTRE Freebox :
Code : Tout sélectionner
MY_APP_ID="Domoticz.app"
MY_APP_TOKEN="4uZTLMMwSyiPB42tSCWLpSSZbXIYi+d+F32tVMx2j1p8oSUUk4Awr/OMZne4RRlY"
4) Récupérer mon script que voici et le copier dans un fichier freebox_infos.sh
Code : Tout sélectionner
#!/bin/bash
cd /home/pi/freebox
# Domoticz server
DOMOTICZ_SERVER="192.168.1.2:8080"
# Freebox Server idx
FREEBOX_FW_IDX="87"
FREEBOX_UPTIME_IDX="88"
FREEBOX_UP_MAX_IDX="89"
FREEBOX_DOWN_MAX_IDX="90"
FREEBOX_DISKSPACE_IDX="91"
# Password admin domoticz à modifier
pwd=toto
#
function show_time () {
num=$1
min=0
hour=0
day=0
if((num>59));then
((sec=num%60))
((num=num/60))
if((num>59));then
((min=num%60))
((num=num/60))
if((num>23));then
((hour=num%24))
((day=num/24))
else
((hour=num))
fi
else
((min=num))
fi
else
((sec=num))
fi
echo "$day"%20jours%20"$hour"%20heures%20"$min"%20mn%20"$sec"%20secs
}
MY_APP_ID="Domoticz.app"
MY_APP_TOKEN="W8dtsufQ300DqFlls6kNdUxDJyyflr+uoX4ZHCqpzqz2PUa0Xt1doL/z+Qgq5r2jt"
# source the freeboxos-bash-api
source ./freeboxos_bash_api.sh
# login
login_freebox "$MY_APP_ID" "$MY_APP_TOKEN"
# get xDSL data
answer=$(call_freebox_api '/connection/xdsl')
#echo " answer : ${answer} "
#echo " "
# extract max upload xDSL rate
up_max_rate=$(get_json_value_for_key "$answer" 'result.up.maxrate')
up_max_rate=$(awk "BEGIN {printf \"%.1f\",${up_max_rate}/1024}")
up_max_rate=$(echo "$up_max_rate%20Mb/s")
down_max_rate=$(get_json_value_for_key "$answer" 'result.down.maxrate')
down_max_rate=$(awk "BEGIN {printf \"%.1f\",${down_max_rate}/1024}")
down_max_rate=$(echo "$down_max_rate%20Mb/s")
uptime=$(get_json_value_for_key "$answer" 'result.status.uptime')
uptimefreebox=$(show_time ${uptime})
echo "Uptime : ${uptimefreebox} "
echo "Max Upload xDSL rate: ${up_max_rate} "
echo "Max Download xDSL rate: ${down_max_rate} "
answer=$(call_freebox_api '/system')
#echo " answer : ${answer} "
#uptimefreebox=$(get_json_value_for_key "$answer" 'result.uptime')
fwfreebox=$(get_json_value_for_key "$answer" 'result.firmware_version')
#echo "Uptime : ${uptimefreebox} "
echo "Firmware : ${fwfreebox} "
answer=$(call_freebox_api '/storage/disk')
answer=$(echo ${answer} | sed -e "s/\[//g" | sed -e "s/\]//g")
#echo " answer : ${answer} "
freediskspace=$(get_json_value_for_key "$answer" 'result.partitions.free_bytes')
freediskspace=$(echo $((${freediskspace}/1024/1024)))
freediskspace=$(awk "BEGIN {printf \"%.2f\",${freediskspace}/1024}")
freediskspace=$(echo "${freediskspace}%20Go")
echo "Free space HD : ${freediskspace} "
#
#Envoi des valeurs vers les devices virtuels
# Send data to Domoticz
curl --silent -s -i -H "Accept: application/json" "http://admin:toto@$DOMOTICZ_SERVER/json.htm?type=command¶m=udevice&idx=$FREEBOX_FW_IDX&nvalue=0&svalue=$fwfreebox"
curl --silent -s -i -H "Accept: application/json" "http://admin:mdp@$DOMOTICZ_SERVER/json.htm?type=command¶m=udevice&idx=$FREEBOX_UPTIME_IDX&nvalue=0&svalue=$uptimefreebox"
curl --silent -s -i -H "Accept: application/json" "http://admin:mdp@$DOMOTICZ_SERVER/json.htm?type=command¶m=udevice&idx=$FREEBOX_UP_MAX_IDX&nvalue=0&svalue=$up_max_rate"
curl --silent -s -i -H "Accept: application/json" "http://admin:mdp@$DOMOTICZ_SERVER/json.htm?type=command¶m=udevice&idx=$FREEBOX_DOWN_MAX_IDX&nvalue=0&svalue=$down_max_rate"
curl --silent -s -i -H "Accept: application/json" "http://admin:mdp@$DOMOTICZ_SERVER/json.htm?type=command¶m=udevice&idx=$FREEBOX_DISKSPACE_IDX&nvalue=0&svalue=$freediskspace"
Changer les valeurs pour :
5) Créer les 5 devices virtuels en type texte.

- 2015-07-02_185505.jpg (108.76 Kio) Consulté 20614 fois
Corriger les 5 valeurs de l'index de chacun des devices dans le script freebox_infos.sh :
Code : Tout sélectionner
FREEBOX_FW_IDX="87"
FREEBOX_UPTIME_IDX="88"
FREEBOX_UP_MAX_IDX="89"
FREEBOX_DOWN_MAX_IDX="90"
FREEBOX_DISKSPACE_IDX="91"
Modifier également le login/passwd dans les envois des données à domoticz via curl à la fin du script (après http://):
Code : Tout sélectionner
curl --silent -s -i -H "Accept: application/json" "http://admin:mdp@$DOMOTICZ_SERVER/json.htm?type=command¶m=udevice&idx=$FREEBOX_FW_IDX&nvalue=0&svalue=$fwfreebox"
curl --silent -s -i -H "Accept: application/json" "http://admin:mdp@$DOMOTICZ_SERVER/json.htm?type=command¶m=udevice&idx=$FREEBOX_UPTIME_IDX&nvalue=0&svalue=$uptimefreebox"
curl --silent -s -i -H "Accept: application/json" "http://admin:mdp@$DOMOTICZ_SERVER/json.htm?type=command¶m=udevice&idx=$FREEBOX_UP_MAX_IDX&nvalue=0&svalue=$up_max_rate"
curl --silent -s -i -H "Accept: application/json" "http://admin:mdp@$DOMOTICZ_SERVER/json.htm?type=command¶m=udevice&idx=$FREEBOX_DOWN_MAX_IDX&nvalue=0&svalue=$down_max_rate"
curl --silent -s -i -H "Accept: application/json" "http://admin:mdp@$DOMOTICZ_SERVER/json.htm?type=command¶m=udevice&idx=$FREEBOX_DISKSPACE_IDX&nvalue=0&svalue=$freediskspace"
6) Rendre le script exécutable :
7) Tester manuellement.
[/code]
pi@raspberrypi ~/freebox $ ./freebox_infos.sh
Uptime : 5%20jours%2022%20heures%2038%20mn%2034%20secs
Max Upload xDSL rate: 9392%20kb/s
Max Download xDSL rate: 37254%20kb/s
Firmware : 3.1.2
Free space HD : 70810%20MBytes
HTTP/1.1 200 OK
Content-Length: 53
Content-Type: application/json;charset=UTF-8
Cache-Control: no-cache
Pragma: no-cache
Access-Control-Allow-Origin: *
Set-Cookie: SID=c53d94da4b4ce6afa470dda84bd0d1cc.1435857371; path=/; Expires= Thu, 02 Jul 2015 17:16:11 GMT
{
"status" : "OK",
"title" : "Update Device"
}
HTTP/1.1 200 OK
Content-Length: 53
Content-Type: application/json;charset=UTF-8
Cache-Control: no-cache
Pragma: no-cache
Access-Control-Allow-Origin: *
Set-Cookie: SID=c53d94da4b4ce6afa470dda84bd0d1cc.1435857371; path=/; Expires= Thu, 02 Jul 2015 17:16:11 GMT
{
"status" : "OK",
"title" : "Update Device"
}
HTTP/1.1 200 OK
Content-Length: 53
Content-Type: application/json;charset=UTF-8
Cache-Control: no-cache
Pragma: no-cache
Access-Control-Allow-Origin: *
Set-Cookie: SID=c53d94da4b4ce6afa470dda84bd0d1cc.1435857371; path=/; Expires= Thu, 02 Jul 2015 17:16:11 GMT
{
"status" : "OK",
"title" : "Update Device"
}
HTTP/1.1 200 OK
Content-Length: 53
Content-Type: application/json;charset=UTF-8
Cache-Control: no-cache
Pragma: no-cache
Access-Control-Allow-Origin: *
Set-Cookie: SID=c53d94da4b4ce6afa470dda84bd0d1cc.1435857372; path=/; Expires= Thu, 02 Jul 2015 17:16:12 GMT
{
"status" : "OK",
"title" : "Update Device"
}
HTTP/1.1 200 OK
Content-Length: 53
Content-Type: application/json;charset=UTF-8
Cache-Control: no-cache
Pragma: no-cache
Access-Control-Allow-Origin: *
Set-Cookie: SID=c53d94da4b4ce6afa470dda84bd0d1cc.1435857372; path=/; Expires= Thu, 02 Jul 2015 17:16:12 GMT
{
"status" : "OK",
"title" : "Update Device"
}
[/code]
Si c'est OK ajouter le script dans votre crontab
Pour faire un check toutes les 10 minutes :
Et voilà !

- 2015-07-02_191603.jpg (182.95 Kio) Consulté 20614 fois
Vous remarquerez que je n'affiche que les 5 infos qui me semblent les plus pertinentes. Il y en a bien d'autres de disponible. J'ai laissé volontairement les echo $answer en commentaire. Si vous les activez, vous verrez toutes les infos disponibles ! Il suffit de créer les variables et les devices virtuels nécessaires et les associer. La liste des infos disponibles est dispo ici :
http://dev.freebox.fr/sdk/os/#api-list
NB : Si vous avez une Freebox V5, ce script ne fonctionnera pas. Il faut donc le modifier en tenant compte de la syntaxe suivante :
fratton a écrit :J'ai une Freebox Crystal (idem Freebox V5) et j'utilise ce script shell :
Code : Tout sélectionner
#!/bin/bash
DOWNLOAD=`wget -q -O - http://mafreebox.freebox.fr/pub/fbx_info.txt | grep ATM | awk '{printf $3}'`
curl -s "http://192.168.1.100:8080/json.htm?type=command¶m=udevice&idx=179&svalue="$DOWNLOAD
UPLOAD=`wget -q -O - http://mafreebox.freebox.fr/pub/fbx_info.txt | grep ATM | awk '{printf $5}'`
curl -s "http://192.168.1.100:8080/json.htm?type=command¶m=udevice&idx=180&svalue="$UPLOAD
Je reste à votre disposition en cas de besoin.
Manu
Synology DS920+ avec VM Debian 12, Aeon Labs Z-Stick Gen5, Aeon Zwave et devices zwaves , Teleinfo USB, devices Zigbee, batterie Marstek Venus E, Shelly Pro 3EM...