Hello,
I would like to use the value returned by the function as variable so I can use this one further in the Flows.
I don’t know how to register this value in a variable (not in homeyscript nor in Flow).
function solarangle(azimuth,altitude){
var teta=90-altitude;
var beta = 90 - Math.atan(Math.tan(teta*Math.PI/180)*Math.sin((azimuth-167)*Math.PI/180))*180/Math.PI;
return beta;
}
So I would like to get the value of “beta” in an existing variable to use in Flow.
I hope that someone can help me and sorry if the answer is already existing but I haven’t found the solution yet (or at least not understood it )
Thanks!
Connect your homeyscript card with the logic card to set variables, select the variable in the logic card (add it if necessary in the variables menu at the top) and select the tag #Result as value.
Good morning,
you understood it right, this was what I needed
Thanks!
Now I just have one more problem to solve:
When I check the return value in the script, I get the expected number so I don’t understand why I get this error message. All values of the variables were checked and are correct and only numerical.
Could you breakdown your solution so it might be used universally? Or is this custom only haha.
I’m facing the same thing with my script
// Define the API key and location
const apiKey = '';
const location = '';
// Construct the API URL
const url = `https://weerlive.nl/api/weerlive_api_v2.php?key=${apiKey}&locatie=${location}`;
// Send a GET request using fetch
fetch(url)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json(); // Parse the response as JSON
})
.then(data => {
console.log(data); // Log the JSON response
// Access specific data points to verify parsing
const liveweer = data.liveweer[0];
console.log(`Location: ${liveweer.plaats}`);
console.log(`Temperature: ${liveweer.temp}°C`);
console.log(`Summary: ${liveweer.samenv}`);
})
.catch(error => {
console.error('There has been a problem with your fetch operation:', error);
});
I think this is about the same issue you replied to some years ago, Robert: wanting to get certain values from returned JSON data from weerlive.nl
Your post below in English:
$ represents the (JSON) object returned by the server
liveweer is the name of a “key” in that object; the value associated with the key is an array of values (each value is another object, so $.liveweer is an array-of-objects)
[0] is the first element of that array; if you want the second element, you have to use [1] (etc);
d0tmax is the name of a key in the (in this case) first element of the liveweer array
The expression is a JSONPath expression. You can here try such expressions in real time: paste the JSON result from the weerlive server into the “JSON” field, enter the JSONPath expression at the top, and on the right you can see the result.