OBone-git / Cozytouch-domoticz

Python script for read/write data between the cozytouch server and domoticz on rpi
MIT License
17 stars 15 forks source link

refreshAllStates fails with 404 since server upgrade (24th May 2023) #50

Closed LudovicRousseau closed 1 year ago

LudovicRousseau commented 1 year ago

The server was unavailable today. The CozyTouch iOS application displayed a message. The server is now back and the iOS application can connect and display the data.

But the Python script still fails. I get:

$ ./cozytouch.py 
**** Tentative interrogation serveur Cozytouch sans login, avec cookie login précédent ****
b'GET->   https://ha110-1.overkiz.com/enduser-mobile-web/externalAPI/json/refreshAllStates   :   404'
Erreur HTTP 404 : 
!!!! Echec interrogation serveur Cozytouch sans login, connexion serveur Cozytouch ****
 POST-> https://ha110-1.overkiz.com/enduser-mobile-web/enduserAPI/login | userId=****&userPassword=**** : 200
Authentification serveur cozytouch OK
Connexion serveur Cozytouch reussie
b'GET->   https://ha110-1.overkiz.com/enduser-mobile-web/externalAPI/json/refreshAllStates   :   404'
Erreur HTTP 404 : 
Traceback (most recent call last):
  File "/Users/rousseau/Documents/github/Cozytouch-domoticz/./cozytouch.py", line 285, in <module>
    data = get_data_from_server()
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rousseau/Documents/github/Cozytouch-domoticz/./cozytouch.py", line 253, in get_data_from_server
    raise Exception("!!!! Echec requete refreshAllStates")
Exception: !!!! Echec requete refreshAllStates

It looks like the URL https://ha110-1.overkiz.com/enduser-mobile-web/externalAPI/json/refreshAllStates is not valid any more.

Tatroxitum commented 1 year ago

Hi,

I confirm, same here : GET-> https://ha110-1.overkiz.com/enduser-mobile-web/externalAPI/json/refreshAllStates : 404 Erreur HTTP 404 : !!!! Echec requete refreshAllStates

when you directly go to overkiz website : "Server is down for maintenance We are sorry for the inconvenience. Please try again in a few minutes"

=> so just wait and see.

Tatroxitum commented 1 year ago

According to somfy website also app doesn't work anymore : https://www.somfy.fr/ralentissements-des-serveurs/ralentissements-des-serveurs-box-domotiques I hope they'll find a solution soon

Aldou63 commented 1 year ago

Same thing for me today since may 24th and the new app android cozytouch 3.6.3#411 has no problem !

Tatroxitum commented 1 year ago

J'en avais marre d'attendre alors j'ai investigué les plugins cozytouch sur d'autres systèmes car le login fonctionne, c'est le refreshallstates qui foire. Il apparait que le problème n'est que sur Domoticz. Par exemple avec Jeedom leur plugin fonctionne (à quelques erreurs près sur certains paramètres suite à la mise à jour de Mai). Exemple : https://community.jeedom.com/t/radiateur-sauter-pas-de-retour-de-linfo-temp-eco/107745 (qui implique que tout le reste fonctionne au 4 juin 2023)

J'ai regardé leur code et les URL API ne sont pas identique. Sur domoticz la solution d'Obone et de Madpatrick (pour connexoon) utilisent l'adresse : https://ha110-1.overkiz.com/enduser-mobile-web/externalAPI/json/ Sur Jeedom ils utilisent l'adresse : https://ha110-1.overkiz.com/enduser-mobile-web/enduserAPI/ les fonctions ensuite appelées ne sont pas les mêmes : https://github.com/geogeocutcut/jeedom-cozytouch-plugin/blob/c5654fc0fafa214a91919da34113e6c83416f8dd/3rdparty/cozytouch/constants/CozyTouchServiceDiscovery.class.php

j'ai fait un test rapide en modifiant le script python ainsi : url_cozytouchlog=u'https://ha110-1.overkiz.com/enduser-mobile-web/enduserAPI' remplacé par url_cozytouchlog=u'https://ha110-1.overkiz.com/enduser-mobile-web/enduserAPI/'

remplacer tous les appels à cozytouch_GET(xxx) par cozytouch_GET('setup/devices')

et dans la définition de cozytouch_GET remplacer la ligne suivante : myurl=url_cozytouch+json par myurl=url_cozytouchlog+json

En activant les traces de DEBUG niveau 2 (DUMP) le dump des data reçues est bien créé. On a bien toutes les infos courantes de ce qui est connecté à la box.

