Use variable from script in a flow, I fail miserably

Hello all,

I have been struggling for 6 hours straight now, and I still don’t have it working, so this is my call for help

What I’m trying to build:

I have a homeyscript that connects to a datalogger. The datalogger gives a json reply and I’m filtering a specific sensor for temperature out of the json output.
This homeyscript will be launched every 5 minutes to update the temperature in a variable called “temperature”.
I want to use this variable “temperature” in a flow, where I want to measure if this variable is above or below 70 degrees using a logic card.
If yes action A, if no action B.

I have been successful in writing the homeyscript to grab the temperature from the datalogger. This is the code I made:

try {
  const res = await fetch('https://datalogger/dlx/download/live?');
  if (!res.ok) throw new Error(`HTTP error! Status: ${res.status}`);

  const json = await res.json();
  const rawTemp = json?.headersets?.[0]?.packets?.[0]?.field_values?.[2]?.value;

  if (rawTemp === undefined) throw new Error('Temperature value not found');

  const temperature = Number(rawTemp);
  log(`Temperature Sensor 3 reading: ${temperature} °C`);

  if (!isNaN(temperature) && temperature < 100) {
    global.set('temperature', rawTemp); 
    log(`Temperature Variable set on: ${temperature} °C`);
    return temperature;
      } else {
    return 'Invalid temperature value';
  }
} catch (err) {
  log(`Error: ${err.message}`);
  return `Error: ${err.message}`;
}

The output when I run the script:
Temperature Sensor 3 reading: 73.8 °C
Temperature Variable set on: 73.8 °C
:white_check_mark: Script Success
:right_arrow_curving_left: Returned: 73.8

I created the variable “temperature” as a number in the screen of the flows.

The flow is extremely simple:

But as you can see the logic is saying the temperature is not greater than 50 despite the fact that the variable and script is saying 73.8

What am I doing wrong?

Thanks!

The second log line shows the value of the same constance temperature, that’s why you see two identical values

I also would refrain from using the same name temperature for different things;
example:

const rawTemp = json?.headersets?.[0]?.packets?.[0]?.field_values?.[2]?.value;
rawTemp = Number(rawTemp);
global.set('Temperature_hs', rawTemp);

To retrieve and view the ‘temperature’ tag in the console, you’d use global.get, as shown in the Homeyscript example scripts

To know what’s going on, and view it’s value: add a timeline card f.i., and add that tag [temperature] to it.

And please format your code as code
(add ``` above and below your script).
Now there’s fancy quotes in it, that never works in scripts