Dimitar Posted December 17, 2023 Share Posted December 17, 2023 Interesting script I make today. You can use HomeAssistant to unify App access to any device ZigBee, Tuya, Thread in all integrations and you then you can control device from Shelly App. Still working on it but hope during Xmas will be ready. You are welcome to comment, I may open a github repository where everyone can commit and make changes. 6 Quote Translate Revert translation? English (American) Finnish French German Italian Portuguese (European) Spanish Link to comment Share on other sites More sharing options...
Dimitar Posted December 17, 2023 Author Share Posted December 17, 2023 And it's done. Tuya enabled Air-conditioner connected to HA with Tuya Integration and controlled from Shelly App via Shelly Gen3 device. Crazy! END TO END REACTION TIME < 1 SEC 🙂 You can see what Virtual components must be created. This is the script: // Replace these with your actual Home Assistant URL and access token let homeAssistantUrl = 'IP:port'; let accessToken = "ACCESS Token"; let entityId = 'Air.conditioner.ID'; // Replace with the actual entity ID const headers = { "Authorization": "Bearer " + accessToken, "Content-Type": "application/json", }; const url = homeAssistantUrl + "api/states/" + entityId; function checkStatus() { Shelly.call("http.request", { method: "GET", url: url, headers: headers }, function (response, error_code, error_message) { if (response.code === 200 && response.body) { let responseBody = JSON.parse(response.body); if (responseBody.hasOwnProperty('state')) { let state = responseBody.state; print("state: " + state); Shelly.call("enum.set", { id: 200, value: state }); } // Print 'current_temperature' and 'temperature' from attributes if (responseBody.attributes) { if (responseBody.attributes.hasOwnProperty('current_temperature')) { let currenttemp = JSON.stringify(responseBody.attributes.current_temperature); print("current_temperature: " + currenttemp); Shelly.call("number.set", { id: 200, value: currenttemp }); } if (responseBody.attributes.hasOwnProperty('temperature')) { let targettemp = JSON.stringify(responseBody.attributes.temperature); print("temperature: " + targettemp); Shelly.call("number.set", { id: 201, value: targettemp }); } } } else { // Handle errors print("Error Code: " + error_code + " - Message: " + error_message); } }); } // Function to change the temperature function setTemperature(newTemp) { const temperatureUrl = homeAssistantUrl + "api/services/climate/set_temperature"; Shelly.call("http.request", { method: "POST", url: temperatureUrl, headers: headers, body: JSON.stringify({ entity_id: entityId, temperature: newTemp }) }, function (response, error_code, error_message) { if (response && response.code === 200) { print("Temperature set to " + newTemp); } else { print("Error setting temperature - Code: " + error_code + " - Message: " + error_message); } }); } function setHvacMode(mode) { const hvacModeUrl = homeAssistantUrl + "api/services/climate/set_hvac_mode"; Shelly.call("http.request", { method: "POST", url: hvacModeUrl, headers: headers, body: JSON.stringify({ entity_id: entityId, hvac_mode: mode }) }, function (response, error_code, error_message) { if (response && response.code === 200) { print("HVAC mode set to " + mode); } else { print("Error setting HVAC mode - Code: " + error_code + " - Message: " + error_message); } }); } Shelly.addStatusHandler(function(event) { // print (event.component); if (event.component === "enum:200") { let newmode = Shelly.getComponentStatus("enum", 200)["value"]; setHvacMode(newmode); } if (event.component === "number:201") { let newTemp = Shelly.getComponentStatus("number", 201)["value"]; setTemperature(newTemp); } }); Timer.set( /* number of miliseconds */ 5000, /* repeat? */ true, /* callback */ checkStatus ); Enjoy 5 1 Quote Translate Revert translation? English (American) Finnish French German Italian Portuguese (European) Spanish Link to comment Share on other sites More sharing options...
Guest PortInnovator Posted March 26 Share Posted March 26 Hi Dimitar, that's awesome and when I get you right this should be the way to control HUE lights via the Shelly WallDisplay and HA, isn't it? Do you have a blueprint to implement a virtual switch or dimmer? Thank you Michael Quote Translate Revert translation? English (American) Finnish French German Italian Portuguese (European) Spanish Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.