Reste ensuite à faire le lien car le fichier json résultant est bien différent ! Je ne m'y connais pas en formatage de données pour les extraire donc si l'un de vous est motivé... Sinon je vais me former mais ça va prendre du temps :)

EDIT : Ok j'ai compris, j'ai fait un premier test et je récupère bien certaines données et envoi bien certaines commandes. Je vais continuer en ce sens et faire prochainement une pull request quand j'aurais fait un truc propre.

Aldou63 commented 1 year ago

Super cela marche bien ! J'avais entrepris la même démarche pour résoudre le problème. Mais je n'avais pas encore de résultat. J'utilise le script pour domoticz mais je l'ai modifié pour mon propre usage et je n'utilise pas les commandes juste les données. Donc en modifiant def JsonDecode(Num):

return data[u'setup'][u'devices'][2][u'states'][Num][u'value']

return data[2][u'states'][Num][u'value']

et aussi d'autres décodage json car j'utilise d'autres données (KW total,Status on off,mode absence...) tout est rentré dans l'ordre. Pour ce faire Visual studio code sur le fichier json dump_cozytouch est très utile. Merci pour ce post.

Tatroxitum commented 1 year ago

Depuis la maintenance de ce matin je n'arrive plus à m’authentifier, je pensais que celle-ci n'était pas finie, bon je vais aussi regarder ce point alors si toi tu arrives à te connecter j'ai du faire une erreur dans le script...

Tatroxitum commented 1 year ago

@Aldou63 tu arrives vraiment à t'authentifier en ce moment même ? Car en reprenant le fichier avant mes modifs j'ai toujours l'erreur Tentative interrogation serveur Cozytouch sans login, avec cookie login précédent GET-> https://ha110-1.overkiz.com/enduser-mobile-web/enduserAPI/setup : 401 Erreur HTTP 401 : !!!! Echec interrogation serveur Cozytouch sans login, connexion serveur Cozytouch POST-> https://ha110-1.overkiz.com/enduser-mobile-web/enduserAPI/login | userId=&userPassword=**** : 401 !!!! Echec authentification serveur cozytouch Erreur HTTP 200 : OK !!!! Echec connexion serveur Cozytouch

Aldou63 commented 1 year ago

@Tatroxitum J'ai eu une erreur d'authentification mais aussi des erreurs 429 ( too many requests) qui nécessitent une nouvelle authentification (j'ai une boucle d'interrogation de 4 mn). J'ai fait des modifs avec des tempos et je teste .

Tatroxitum commented 1 year ago

J'ai compris mon erreur, j'étais encore sur l'ancien serveur d'atlantic pour l'auth... Ils l'ont définitivement fermé. j'étais pas à jour ^^ J'ai trouvé pas mal de choses sur l'API en tâtonnant, je push dès que j'ai suffisamment poussé les tests.

Aldou63 commented 1 year ago

