From 4082a155a4895baea67c8ee05a592b373cc87cd9 Mon Sep 17 00:00:00 2001 From: Moritz Graf Date: Sun, 5 Jul 2026 07:55:41 +0200 Subject: [PATCH] feat(shelly): auto-start script after successful upload in upload.py --- terraform_shelly/scripts/upload.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/terraform_shelly/scripts/upload.py b/terraform_shelly/scripts/upload.py index 41e7e37..52307a0 100644 --- a/terraform_shelly/scripts/upload.py +++ b/terraform_shelly/scripts/upload.py @@ -58,6 +58,23 @@ def upload(ip, script_id, code_file): print("Script upload complete!") + # Start the script after upload + print(f"Starting script {script_id}...") + req = urllib.request.Request( + url, + data=json.dumps({"id": 1, "method": "Script.Start", "params": {"id": int(script_id)}}).encode('utf-8'), + headers={'Content-Type': 'application/json'} + ) + try: + with urllib.request.urlopen(req) as resp: + res = json.loads(resp.read().decode('utf-8')) + if "error" in res: + print(f"Start request returned error: {res['error']}") + else: + print("Script started successfully.") + except Exception as e: + print(f"Start request failed: {e}") + if __name__ == "__main__": if len(sys.argv) < 4: print("Usage: python3 upload.py ")