[Tuto] Worx : landroid et la nouvelle application
-
Hober Mallow
- Messages : 9
- Inscription : 02 oct. 2016, 21:54
-
Chrominator
- Messages : 1042
- Inscription : 19 déc. 2015, 07:29
- Localisation : France
Re: [Tuto] Worx : landroid et la nouvelle application
A mon tour, j'ai repris le script de Hober Mallow qui l'avait hérité de macben pour prendre en compte le reset qui peut être fait quand on change les lames ou la batterie.
*** ATTENTION *** J'ai aussi changé le shebang au profit de bash, plus adapté pour les calculs arithmétiques (enfin c'est mon avis).
*** ATTENTION *** J'ai aussi changé le shebang au profit de bash, plus adapté pour les calculs arithmétiques (enfin c'est mon avis).
Code : Tout sélectionner
#!/bin/bash
##########################################################################
### Script de mise a jour des statuts Tondeuse Landroid dans Domoticz ###
### 2023 04 23 ###
### ###
### 2025-10-13: Prise en compte du reset batterie et lames pour la ###
### détermination de leur durée d'utilisation ###
### ###
##########################################################################
# https://easydomoticz.com/forum/viewtopic.php?p=113303#p113303
###
### Mettre les bonnes informations ci-dessous
###### Compte WORX - Format Mail
LOGIN_WORX=xxxxxxxxxx
##########################################################################
### MdP WORX
MDP_WORX=xxxxxxxxxx
##########################################################################
### Numero de serie de la tondeuse
SERIAL_LANDROID=xxxxxxxxxxx
##########################################################################
### MAC Adresse de la tondeuse
MAC_LANDROID=xxxxxxxxxxxx
##########################################################################
### Adresse ip Domoticz
ADRESSE_IP=0.0.0.0
##########################################################################
### Adresse port Domoticz
ADRESSE_PORT=8080
##########################################################################
### Chemin du scripts, ne pas oublier de créer le répertoire shell
PATH_SCRIPT=
##########################################################################
### ID Device Domoticz - Distance parcouru - Type Dummy, Custom Sensor, Echelle Km
ID_DISTANCE=xxxx
##########################################################################
### ID Device Domoticz - Temps de Fonctionnement - Type Dummy, Custom Sensor, Echelle Heures
ID_TEMPS_TRAVAIL=xxxxx
##########################################################################
### ID Device Domoticz - Temps de Lame - Type Dummy, Custom Sensor, Echelle Heures
ID_TEMPS_LAME=xxxx
##########################################################################
### ID Device Domoticz - Nombre Cycle Batterie - Type Dummy, Compteur
ID_N_BATTERIE=xxxx
##########################################################################
### ID Device Domoticz - Tension de la Batterie - Type Dummy, Tension
ID_V_BATTERIE=xxxx
##########################################################################
### ID Device Domoticz - Temperature de la Batterie - Dummy Custom sensor, Temperature
ID_TEMP_BATTERIE=xxxx
##########################################################################
### ID Device Domoticz - Pourcentage charge de la Batterie - Dummy Custom sensor, pourcentage
ID_POURCENTAGE_BATTERIE=xxxx
##########################################################################
### ID Device Domoticz - Statut Tondeuse - Dummy Custom sensor, Alert
ID_STATUT=xxxx
##########################################################################
### ID Device Domoticz - Erreur Tondeuse - Dummy Custom sensor, Alert
ID_ERREUR=xxxx
##########################################################################
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
TOKEN=$(curl -v -X POST -d "{\"client_id\": \"150da4d2-bb44-433b-9429-3773adc70a2a\", \"grant_type\": \"password\", \"scope\": \"*\", \"client_secret\": \"nCH3A0WvMYn66vGorjSrnGZ2YtjQWDiCvjg7jNxK\", \"username\": \"$LOGIN_WORX\", \"password\":\"$MDP_WORX\"}" -H 'Content-Type: application/json' https://id.worx.com/oauth/token | jq -r '.access_token')
"landroid.sh" 178 lines, 8643 bytes
TOKEN=$(curl -v -X POST -d "{\"client_id\": \"150da4d2-bb44-433b-9429-3773adc70a2a\", \"grant_type\": \"password\", \"scope\": \"*\", \"client_secret\": \"nCH3A0WvMYn66vGorjSrnGZ2YtjQWDiCvjg7jNxK\", \"username\": \"$LOGIN_WORX\", \"password\":\"$MDP_WORX\"}" -H 'Content-Type: application/json' https://id.worx.com/oauth/token | jq -r '.access_token')
curl -X GET -H 'Accept: application/json' -H 'Content-Type: application/json' -H "Authorization: Bearer $TOKEN" "https://api.worxlandroid.com/api/v2/product-items/$SERIAL_LANDROID?status=1&mac_address=$MAC_LANDROID" > $PATH_SCRIPT/shell/worx_curl2.json
curl -X GET -H 'Accept: application/json' -H 'Content-Type: application/json' -H "Authorization: Bearer $TOKEN" https://api.worxlandroid.com/api/v2/product-items > $PATH_SCRIPT/shell/worx_curl1.json
## Distance parcourue - Type Dummy, Custom Sensor, Echelle Km
DISTANCE_COVERED=`cat $PATH_SCRIPT/shell/worx_curl1.json | jq '.[]|.distance_covered'/1000`
echo "EXEC Distance parcourue $DISTANCE_COVERED"
exec="http://${ADRESSE_IP}:${ADRESSE_PORT}/json.htm?type=command¶m=udevice&idx=${ID_DISTANCE}&svalue=${DISTANCE_COVERED}"
echo $exec
curl $exec
## Temps de Fonctionnement - Type Dummy, Custom Sensor, Echelle Heures
MOWER_WORKED=`cat $PATH_SCRIPT/shell/worx_curl1.json | jq '.[]|.mower_work_time'/60`
echo "EXEC Temps de Fonctionnement $MOWER_WORKED heures"
exec="http://${ADRESSE_IP}:${ADRESSE_PORT}/json.htm?type=command¶m=udevice&idx=${ID_TEMPS_TRAVAIL}&svalue=${MOWER_WORKED}"
echo $exec
curl $exec
## Temps de Lame - Type Dummy, Custom Sensor, Echelle Heures
BLADE_WORKED=`cat $PATH_SCRIPT/shell/worx_curl1.json | jq '.[]|.blade_work_time'`
BLADE_WORKED_RESET=`cat $PATH_SCRIPT/shell/worx_curl1.json | jq '.[]|.blade_work_time_reset'`
BLADE_WORKED=$((BLADE_WORKED - BLADE_WORKED_RESET))
BLADE_WORKED=$((BLADE_WORKED / 60))
echo "EXEC Temps de Lame $BLADE_WORKED heures"
exec="http://${ADRESSE_IP}:${ADRESSE_PORT}/json.htm?type=command¶m=udevice&idx=${ID_TEMPS_LAME}&svalue=${BLADE_WORKED}"
echo $exec
curl $exec
## Temperature de la Batterie - Dummy Custom sensor, Temperature
TEMP_BAT=`cat $PATH_SCRIPT/shell/worx_curl2.json | jq .last_status.payload.dat.bt."t"`
echo "EXEC Temperature de la Batterie $TEMP_BAT"
exec="http://${ADRESSE_IP}:${ADRESSE_PORT}/json.htm?type=command¶m=udevice&idx=${ID_TEMP_BATTERIE}&svalue=${TEMP_BAT}"
echo $exec
curl $exec
## Nombre Cycle Batterie - Type Dummy, Compteur
NB_CHARGE=`cat $PATH_SCRIPT/shell/worx_curl1.json | jq '.[]|.battery_charge_cycles'`
NB_CHARGE_RESET=`cat $PATH_SCRIPT/shell/worx_curl1.json | jq '.[]|.battery_charge_cycles_reset'`
NB_CHARGE=$((NB_CHARGE - NB_CHARGE_RESET))
echo "EXEC Nombre Cycle Batterie $NB_CHARGE"
exec="http://${ADRESSE_IP}:${ADRESSE_PORT}/json.htm?type=command¶m=udevice&idx=${ID_N_BATTERIE}&svalue=${NB_CHARGE}"
echo $exec
curl $exec
## Tension batterie, Dummy Custom sensor, Tension
TENSION_BAT=`cat $PATH_SCRIPT/shell/worx_curl2.json | jq .last_status.payload.dat.bt."v"`
echo "EXEC Tension batterie $TENSION_BAT"
exec="http://${ADRESSE_IP}:${ADRESSE_PORT}/json.htm?type=command¶m=udevice&idx=${ID_V_BATTERIE}&svalue=${TENSION_BAT}"
echo $exec
curl $exec
## Pourcentage batterie, Dummy Custom sensor, pourcentage
POURCENTAGE_BAT=`cat $PATH_SCRIPT/shell/worx_curl2.json | jq .last_status.payload.dat.bt."p"`
echo "EXEC Pourcentage batterie $POURCENTAGE_BAT"
exec="http://${ADRESSE_IP}:${ADRESSE_PORT}/json.htm?type=command¶m=udevice&idx=${ID_POURCENTAGE_BATTERIE}&svalue=${POURCENTAGE_BAT}"
echo $exec
curl $exec
## Statuts Tondeuse - Dummy Custom sensor, Alert
STATE_STATE=`cat $PATH_SCRIPT/shell/worx_curl2.json | jq '.last_status.payload.dat.ls'`
case $STATE_STATE in
0) ALERT=0;TEXT_STATE=Inactif;;
1) ALERT=1;TEXT_STATE=Maison;;
2) ALERT=1;TEXT_STATE=Démarrage;;
3) ALERT=1;TEXT_STATE=Départ%20maison;;
4) ALERT=1;TEXT_STATE=Suit%20le%20câble;;
3) ALERT=1;TEXT_STATE=Départ%20maison;;
4) ALERT=1;TEXT_STATE=Suit%20le%20câble;;
5) ALERT=2;TEXT_STATE=Recherche%20la%20base;;
6) ALERT=2;TEXT_STATE=Recherche%20le%20câble;;
7) ALERT=1;TEXT_STATE=Tonte;;
8) ALERT=4;TEXT_STATE=Soulevée;;
9) ALERT=4;TEXT_STATE=Bloquée;;
10) ALERT=4;TEXT_STATE=Lames%20bloquées;;
11) ALERT=3;TEXT_STATE=Debug;;
12) ALERT=3;TEXT_STATE=Remote%20control;;
30) ALERT=1;TEXT_STATE=Retour%20maison;;
31) ALERT=1;TEXT_STATE=Création%20zones%20tonte;;
32) ALERT=1;TEXT_STATE=Coupe%20la%20bordure;;
* ) ALERT=0;TEXT_STATE=Inconnu;;
esac
ACTUAL_TEXT_STATE=$(curl -s "http://$ADRESSE_IP:$ADRESSE_PORT/json.htm?type=devices&rid=$ID_STATUT" | grep 'Data'| cut -d'"' -f 4 | sed 's/ /%20/g' | sed 's/\\u00e9/é/' | sed 's/\\u00e2/â/')
if [ "$ACTUAL_TEXT_STATE" != "$TEXT_STATE" ]
then
exec="http://${ADRESSE_IP}:${ADRESSE_PORT}/json.htm?type=command¶m=udevice&idx=${ID_STATUT}&nvalue=${ALERT}&svalue=${TEXT_STATE}"
echo $exec
curl $exec
fi
## Erreur Tondeuse - Dummy Custom sensor, Alert
LANDROID_ERROR=`cat $PATH_SCRIPT/shell/worx_curl2.json | jq '.last_status.payload.dat.le'`
case $LANDROID_ERROR in
0) ALERT=1;TEXT_ERROR=RAS;;
1) ALERT=4;TEXT_ERROR=Bloquée;;
2) ALERT=4;TEXT_ERROR=Soulevée;;
3) ALERT=4;TEXT_ERROR=Câble%20non%20trouvé;;
4) ALERT=4;TEXT_ERROR=En%20dehors%20des%20limites;;
5) ALERT=2;TEXT_ERROR=Délai%20pluie;;
6) ALERT=3;TEXT_ERROR=Fermer%20capot%20pour%20tondre;;
7) ALERT=3;TEXT_ERROR=Fermer%20capot%20pour%20retour%20maison;;
8) ALERT=4;TEXT_ERROR=Moteur%20lames%20bloqué;;
9) ALERT=4;TEXT_ERROR=Moteur%20roues%20bloqué;;
10) ALERT=4;TEXT_ERROR=Timeout%20après%20blocage;;
11) ALERT=4;TEXT_ERROR=Renversée;;
12) ALERT=3;TEXT_ERROR=Batterie%20faible;;
13) ALERT=4;TEXT_ERROR=Câble%20inversé;;
14) ALERT=4;TEXT_ERROR=Erreur%20charge%20batterie;;
15) ALERT=4;TEXT_ERROR=Delai%20recherche%20station%20dépassé;;
* ) ALERT=0;TEXT_ERROR=Inconnu;;
esac
ACTUAL_TEXT_ERROR=$(curl -s "http://$ADRESSE_IP:$ADRESSE_PORT/json.htm?type=devices&rid=$ID_ERREUR" | grep 'Data'| cut -d'"' -f 4 | sed 's/ /%20/g'| sed 's/\\u00e9/é/' | sed 's/\\u00e2/â/')
if [ "$ACTUAL_TEXT_ERROR" != "$TEXT_ERROR" ]
then
exec="http://${ADRESSE_IP}:${ADRESSE_PORT}/json.htm?type=command¶m=udevice&idx=${ID_ERREUR}&nvalue=${ALERT}&svalue=${TEXT_ERROR}"
echo $exec
curl $exec
fi
Un bon frein vaut mieux que deux sparadraps.
Ubuntu 24.04.3 LTS - Domoticz 2025.1 (build 16782)
Pentium G3220T 2.6GHz - 4Go DDR3
RFXtrx433 USB Ver Pro1/1043
Z-Stick GEN5 Version: 1.6-1136-g07ea22bb
Rtl433 RTL-SDR receiver
RFLink Gateway
Zigbee SLZB-06
Ubuntu 24.04.3 LTS - Domoticz 2025.1 (build 16782)
Pentium G3220T 2.6GHz - 4Go DDR3
RFXtrx433 USB Ver Pro1/1043
Z-Stick GEN5 Version: 1.6-1136-g07ea22bb
Rtl433 RTL-SDR receiver
RFLink Gateway
Zigbee SLZB-06