@Tatroxitum J'ai reporté tes dernières modifications sur mon application. Pour les data cela fonctionne parfaitement. Mais j'ai une erreur http 429 (too many requests) qui nécessite une réauthentification toute les 10 boucles environ ( période d'interrogation des données de 4mn) -------------> boucle 2023-06-14 13:00 boucle 2023-06-14 13:04 boucle 2023-06-14 13:08 Erreur Cozytouch_GET http: 429 2023-06-14 13:08 !!!! Echec interrogation serveur Cozytouch sans login, connexion serveur Cozytouch Authentification serveur cozytouch OK Connexion serveur Cozytouch reussie boucle 2023-06-14 13:12 boucle 2023-06-14 13:16 boucle 2023-06-14 13:20 boucle 2023-06-14 13:24 boucle 2023-06-14 13:28 boucle 2023-06-14 13:32 boucle 2023-06-14 13:36 boucle 2023-06-14 13:40 boucle 2023-06-14 13:44 boucle 2023-06-14 13:48 Erreur Cozytouch_GET http: 429 2023-06-14 13:48 !!!! Echec interrogation serveur Cozytouch sans login, connexion serveur Cozytouch Authentification serveur cozytouch OK Connexion serveur Cozytouch reussie boucle 2023-06-14 13:52 .............. et ainsi de suite.

Je n'ai pas testé ta version originale mais je vais le faire dés que j'aurai un moment. Ma version précédente marchait trés bien sans réauthentification à condition d'avoir une période inférieure à 5mn et je n'avais jamais eu de code 429.

Tatroxitum commented 1 year ago

mon cron est configuré ainsi : /1 * python /home/'user'/domoticz/scripts/cozytouch.py Donc si ça marche de mon coté toutes les minutes il doit y avoir d'autres différences avec ton script. Après il est possible qu'il y ai un nombre max de connexions par jour, comme je ne m'étais pas connecté hier attendons 24h pour voir si je tombe sur la même erreur.

Aldou63 commented 1 year ago

ok merci je vais faire des recherches sur mon script.

Aldou63 commented 1 year ago

N'ayant rien trouvé sur mon script j'ai testé la version 5.35 sur un serveur de test pour domoticz. Le programme crée bien tous les devices et les données collectées sont exactes. En mettant une période de1 mn j'ai comme sur ma version une erreur 429 suivi d'une réauthentification toutes les 5 boucles. Je n'ai pas utilisé de cron mais une boucle while à hauteur du déroulement du script pour pouvoir suivre plus facilement le programme avec un compteur. (Mes données sont récupérés sur mon chauffe eau thermodynamique Aeromax 5 Thermor)

Tatroxitum commented 1 year ago

J'ai le même comportement en fait : Lorsque je fais une requête toutes les minutes, j'ai le retour 429 qui apparait au bout de 5 minutes (too many requests) Le script se déroule cependant correctement ensuite : on se ré-authentifie et tout est ok. J'ai regardé dans les logs depuis début janvier 2023 et en effet on n'avait pas se comportement avant. Tout ce que j'ai modifié dans cette nouvelle version c'est le contenu des requêtes, pas leur nombre. Pour moi c'est donc une limitation due au serveur d'Overkiz suite à leur mise à jour le 24 mai. Mais encore une fois, le script s’authentifie dans la foulée et tout se déroule correctement donc ce n'est pas vraiment un problème.

Aldou63 commented 1 year ago

Oui je suis d'accord.

Tatroxitum commented 1 year ago

Je propose d'attendre qu'@OBone-git valide la pull request pour fermer cette issue

poelie83 commented 1 year ago

So, I updated the script with the new 5.35 to make it work, at least that's what I thought. After updating the script i get the following error messages:

¤¤¤¤ Demarrage script cozytouch <=> domoticz version 5.35 (debug :1)
Version python : 2.7.16
**** Test existence / creation configuration cozytouch (hardware domoticz + fichier de sauvegarde) ****
Fichier de sauvegarde de la configuration : /home/pi/cozytouch_save
idx hardware cozytouch dans le fichier de sauvegarde de la configuration : 19
GET->   http://192.168.0.105:8080/json.htm?type=hardware   :   200
idx hardware cozytouch dans domoticz : 19
**** Fin fonction test ****
Test présence du fichier de sauvegarde cozytouch et virtual hardware domoticz OK

**** Tentative interrogation serveur Cozytouch sans login, avec cookie login précédent ****
GET->   https://ha110-1.overkiz.com/enduser-mobile-web/enduserAPI/setup   :   200
Requete de test sans login reussie, bypass login

**** Decouverte devices ****
GET->   https://ha110-1.overkiz.com/enduser-mobile-web/enduserAPI/setup   :   200

Gateway Cozytouch : etat on / connexion : OK / version : 2022.7.4
**** Demarrage procedure d'ajout devices Cozytouch ****
GET->   http://192.168.0.105:8080/json.htm?type=command&param=addlogmessage&message=Cozytouch : Recherche des devices connectes ...    :   200
GET->   http://192.168.0.105:8080/json.htm?type=command&param=addlogmessage&message=Cozytouch : creation Bridge Cozytouch localisation inconnue ,url: internal://0841-6951-5503/pod/0   :   200
Ajout: Bridge Cozytouch localisation inconnue
GET->   http://192.168.0.105:8080/json.htm?type=command&param=addlogmessage&message=Cozytouch : Device avec classe io:StackComponent inconnu   :   200
GET->   http://192.168.0.105:8080/json.htm?type=createvirtualsensor&idx=19&sensorname=Etat chauffe DHWP All House+&sensortype=6   :   200
Traceback (most recent call last):
  File "cozytouch.py", line 1916, in <module>
    decouverte_devices()
  File "cozytouch.py", line 673, in decouverte_devices
    liste= Add_DHWP_THERM (save_idx,liste,url,x,(data[u'rootPlace'][u'label']),name) # label sur rootplace
  File "cozytouch.py", line 1029, in Add_DHWP_THERM
    DHWP_THERM[u'idx_on_off']= domoticz_add_virtual_device(idx,6,nom_switch_on_off)
  File "cozytouch.py", line 337, in domoticz_add_virtual_device
    idx=(data[u'idx'])
KeyError: u'idx'

Any idea what's going wrong? in domoticz I see the new hardware 5.35 but no new devices.

Aldou63 commented 1 year ago

When I test the new version 5.35 I have to delete cozytouch_save of the previous version to make it work.

Tatroxitum commented 1 year ago

Can you activate dump (debug=2) And send me this dump file ? Thanks.

Le jeu. 15 juin 2023, 09:16, poelie83 @.***> a écrit :

So, I updated the script with the new 5.35 to make it work, at least that's what I thought. After updating the script i get the following error messages:

`¤¤¤¤ Demarrage script cozytouch <=> domoticz version 5.35 (debug :1) Version python : 2.7.16 **** Test existence / creation configuration cozytouch (hardware domoticz

  • fichier de sauvegarde) Fichier de sauvegarde de la configuration : /home/pi/cozytouch_save idx hardware cozytouch dans le fichier de sauvegarde de la configuration : 19 GET-> http://192.168.0.105:8080/json.htm?type=hardware : 200 idx hardware cozytouch dans domoticz : 19 Fin fonction test **** Test présence du fichier de sauvegarde cozytouch et virtual hardware domoticz OK

Tentative interrogation serveur Cozytouch sans login, avec cookie login précédent GET-> https://ha110-1.overkiz.com/enduser-mobile-web/enduserAPI/setup : 200 Requete de test sans login reussie, bypass login

Decouverte devices GET-> https://ha110-1.overkiz.com/enduser-mobile-web/enduserAPI/setup : 200

Gateway Cozytouch : etat on / connexion : OK / version : 2022.7.4 Demarrage procedure d'ajout devices Cozytouch GET-> http://192.168.0.105:8080/json.htm?type=command&param=addlogmessage&message=Cozytouch : Recherche des devices connectes ... : 200 GET-> http://192.168.0.105:8080/json.htm?type=command&param=addlogmessage&message=Cozytouch : creation Bridge Cozytouch localisation inconnue ,url: internal://0841-6951-5503/pod/0 : 200 Ajout: Bridge Cozytouch localisation inconnue GET-> http://192.168.0.105:8080/json.htm?type=command&param=addlogmessage&message=Cozytouch : Device avec classe io:StackComponent inconnu : 200 GET-> http://192.168.0.105:8080/json.htm?type=createvirtualsensor&idx=19&sensorname=Etat chauffe DHWP All House+&sensortype=6 : 200 Traceback (most recent call last): File "cozytouch.py", line 1916, in decouverte_devices() File "cozytouch.py", line 673, in decouverte_devices liste= Add_DHWP_THERM (save_idx,liste,url,x,(data[u'rootPlace'][u'label']),name) # label sur rootplace File "cozytouch.py", line 1029, in Add_DHWP_THERM DHWP_THERM[u'idx_on_off']= domoticz_add_virtual_device(idx,6,nom_switch_on_off) File "cozytouch.py", line 337, in domoticz_add_virtual_device idx=(data[u'idx']) KeyError: u'idx' ` Any idea what's going wrong? in domoticz I see the new hardware 5.35 but no new devices.

— Reply to this email directly, view it on GitHub https://github.com/OBone-git/Cozytouch-domoticz/issues/50#issuecomment-1592492948, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGVKL737Q6DD6PQH2HXKP6TXLKZDFANCNFSM6AAAAAAYN5M5H4 . You are receiving this because you were mentioned.Message ID: @.***>

poelie83 commented 1 year ago

@Tatroxitum please see below: I already removed the cozytouch_save without any result

¤¤¤¤ Demarrage script cozytouch <=> domoticz version 5.35 (debug :2)
Version python : 2.7.16
**** Test existence / creation configuration cozytouch (hardware domoticz + fichier de sauvegarde) ****
Fichier de sauvegarde de la configuration : /home/pi/cozytouch_save
Fichier de sauvegarde de la configuration inexistant, creation hardware cozytouch dans domoticz et nouveau fichier de sauvegarde
GET->   http://192.168.0.105:8080/json.htm?type=command&param=addhardware&htype=15&port=1&name=Cozytouch_V5.35&enabled=true   :   200
('    **** domoticz cozytouch hardware index : ', '21')
GET->   http://192.168.0.105:8080/json.htm?type=command&param=addlogmessage&message=Creation nouvelle configuration ...   :   200
Hardware cozytouch dans domoticz et nouveau fichier de sauvegarde de la configuration crees
**** Fin fonction test ****
Test présence du fichier de sauvegarde cozytouch et virtual hardware domoticz OK

**** Tentative interrogation serveur Cozytouch sans login, avec cookie login précédent ****
GET->   https://ha110-1.overkiz.com/enduser-mobile-web/enduserAPI/setup   :   401
Erreur HTTP 401 :
!!!! Echec interrogation serveur Cozytouch sans login, connexion serveur Cozytouch ****
 POST-> https://ha110-1.overkiz.com/enduser-mobile-web/enduserAPI/login | userId=****&userPassword=**** : 200
Authentification serveur cozytouch OK
Connexion serveur Cozytouch reussie
GET->   https://ha110-1.overkiz.com/enduser-mobile-web/enduserAPI/setup   :   200
Requete setup reussie
**** Decouverte devices ****
GET->   https://ha110-1.overkiz.com/enduser-mobile-web/enduserAPI/setup   :   200

Gateway Cozytouch : etat on / connexion : OK / version : 2022.7.4
**** Demarrage procedure d'ajout devices Cozytouch ****
GET->   http://192.168.0.105:8080/json.htm?type=command&param=addlogmessage&message=Cozytouch : Recherche des devices connectes ...    :   200
GET->   http://192.168.0.105:8080/json.htm?type=command&param=addlogmessage&message=Cozytouch : creation Bridge Cozytouch localisation inconnue ,url: internal://0841-6951-5503/pod/0   :   200
Ajout: Bridge Cozytouch localisation inconnue
GET->   http://192.168.0.105:8080/json.htm?type=command&param=addlogmessage&message=Cozytouch : Device avec classe io:StackComponent inconnu   :   200
GET->   http://192.168.0.105:8080/json.htm?type=createvirtualsensor&idx=21&sensorname=Etat chauffe DHWP All House+&sensortype=6   :   200
Traceback (most recent call last):
  File "./cozytouch.py", line 1916, in <module>
    decouverte_devices()
  File "./cozytouch.py", line 673, in decouverte_devices
    liste= Add_DHWP_THERM (save_idx,liste,url,x,(data[u'rootPlace'][u'label']),name) # label sur rootplace
  File "./cozytouch.py", line 1029, in Add_DHWP_THERM
    DHWP_THERM[u'idx_on_off']= domoticz_add_virtual_device(idx,6,nom_switch_on_off)
  File "./cozytouch.py", line 337, in domoticz_add_virtual_device
    idx=(data[u'idx'])
KeyError: u'idx'
Aldou63 commented 1 year ago

Don't now if it can resolve the problem but I forgot to tell you that I have also delete the hardware associated with the devices before testing the new version . My fisrt test was with the old harware and the old cozytouch_save and it don't work with the same type of error you have. Starting with no old hardware and cozytouch_save recreate the devices and give true data. (test with domoticz V 2023.1)

poelie83 commented 1 year ago

@Aldou63, unfortunately removing all the hardware is giving the same result as above. V 2023.1 (build 15332)

Tatroxitum commented 1 year ago

We need the cozytouch-dump.txt to investigate (debug = 2) Seems like the is an information missing for your hot water system

Le jeu. 15 juin 2023, 15:40, poelie83 @.***> a écrit :

@Aldou63 https://github.com/Aldou63, unfortunately removing all the hardware is giving the same result as above.

— Reply to this email directly, view it on GitHub https://github.com/OBone-git/Cozytouch-domoticz/issues/50#issuecomment-1593087165, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGVKL77GMCAGSWKLIKGZS4TXLMGFVANCNFSM6AAAAAAYN5M5H4 . You are receiving this because you were mentioned.Message ID: @.***>

poelie83 commented 1 year ago

Please find the dump file here click

LudovicRousseau commented 1 year ago

Thanks all for your work. I updated my code using this simple patch https://github.com/LudovicRousseau/Cozytouch-domoticz/commit/130e2da15b752cd8f9d130770ce8b8843cc81113

The problem is fixed for me so I close this issue. But you can continue to communicate here.

Tatroxitum commented 1 year ago

I'm investigating this issue. @poelie83 Please create a new issue with the informations above

niavok commented 1 year ago

Thanks @Tatroxitum , I updated my water heater control script (broken since May 24th) based on your changes and it works well again ! https://github.com/niavok/cozytouch_peak_hours/commit/d3c21202ff9a8686c80a8d51eff97d07c75639c1