Get value from homeyscript in a variable that can be used in advanced flow

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).
image

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 :slight_smile: )
Thanks!

Maybe I misunderstand you, but have you tried the respective logic flow card (sorry, screenshot is in German):

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.

2 Likes

Good morning,
you understood it right, this was what I needed :+1:
Thanks!

Now I just have one more problem to solve:
image
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.

Can you share your flow?

Returned: undefined

So your script isn’t returning anything.

Here is the function:
function solarangle(azimuth,altitude){

let teta = 90 - altitude;
let beta = 90 - Math.atan(Math.tan(teta*Math.PI/180)*Math.sin((azimuth-167)*Math.PI/180))180/Math.PI;
let percentage = 0;
if (beta >150){
percentage = 100;
} else {
percentage = Math.round(beta/150
100);
}
return percentage;
}

image

Can you see why the script would not return the value?

Your script only declares a function but doesn’t actually call it. It also doesn’t do anything to parse the argument.

Try adding this at the end of the script:

const input = JSON.parse(args[0]);
return solarangle(input.azimuth, input.altitude);
1 Like

Thanks a lot!
It works now!