Dimitar Posted December 3, 2023 Share Posted December 3, 2023 To work you need to create virtual same virtual components and then change ID in the script:Â let CONFIG = { Â accuWeatherAPIKEY: "YOUR KEY", Â weatherForecastEndpoint: Â Â "http://dataservice.accuweather.com/forecasts/v1/daily/1day/", Â weatherCurrentEndpoint: Â Â "http://dataservice.accuweather.com/currentconditions/v1/", Â locations: { Â Â Chicago: 348308, Â Â Miami: 347936, Â Â Mosfellsbaer: 190395, Â Â Sofia: 51097 Â }, }; let checkInterval = 10000; let timerID = null; let roomtemp = 0; //Event register Shelly.addEventHandler(function (event) { Â if (event.name === "script" && event.id === 5) { Â Â Â roomtemp = event.info.data.temp; Â Â Â Shelly.call("number.set", { id: 204, value: roomtemp }); Â Â Â print ("Room temp: " + roomtemp); Â } }); // Initialize timer outside the updateSettings function timerID = Timer.set(checkInterval, true, function() { Â // console.log("Checking weather"); Â let city = Shelly.getComponentStatus("enum", 200)["value"]; Â // print(city); Â TemperatureControlLocation(city); }); // Add a new endpoint to serve the form for updating the API key HTTPServer.registerEndpoint("update-api-key-form", function(req, res) { Â let htmlForm = '<html>' + Â Â '<head>' + Â Â Â '<style>' + Â Â Â Â 'body {' + Â Â Â Â Â 'background-color: #11191f;' + Â Â Â Â Â 'font-family: Arial, sans-serif;' + Â Â Â Â Â 'text-align: center;' + Â Â Â Â Â 'padding-top: 50px;' + Â Â Â Â '}' + Â Â Â Â 'form {' + Â Â Â Â Â 'background: #C0C0C0;' + Â Â Â Â Â 'padding: 20px;' + Â Â Â Â Â 'border-radius: 8px;' + Â Â Â Â Â 'box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);' + Â Â Â Â Â 'display: inline-block;' + Â Â Â Â Â 'margin-top: 20px;' + Â Â Â Â '}' + Â Â Â Â 'input, button {' + Â Â Â Â Â 'margin-bottom: 15px;' + Â Â Â Â Â 'padding: 10px;' + Â Â Â Â Â 'width: 250px;' + Â Â Â Â Â 'border-radius: 4px;' + Â Â Â Â Â 'border: 1px solid #ddd;' + Â Â Â Â '}' + Â Â Â Â 'button {' + Â Â Â Â Â 'background-color: #007bff;' + Â Â Â Â Â 'color: white;' + Â Â Â Â Â 'border: none;' + Â Â Â Â Â 'cursor: pointer;' + Â Â Â Â Â 'width: 270px;' + Â Â Â Â '}' + Â Â Â Â 'button:hover {' + Â Â Â Â Â 'background-color: #0056b3;' + Â Â Â Â '}' + Â Â Â Â 'label {' + Â Â Â Â Â 'display: block;' + Â Â Â Â Â 'margin-bottom: 5px;' + Â Â Â Â '}' + Â Â Â '</style>' + Â Â '</head>' + Â Â '<body>' + Â Â Â '<div style="text-align: center;">' + Â Â Â Â '<img src="https://info.shelly.cloud/wp-content/uploads/2021/07/shelly_logo_blue.png" alt="Shelly Logo" style="max-width: 200px; margin-top: 20px;">' + Â Â Â '</div>' + Â Â Â '<form id="updateForm" action="/script/1/update-settings" method="post" style="margin: auto; width: 300px;">' + Â Â Â Â '<label for="apikey"><img src="http://minhome.net:8080/key.png" alt="Key Icon" class="key-icon">AccuWeather API Key:</label>' + Â Â Â Â '<input type="text" id="apikey" name="apikey" value="' + CONFIG.accuWeatherAPIKEY + '"><br>' + Â Â Â Â '<label for="checkInterval">Check Interval (ms):</label>' + Â Â Â Â '<input type="number" id="checkInterval" name="checkInterval" value="' + checkInterval + '"><br>' + Â Â Â Â '<button type="submit">Update Settings</button>' + Â Â Â '</form>' + '<div style="margin-top: 20px;">' + Â '<a href="#" onclick="this.href=\'http://\' + window.location.hostname + \'/#\'" style="text-decoration: none; color: inherit;">' + Â Â '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-home">' + Â Â Â Â Â Â '<path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"></path>' + Â Â Â Â Â Â '<polyline points="9 22 9 12 15 12 15 22"></polyline>' + Â Â Â Â Â '</svg>' + Â Â Â Â '</a>' + Â '<a href="#" onclick="this.href=\'http://\' + window.location.hostname + \'/#/script/1\'" style="text-decoration: none; color: inherit; margin-left: 10px;">' + Â Â '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-code">' + Â Â Â Â Â Â '<polyline points="16 18 22 12 16 6"></polyline>' + Â Â Â Â Â Â '<polyline points="8 6 2 12 8 18"></polyline>' + Â Â Â Â Â '</svg>' + Â Â Â Â '</a>' + Â Â Â '</div>' + Â Â '</body>' + Â '</html> Â Quote Translate Revert translation? English (American) Finnish French German Italian Portuguese (European) Spanish Link to comment Share on other sites More sharing options...
Shelly Dennis Dalgaard Gottlieb Posted June 8 Shelly Share Posted June 8 Just to be sure - with this script, you will be able to create a thermostat function that works locally, right? No need of cloud like for the thermostat feature in the app. 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.