{"id":23107365,"url":"https://github.com/elmodo7/tuya4ahk","last_synced_at":"2025-07-02T03:03:12.283Z","repository":{"id":222660795,"uuid":"758029331","full_name":"elModo7/Tuya4AHK","owner":"elModo7","description":"An AHK class for wrapping Tuya OpenAPI calls for IoT device automation over Wi-Fi.","archived":false,"fork":false,"pushed_at":"2024-02-15T17:22:39.000Z","size":31,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-03T22:43:12.560Z","etag":null,"topics":["ahk","autohotkey","iot","openapi","tuya","tuya-api","tuya-cloud"],"latest_commit_sha":null,"homepage":"","language":"AutoHotkey","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elModo7.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-15T13:39:41.000Z","updated_at":"2024-02-15T15:49:33.000Z","dependencies_parsed_at":"2024-02-15T16:50:39.718Z","dependency_job_id":"d2a738de-223b-414e-aa9d-a22443d3d2f2","html_url":"https://github.com/elModo7/Tuya4AHK","commit_stats":null,"previous_names":["elmodo7/tuya_iot_autohotkey_openapi","elmodo7/tuya4ahk"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/elModo7/Tuya4AHK","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elModo7%2FTuya4AHK","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elModo7%2FTuya4AHK/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elModo7%2FTuya4AHK/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elModo7%2FTuya4AHK/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elModo7","download_url":"https://codeload.github.com/elModo7/Tuya4AHK/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elModo7%2FTuya4AHK/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263066557,"owners_count":23408387,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ahk","autohotkey","iot","openapi","tuya","tuya-api","tuya-cloud"],"created_at":"2024-12-17T01:13:27.780Z","updated_at":"2025-07-02T03:03:12.262Z","avatar_url":"https://github.com/elModo7.png","language":"AutoHotkey","readme":"\n## Tuya IoT Cloud OpenAPI wrapper for AutoHotkey\nI had some wifi bulbs that I was given like 5 years ago or so and I wanted to automate them with **[AutoHotkey](https://www.autohotkey.com/)**.\nI noticed they were using **port 6668**, so chances were they could use **[Tuya Cloud API](https://developer.tuya.com/en/docs/cloud)** and since there was no ahk library for dealing with them I made my own.\n\nNow I've read Tuya is known for changing their API a lot and __making it hard on purpose__ for users to deal directly with their IoT devices (which was my idea in the first place). However, ***this is working as of 15/Feb/2024.***\n\n## Connection Flow:\n\n```mermaid\ngraph LR\nA[AutoHotkey\u003cbr\u003eBuild cmd] -.- B((Bulb))\nA --\u003e C1{Sign Request}\nC1 --\u003e C(HTTP Query)\nD[(Tuya Cloud)] --\u003e B\nC --\u003e D\n\nclassDef ahk fill:#586,stroke:#333;\nclassDef bulb fill:#990,stroke:#333;\nclassDef sign fill:#888,stroke:#333;\nclassDef tuya fill:#F50,stroke:#333;\nclass A ahk\nclass C1 sign\nclass B bulb\nclass D tuya\n```\n\n## Class Usage\n\n### Initializing the class and obtaining a *Token*\n```AutoHotkey\ntuyaApi := new TuyaApi()\ntuyaApi.cfg.debug := 1 ; Get notified of errors (default off)\ntuyaApi.getToken()\n```\n\u003e **Quick Note:** getToken is not always necessary since this lib is able to detect invalid or deprecated tokens and **recreate a valid token** on its own when **performing an action**.\n\n#### Performing actions on the devices\n```AutoHotkey\n; Turn on light\ntuyaApi.toggleOn(tuyaApi.devices[1].id, \"true\") ; Returns status 200 if successful\n\n; Turn off light\ntuyaApi.toggleOn(tuyaApi.devices[1].id, \"false\")\n\n; Turns on light, sets luminosity to 1000 (max [10-1000]) and warmness to 0 (warmest [0-1000])\ntuyaApi.setNormalLightStatus(tuyaApi.devices[1].id, \"true\", \"1000\", \"0\")\n\n; Turns on light, sets HSV values to: h:240 -\u003e blue, saturation -\u003e 1000, value -\u003e 1000\ntuyaApi.setHSVLightStatus(tuyaApi.devices[1].id, \"true\", \"240\", \"1000\", \"1000\")\n```\n\n### Getting device information\n```AutoHotkey\nbulb1_info := tuyaApi.getDeviceInfo(tuyaApi.devices[1].id) ; Get info of a specific device\ndevices_info := tuyaApi.getDevicesInfo(tuyaApi.devices) ; Get info of each registered device\nbulb1_stats := tuyaApi.getDeviceStats(tuyaApi.devices[1].id) ; Get stats of a scpecific device\ndevices_stats := tuyaApi.getDevicesStats(tuyaApi.devices) ; Get stats of each registered device\n```\n\n## Configuration Example\n### common_data.json\n```JSON\n{\n  \"debug\": false,\n  \"url\": \"https://openapi.tuyaeu.com\",\n  \"client_id\": \"9647axf8vtyuqtwugjnd\",\n  \"secret\": \"aa75b183b4v757aba8db85u8945c7acf\",\n  \"project_code\": \"p1807878438912hout6r\"\n}\n```\n\n### devices.json\n```JSON\n[\n  {\n    \"type\": \"bulb\",\n    \"name\": \"Smart Bulb\",\n    \"id\": \"07468567f4cfa678542d\",\n    \"product_id\": \"1urlnfjaiklk4dly\"\n  },\n  {\n    \"type\": \"bulb\",\n    \"name\": \"Smart Bulb 2\",\n    \"id\": \"03740273f4cfa2289311\",\n    \"product_id\": \"irsteipfgt0kt7rco\"\n  }\n]\n```\n\n## Detailed connection flow:\n```mermaid\nsequenceDiagram\nAutoHotkey -\u003e\u003e Tuya API: GetToken()\nTuya API--\u003e\u003eAutoHotkey: TokenData\nAutoHotkey -\u003e\u003e Tuya API: RunAction(token, body)\nTuya API-\u003e\u003e Bulb: Turn On at  50%\nBulb -\u003e\u003e Tuya API: ACK\nTuya API-\u003e\u003e AutoHotkey: Command completed successfully\nNote right of Bulb: Bulbs have a reverse\u003cbr\u003econnection towards\u003cbr\u003eTuya IoT services so\u003cbr\u003ewe need Tuya as a\u003cbr\u003eMiddleman to establish\u003cbr\u003e a connection.\n```\n\n## Libraries used\n - [Cryptography API: Next Generation (CNG)](https://github.com/jNizM/AHK_CNG)\n - [cJSON](https://github.com/G33kDude/cJson.ahk)\n\n## Notes\nI have implemented but not yet used **refresh tokens**, feel free to improve this library by doing a pull request.\n\nI **do not have nor automate IoT stuff myself** nor I tend to create AutoHotkey libs for others (I'm more and more leaning towards doing so though lately because I'm planning to **make Udemy Courses or video content** on AutoHotkey development), so any suggestion is greatly appreciated.\n\nThis project was written with AutoHotkey v1 in mind, if you want to port it to AHK v2 or want some advise on it, you can find me on Discord.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felmodo7%2Ftuya4ahk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felmodo7%2Ftuya4ahk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felmodo7%2Ftuya4ahk/lists"}