tuya_project/tuya-control/devices/shutters/volet_dino_close_toggle.py
2025-04-27 19:45:45 +02:00

77 lines
2.4 KiB
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Script pour fermer le volet Dino
À utiliser avec StreamDeck
"""
import tinytuya
import json
# Informations Cloud Tuya
API_REGION = "eu"
API_KEY = "fdjdjurkm34yyjp77c7d"
API_SECRET = "3e71807fb0c6406792bdf4f07f98e577"
# ID et nom de l'appareil
DEVICE_ID = "bff082745aedf9fc1aqy3e" # ID du volet Dino
DEVICE_NAME = "Volet dino" # Nom de l'appareil
# Code des commandes du volet
SWITCH_CODE = "control" # Pour les volets Tuya, le code est souvent "control"
def main():
"""Fonction principale pour fermer le volet via Cloud"""
# Connexion au Cloud
cloud = tinytuya.Cloud(
apiRegion=API_REGION,
apiKey=API_KEY,
apiSecret=API_SECRET
)
tinytuya.set_debug(True) # Pour debug si besoin
# Lire l'état actuel du volet
print(f"🔍 Récupération du statut pour l'appareil {DEVICE_ID}...")
status = cloud.getstatus(DEVICE_ID)
if not status:
print(f"❌ Aucune réponse de l'API Cloud pour {DEVICE_NAME}")
return
try:
print(f"📊 Réponse brute: {json.dumps(status, indent=2)}")
except Exception as e:
print(f"⚠️ Erreur lors de l'affichage de la réponse: {e}")
# Vérification de l'état actuel
current_state = None
if isinstance(status, dict) and "result" in status:
result = status["result"]
for item in result:
if item.get("code") == SWITCH_CODE:
current_state = item.get("value")
break
print(f" État actuel du volet: {current_state}")
# Envoyer la commande pour fermer le volet
commands = {
"commands": [
{"code": SWITCH_CODE, "value": "close"}, # Essayez "close" pour fermer
# Vous pouvez également essayer "fermer" si cela est supporté
]
}
print(f"📤 Envoi de la commande: {json.dumps(commands, indent=2)}")
response = cloud.sendcommand(DEVICE_ID, commands)
print(f"📥 Réponse reçue: {json.dumps(response, indent=2) if response else 'Aucune réponse'}")
if response is not None and response.get("success"):
print(f"{DEVICE_NAME} est maintenant fermé")
else:
error_msg = response.get("msg", "Erreur inconnue") if response else "Pas de réponse"
print(f"❌ Échec pour {DEVICE_NAME}: {error_msg}")
if __name__ == "__main__":
main()